In java
Write a program that draws out a path based on the user input. The starting coordinates for the path is the middle of the DrawingPanel. Ask the user to enter an x and a y coordinate for a DrawingPanel. Your program will draw a line from the last coordinates to the current coordinates the user enters. If the user enters an x value or y value out of bounds of the DrawingPanel, then end the program.

Answers

Answer 1

Answer:

import javax.swing.JPanel;

import javax.swing.JOptionPane;

import javax.swing.JFrame;

import javax.swing.JLabel;  

import javax.swing.JTextField;

import javax.swing.border.Border;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.BorderFactory;

import javax.swing.JButton;

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.FlowLayout;

import java.awt.Graphics;

import java.awt.Rectangle;

public class DrawingPanel{

 

private static final int width = 800;

private static final int heigth = 500;

private static JFrame mainFrame;

private static JPanel mainPanel, inputPanel, drawPanel;

private static JLabel xLabel, yLabel;

private static JTextField xField, yField;

private static JButton drawButton;

 

public static void main(String[] args)

{

mainFrame = new JFrame("Draw Path");

mainPanel = new JPanel(new BorderLayout());

 

inputPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));

xLabel = new JLabel("X Coordinate: ");

xField = new JTextField(5);

yLabel = new JLabel("Y Coordinate: ");

yField = new JTextField(5);

drawButton = new JButton("Draw");

inputPanel.add(xLabel);

inputPanel.add(xField);

inputPanel.add(yLabel);

inputPanel.add(yField);

inputPanel.add(drawButton);

 

Border border = BorderFactory.createLineBorder(Color.black);

drawPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));

drawPanel.setBorder(border);

 

mainPanel.add(inputPanel, BorderLayout.NORTH);

mainPanel.add(drawPanel, BorderLayout.CENTER);

 

mainFrame.add(mainPanel);

mainFrame.setSize(PANEL_WIDTH, PANEL_HEIGHT);

mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

mainFrame.setLocationRelativeTo(null);

mainFrame.setResizable(false);

mainFrame.setVisible(true);

 

// action listener for draw button

drawButton.addActionListener(new ActionListener() {

(use the at sign here)Override

public void actionPerformed(ActionEvent e) {

if(xField.getText().equals("") || yField.getText().equals(""))

JOptionPane.showMessageDialog(null, "Please enter the x and y coordinates!");

else

{

int x2 = Integer.parseInt(xField.getText().trim());

int y2 = Integer.parseInt(yField.getText().trim());

if(x2 > WIDTH || y2 > HEIGHT)

JOptionPane.showMessageDialog(null, "x and y coordinates should be less than "

+ width + " and " + height + " respectively!");

else

drawPath(x2, y2);

}

}

});

}

 

public static void drawPath(int x2, int y2)

{

int x1 = (int)drawPanel.getBounds().getCenterX();

int y1 = (int)drawPanel.getBounds().getCenterY();

 

Graphics g = drawPanel.getGraphics();

Rectangle r = drawPanel.getBounds();

g.setColor(drawPanel.getBackground());

g.fillRect(r.x, r.y, r.width, r.height);

 

g.setColor(Color. blue);

g.drawLine(x1, y1, x2, y2);

}

}

Explanation:

The class DrawingPanel is a Java class that gets the user input for the coordinate of a path with predetermined heigth and width (defined in the class). The methods of the class are; getGraphics(), getBounds(), getBackground(), setColor() and fillRect(). The result is a rectangular path GUI on the screen.


Related Questions

A series of gentle often open-ended inquiries that allow the client to progressively examine the assumptions and interpretations here she is made about the victimization experience is called:_____.

Answers

Answer:

Trauma Narrative

Explanation:

Given that Trauma narrative is a form of narrative or carefully designed strategy often used by psychologists to assists the survivors of trauma to understand the meaning or realization of their experiences. It is at the same time serves as a form of openness to recollections or memories considered to be painful.

Hence, A series of gentle often open-ended inquiries that allow the client to progressively examine the assumptions and interpretations he or she is made about the victimization experience is called TRAUMA NARRATIVE

What is the shortcut key to “Left Align” the selected text

Answers

Explanation:

The shortcut key to"left align" the selected text is Control+L

heyyy y’all hope your day was great

Which of the following are downlink transport channels?
a. BCH.
b. PCH.
C. RACH.
d. UL-SCH.
e. DL-SCH.

Answers

I think it’s a or b

Any one know??please let me know

Answers

Answer:

B

Explanation:

Answer:

The answer is B.

Explanation:

Also I see your using schoology, I use it too.

How did NAT help resolve the shortage of IPV4 addresses after the increase in SOHO, Small Office Home Office, sites requiring connections to the Internet?

Answers

Question Completion:

Choose the best answer below:

A. It provides a migration path to IPV6.

B. It permits routing the private IPV4 subnet 10.0.0.0 over the Internet.

C. NAT adds one more bit to the IP address, thus providing more IP addresses to use on the Internet.

D. It allowed SOHO sites to appear as a single IP address, (and single device), to the Internet even though there may be many devices that use IP addresses on the LAN at the SOHO site.

Answer:

NAT helped resolve the shortage of IPV$ addresses after the increase in SOHO, Small Office Home Office sites requiring connections to the internet by:

D. It allowed SOHO sites to appear as a single IP address, (and single device), to the Internet even though there may be many devices that use IP addresses on the LAN at the SOHO site.

Explanation:

Network Address Translation (NAT) gives a router the ability to translate a public IP address to a private IP address and vice versa.  With the added security that it provides to the network, it keeps the private IP addresses hidden (private) from the outside world.  By so doing, NAT permits routers (single devices) to act as agents between the Internet (public networks) and local (private) networks.  With this facilitation, a single unique IP address is required to represent an entire group of computers to anything outside their networks.

Pointers are addresses and have a numerical value. You can print out the value of a pointer as cout << (unsigned)(p). Write a program to compare p, p + 1, q, and q + 1, where p is an int* and q is a double*. Explain the results.

Answers

Answer:

#include <iostream>

using namespace std;

int main() {

  int i = 2;

  double j = 3;

 

  int *p = &i;

  double *q = &j;

 

  cout << "p = " << p << ", p+1 = " << p+1 << endl;

  cout << "q = " << q << ", q+1 = " << q+1 << endl;

  return 0;

}

Explanation:

In C++, pointers are variables or data types that hold the location of another variable in memory. It is denoted by asterisks in between the data type and pointer name during declaration.

The C++ source code above defines two pointers, "p" which is an integer pointer and "q", a double. The reference of the variables i and j are assigned to p and q respectively and the out of the pointers are the location of the i and j values in memory.

what types of problems if no antivirus is not installed

Answers

If you meant what would happen if you don't install an antivirus software, trust me, you don't want to know. I'd definitely recommend either Webroot (I believe that's how it's spelled) or Mcafee.

Suppose an application generates chunks 60 bytes of data every 200msec. Assume that each chunk gets put into a TCP packet (using a standard header with no options) and that the TCP packet gets put into an IP packets. What is the % of overhead that is added in because of TCP and IP combines?
1) 40%
2) 10%
3) 20%
4) 70%

Answers

Answer:

1) 40%

Explanation:

Given the data size = 60 byte

data traversed through TSP then IP

Header size of TCP = 20 bytes to 60 bytes

Header size of IP = 20 bytes to 60 bytes

Calculating overhead:

By default minimum header size is taken into consideration hence TCP header size = 20 bytes and IP header size = 20 bytes

Hence, the correct answer is option 1 = 40%

A substring of some character string is a contiguous sequence of characters in that string (which is different than a subsequence, of course). Suppose you are given two character strings, X and Y , with respective lengths n and m. Describe an efficient algorithm for finding a longest common substring of X and Y .For each algorithm:i. Explain the main idea and approach.Write appropriate pseudo-code.Trace it on at least three different examples, including at least a canonical case and two corner cases.
iv. Give a proof of correctness.v. Give a worst-case asymptotic running time analysis.

Answers

Answer:

create a 2-dimensional array, let both rows represent the strings X and Y.

check for the common characters within a string and compare them with the other string value.

If there is a match, append it to the array rows.

After iterating over both strings for the substring, get the longest common substring for both strings and print.

Explanation:

The algorithm should create an array that holds the substrings, then use the max function to get the largest or longest substring in the array.

Thale cress is a plant that is genetically engineered with genes that break down toxic materials. Which type of organism is described?
recombinant
transgenic
transverse
restriction

Answers

Answer: Transgenic

Explanation:

Since the thale cress is a plant that is genetically engineered with genes that break down toxic materials, the type of organism that is described here is the transgenic plant.

Transgene is when a gene is naturally transferred or transferred from an organism to another organism by genetic engineering method.

Therefore, the correct option is transgenic.

Answer:

The answer is B (transgenic)

Explanation:

Write a SELECT statement that returns these columns from the Customers table:
Customer last name customer_last name column
City customer_city column
Zip code customer_zip Column
Return only the rows with customer_state equal to IL .
Sort the results in Descending order of customer last name
SCHEMA:
CREATE TABLE customers
(
customer_id INT NOT NULL,
customer_last_name VARCHAR(30),
customer_first_name VARCHAR(30),
customer_address VARCHAR(60),
customer_city VARCHAR(15),
customer_state VARCHAR(15),
customer_zip VARCHAR(10),
customer_phone VARCHAR(24)
);
INSERT INTO customers VALUES
(1, 'Anders', 'Maria', '345 Winchell Pl', 'Anderson', 'IN', '46014', '(765) 555-7878'),
(2, 'Trujillo', 'Ana', '1298 E Smathers St', 'Benton', 'AR', '72018', '(501) 555-7733'),
(3, 'Moreno', 'Antonio', '6925 N Parkland Ave', 'Puyallup', 'WA', '98373', '(253) 555-8332'),
(4, 'Hardy', 'Thomas', '83 d''Urberville Ln', 'Casterbridge', 'GA', '31209', '(478) 555-1139'),
(5, 'Berglund', 'Christina', '22717 E 73rd Ave', 'Dubuque', 'IA', '52004', '(319) 555-1139'),
(6, 'Moos', 'Hanna', '1778 N Bovine Ave', 'Peoria', 'IL', '61638', '(309) 555-8755'),
(7, 'Citeaux', 'Fred', '1234 Main St', 'Normal', 'IL', '61761', '(309) 555-1914'),
(8, 'Summer', 'Martin', '1877 Ete Ct', 'Frogtown', 'LA', '70563', '(337) 555-9441'),
(9, 'Lebihan', 'Laurence', '717 E Michigan Ave', 'Chicago', 'IL', '60611', '(312) 555-9441'),
(10, 'Lincoln', 'Elizabeth', '4562 Rt 78 E', 'Vancouver', 'WA', '98684', '(360) 555-2680');

Answers

Answer:

SELECT customer_last_name, customer_city, customer_zip FROM customers WHERE customer_state = 'IL' ORDER BY customer_last_name DESC;

Explanation:

Here, we are given a SCHEMA with the table name customers.

It's creation command and commands to insert values are also given.

We have to print the customer last name, city and zip code of all the customers who have their state as IL in the decreasing order of their last names.

Let us learn a few concepts first.

1. To print only a specified number of columns:

We can write the column names to be printed after the SELECT command.

2. To print results as per a condition:

We can use WHERE clause for this purpose.

3. To print in descending order:

We can use ORDER BY clause with the option DESC to fulfill the purpose.

Therefore, the answer to our problem is:

SELECT customer_last_name, customer_city, customer_zip FROM customers WHERE customer_state = 'IL' ORDER BY customer_last_name DESC;

Output of the command is also attached as screenshot in the answer area.

Generally speaking, digital marketing targets any digital device and uses it to advertise and sell a(n) _____.


religion

product or service

governmental policy

idea

Answers

Answer:

product or service

Explanation:

Digital marketing is a type of marketing that uses the internet and digital media for the promotional purposes. It is a new form of marketing where the products are not physically present. The products and services are digitally advertised and are used for the popularity and promotion. Internet and digital space are involved in the promotion. Social media, mobile applications and websites are used for the purpose.

Answer:

A.) Product or service

Explanation:

Digital marketing is the practice of promoting products or services through digital channels, such as websites, search engines, social media, email, and mobile apps. The goal of digital marketing is to reach and engage with potential customers and ultimately to drive sales of a product or service. It can target any digital device that can access the internet, and it can use a variety of techniques such as search engine optimization, pay-per-click advertising, social media marketing, content marketing, and email marketing to achieve its objectives.

A video game character can face one of four directions

Answers

Really
I didn’t know that:)

Which of the following is NOT true?

a. The process provides the macro steps
b. Methodologies provide micro steps that never transcends the macro steps.
c. Methodologies provide micro steps that sometimes may transcend the macro steps.
d. A methodology is a prescribed set of steps to accomplish a task.

Answers

Answer:

b. Methodologies provide micro-steps that never transcends the macro steps.

Explanation:

Methodologies are a series of methods, processes, or steps in completing or executing a project. Projects can be divided into macro steps or processes and these macro steps can be divided into several micro-steps. This means that, in methodology, micro-steps always transcends to a macro-step.

Select the correct answer from each drop-down menu.
Complete the sentence listing the basic parts of a computer.
All computers have these four basic parts: an input device, a

Answers

Answer:

all computers have an input device, storage, proccesing,and output

hope it helped

Explanation:

3. Write a function named sum_of_squares_until that takes one integer as its argument. I will call the argument no_more_than. The function will add up the squares of consecutive integers starting with 1 and stopping when adding one more would make the total go over the no_more_than number provided. The function will RETURN the sum of the squares of those first n integers so long as that sum is less than the limit given by the argument

Answers

Answer:

Following are the program to this question:

def sum_of_squares(no_more_than):#defining a method sum_of_squares that accepts a variable

   i = 1#defining integer variable  

   t = 0#defining integer variable

   while(t+i**2 <= no_more_than):#defining a while loop that checks t+i square value less than equal to parameter value  

       t= t+ i**2#use t variable to add value

       i += 1#increment the value of i by 1

   return t#return t variable value

print(sum_of_squares(12))#defining print method to call sum_of_squares method and print its return value

Output:

5

Explanation:

In the program code, a method "sum_of_squares" is declared, which accepts an integer variable "no_more_than" in its parameter, inside the method, two integer variable "i and t" are declared, in which "i" hold a value 1, and "t" hold a value that is 0.

In the next step, a while loop has defined, that square and add integer value and check its value less than equal to the parameter value, in the loop it checks the value and returns t variable value.

Which formatting option(s) can be set for conditional formatting rules?

Answers

Answer:

D

Explanation:

Any of these formatting options as well as number, border, shading, and font formatting can be set.

Other Questions
Adam rode in a bike-a-thon. At the end of each hour of the bike-a-thon, he recorded the total distance he had traveled since the bike-a-thon began. This is shown in the table below. Based on this table, is the total distance traveled by Adam a function of time? HELPPPP Jonathan purchased pants for 25% off. the original cost of the pants were $54.75 what was the cost of the pants after discount? The aquarium has 198 fish tanks with 15 fish in each. They also have 297 tanks with 12 crustacean in each. Does the aquarium have more fish or crustaceans? Find the value of the missing angle in the triangle below: A store sold 156 boxes of candy canes over the holiday season. Each box contained 12 candy canes. How many candy canes were sold in all? PLZ HELP if u know the amswer Write the code for the method getNewBox. The method getNewBox will return a GiftBox that has dimensions that are m times the dimensions of its GiftBox parameter, where m is a double parameter of the method. For example, given the following code segment: GiftBox gift = new Gift Box (3.0, 4.0, 5.0): The call getNewBox , 0, 5). would return a GiftBox whose dimensions are: length = 1.5, width = 2.0, and height = 2.5 . Unit 8: Right Triangles & Trigonometry Date: Bell: Homework 3: Trigonometry: Ratios & Finding Missing Sides Which of the following conditions is necessary to prove that a quadrilateral is a parallelogram? A. the diagonals bisect each otherB. The diagonals are congruentC. The diagonals are perpendicularD. The diagonals intersect on the perpendicular bisector of the two sides? What is magnetism?O a property of all rocksO a property of all metalsO the force of attraction or repulsion of magnetic materialsO a force that depends on mass and distance Helppp please i need helppppppppoooo #1. please help me with my math Select All How many formula units are 113.5 grams of Ca(OH)2 A football team gained 9 yards on one play and then lost 22 yards on the next andfinally gained 12 yards on the final play. What is the result of the three plays? Tamara has a cell phone plan that charges $0.07 per minute plus a monthly fee of $19.00. She budgets $29.50 per month for total cell phone expenses. What is the maximum number of minutes Tamara could use her phone each month in order to stay within her budget? In the late 1600s, the change by the British government in enforcing colonial rules was called ? A. The Navigation Acts.B. The Frame of Government.C. Salutary neglectD. Self-government How is a triad constructed? yall im looking rough today...no filter What happens when you put Justin Bieber and lady Gaga together you get JUSTIN GAGA Select the correct text in the passage. Read the excerpt from "The Gift of the Magi" by O. Henry. Which sentence reveals the situational irony?