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

Which Cisco IOS command will permit the engineer to modify the current configuration of the switch while it is powered on?

Answers

Configure terminal because Commands in this mode are written to the running configuration file as soon as you enter them (using the Enter key/Carriage Return). After you enter the configure terminal command, the system prompt changes from switch# to switch(config)#, indicating that the switch is in configuration mode.

:) :) :):):):)):):):)):)/):))::)):):):):):)):):)):):))/):):))

Answers

Answer:

:)))))))))))))))))))))))))))))))))))))))) thanks

Use the drop-down tool to select the phrase that completes each sentence,
In Windows, deleted files go to the
If you want to see the most information about a file, you can view them in
A file manager can help you
DONE
I

Answers

Answer:

1. recycle bin

2. details view

3. move a file

Explanation:

i did the assignment on edge. and got it right

Answer:

In Windows, deleted files go to the

✔ Recycle Bin

If you want to see the most information about a file, you can view them in

✔ details view

A file manager can help you

✔ move a file

Explanation: Hope it helps ^w^

Even with a quality burglary-resistant chest on the premises, special function locks may be appropriate because:________.
a. A dishonest worker might open the safe at night .b. A burglar may force a worker to open the safe during working hours.c. Without special locking devices, workers may be tempted to leave the safe unlocked for easy access during the day.d. All of the above

Answers

Answer:

d ) all of the above

Explanation:

is the correct answer

help please with the question in the photo

Answers

Answer:

A

Explanation:

A because, why would someone want to listen to your own interests?

What input is needed for the defined output?

Answers

Answer:

The data that are needed to be included in the output is called as

Inputs are the signals or data received by the system and outputs are the signals or data sent from it. The term can also be used as part of an action; to "perform I/O" is to perform an input or output operation

having a bad day? enjoy this front view of phinias (can't spell his name)​

Answers

Answer:

ouch what happened to him

congrats you ruined my childhood

(thanks for the free points!!)

If you are a mathematics student and want to study the secret of writing cryptographic codes, algorithms, encryption and decryption techniques, then you are learning about cryptography.

If you are a cryptography student and want to write a PHD style paper on cryptography and cryptanalysis, then you are learning about cryptology.

If you work at the code breaking division at the National Security Agency (NSA), then you are part of which team?

A. Cryptosystems Team
B. Cryptanalysis Team
C. Cryptologist Team
D. Cracker Team​

Answers

Answer:

d

Explanation:

hi

what is the operating system on an IBM computer?​

Answers

Answer:

OS/VS2 and MVS

Explanation:

IBM OS/2, is full International Business Machines Operating System/2, an operating system introduced in 1987 IBM and the Microsoft Corporation to operate the second-generation line of IBM personal computers, the PS/2 (Personal System/2.) hope this helps! Pleas mark me as brainliest! Thank you! :))

Problem 4 (25 points)Consider a byte addressing architecture with 64-bit memory addresses.(a)Which bits of the address would be used in the tag, index and offset in a direct-mapped cache with 512 1-word blocks. 3(b)Which bits of the address would be used in the tag, index and offset in a direct-mapped cache with 64 8-word blocks.(c)What is the ratio of bits used for storing data to total bits stored in the cache in each of the above cases

Answers

Answer:

Following are the solution to the given points:

Explanation:

The Memory address value = 64 bit

The Size of the word [tex]= \frac{64}{8} =8 \ Byte[/tex]

In point a:

The offset size [tex]= 3\ bits[/tex] ( in 1-word block size)  

The Index size [tex]= 9 \ bits[/tex] (as block number =512)  

Tag size [tex]= 64 - 12 = 52\ bits[/tex]

In point b:

The offset size [tex]= 8 \times 8 \ bytes = 2^6 = 6 \ bits.[/tex]

The Index size [tex]= 64 \ bits = 2^6 \ =6 \ bits[/tex]

Tag size  [tex]= 64 - 12 = 52\ bits[/tex]

In point c:

The Ratio at point a  

[tex]\to 3:64[/tex]

The Ratio at point b

[tex]\to 6:64[/tex]

Why are people's visions of utopias and dystopias subjective?
A. Because the vision one person has of paradise will likely match
the vision most people have of a utopia
B. Because only certain technologies make things better and
different ones make things worse in a dystopia
C. Because all technology is dangerous and can lead to the downfall
of all societies, resulting in dystopia
D. Because the technology needed for one person's utopia may be
what creates disaster for another person's dystopia

Answers

Answer:

D. Because the technology needed for one person's utopia may be what creates disaster for another person's dystopia.

Explanation:

Because the technology needed for one person's utopia may be what creates disaster for another person's dystopia are people's visions of utopias and dystopias subjective. Thus option D is correct.

What are utopias and dystopias?

Speculative fiction categories that study social as well as political structures include utopian and dystopian literature. In order to pique readers' interest, utopian fiction often depicts a world that adheres to the author's ethics and has many elements of a different reality.

Ultimately, it all varies depending on who you ask. A person's dystopia may be another person's utopia. We don't all have the same notions regarding what a utopia would look like, which is, in my opinion, one of the grounds why people don't live in one. Therefore, option D is the correct option.

Learn more about utopias and dystopias, Here:

https://brainly.com/question/905235

#SPJ2

You are part of a sales group that has been asked to give a presentation.
Before you begin, what should you and your group do?
O A. Figure out who is the best public speaker.
O B. Look into file-sharing options so that everyone can work on the
same file at the same time.
OC. Buy the best software on the market.
O D. Ask if you have to give a slide presentation.

Answers

The answer is the 2 one becuase I took the test

What is meant by the term visual communication?

Answers

Answer:

eye contact

Explanation:

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:

Which important aspect of the Roman Empire did the barbarians destroy?

Answers

Answer:

centers of learning

Explanation:

Under the leadership of Emperor Valens, Rome was already having financial hardships. This meant that it didn't have enough money left to repair its empire nor to strengthen it against invaders. Soon, the barbarians such as the Franks, Huns, Saxons, etc. started attacking Rome. They spent a lot of time destroying the outer regions of the empire because they were also at war with each other. They penetrated Rome and it soon fell. The barbarians didn't only destroy the cities but they also destroyed the "centers of learning." Roman people were known to value education. With the fall of the Roman Empire, so did education and sophisticated architectures follow.  

Answer:

i dont know but them barbs are crazy can't believe they were a thing back then

Explanation:

lol

How do you overload a C2677 error code in c++ for '-'?

Answers

The answer is the c++ one I know becuase I took the test

Should video gaming be considered a school sport?

Answers

Answer:

I believe it should be in higher grades such as high school or college so people don't abuse it like little kids might.

Answer:

No because the defininition of sports is an activity involving physical exertion and Video games don't involve physical extertion.

The question is in the photo

Answers

Answer:

a

the most suitable answer

What is Microsoft PowerPoint?
Oa presentation program included with Microsoft Office
oa project management program available only in certain versions of Microsoft Office
Oa desktop publishing program included with Microsoft Office
oa collaboration program available only in certain versions of Microsoft Office

Answers

Answer:

ITS THE FIRST ONE :)

Explanation:

ALSO IF ITS NOT THE FIRST ONE GO ON YT!

Is anyone else having an issue with brainly mobile, where they don't let you watch ads? If so, what do you do to fix it?​

Answers

Answer:

no im not

Explanation:

but i sorry that you are

A strictly dominates choice B in a multi-attribute utility. It is in your best interest to choose A no matter which attribute youare optimizing.

a. True
b. False

Answers

Answer:

A strictly dominates choice B in a multi-attribute utility. It is in your best interest to choose A no matter which attribute youare optimizing.

a. True

Explanation:

Yes.  It is in the best interest to choose option A which dominates choice B.  A Multiple Attribute Utility involves evaluating the values of alternatives in order to make preference decisions over the available alternatives.  Multiple Attribute Utility decisions are basically characterized by multiple and conflicting attributes.  To solve the decision problem, weights are assigned to each attribute.  These weights are then used to determine the option that should be prioritized.

What is the purpose of a Hyperlink

Can you answer both

Answers

Answer:

Number 16 is A Or B And Number 17 is B I think

Explanation:

Which interpersonal skill is the most important for a telecom technician to develop?
teamwork
active listening
conflict resolution
social awareness

Answers

Answer: Interpersonal communication is the process of face-to-face exchange of thoughts, ideas, feelings and emotions between two or more people. This includes both verbal and nonverbal elements of personal interaction.

Explanation:

i think plz dont be mad

Question # 6
Dropdown
Choose the correct ending to the sentence below.


The function localtime() _____________________

Answers

Answer:

returns a different value every time you use it

Explanation: :)

If an object someThing has a method someMethod( ), then you can call the method using the statement ____________ .
a. someMethod(someThing);
b. someThing.someMethod( );
c. someMethod.someThing() ;
d. someThing = someMethod( );

Answers

Answer:

C) someThing.someMethod( )

Explanation:

The methods in a class can be accessed outside the class (assuming they are public methods and not private to the class) by using the dot(.) symbol and calling the method on the instance or object of the class.

In this case, the object of the class someThing, calls the method, someMethod( ) by using a dot and the name of the method with a parentheses at the end. This enables the code in the method act on the class instance or object.

Write a program that asks the user for a word. Next, open up the movie reviews.txt file and examine every review one at a time. If a review contains the desired word you should make a note of the review score in an accumulator variable. Finally, produce some output that tells your user how that word was used across all reviews as well as the classification for this word (any score of 2.0 or higher can be considered

Answers

Answer:

import numpy as np

word = input("Enter a word: ")

acc = []

with open("Downloads/record-collection.txt", "r") as file:

   lines = file.readlines()

   for line in lines:

       if word in line:

           line = line.strip()

           acc.append(int(line[0]))

   if np.mean(acc) >= 2:

       print(f"The word {word} is a positive word")

       print(f"{word} appeared {len(acc)} times")

       print(f"the review of the word {word} is {round(np.mean(acc), 2)}")

   else:

       print(f"the word {word} is a negative word with review\

{round(np.mean(acc), 2)}")

Explanation:

The python program gets the text from the review file, using the user input word to get the definition of reviews based on the word, whether positive or negative.

The program uses the 'with' keyword to open the file and created the acc variable to hold the reviews gotten. The mean of the acc is calculated with the numpy mean method and if the mean is equal to or greater than 2 it is a positive word, else negative.

Guys, please help me asap (Photo Attached) !!!!!!! HELP 25pts!!!!

Answers

The answer is the first number line.

30/150 = 1/5 = 20%

Answer:

20%

Convert fraction (ratio) 30 / 150 Answer: 20%

The first one.

Please I need one more braniest for 'expert' may I get it?

Explanation:

If a computer reboots itself on its own, the computer might have a(n) access problem. hardware problem. Internet problem. software problem.

Answers

Answer:

D) Software problem

Explanation:

plz give me brainliest

D

edge2021      YWWWWWWWWWWWWWWWWWWWWW                                  

Suppose that a t-shirt comes in five sizes: S, M, L, XL, XXL. Each size comes in four colors. How many possible t-shirts are there?

Answers

Answer:

120

Explanation:

This question is basically asking how many ways can we arrange 5 sizes of shirts if they come in 4 colors.

5 permutation of 4

To find permutation, we use the formula

P(n, r) = n! / (n - r)!

Where

n is the size of the shirts available, 5

r is the color of each shirt available, 4

P(5, 4) = 5! / (5 - 4)!

P(5, 4) = (5 * 4 * 3 * 2 * 1) / 1!

P(5, 4) = 120 / 1

P(5, 4) = 120

Therefore, the total number of shirts available is 120

C++ please
Write a program that does the following.
Create a dynamic two dimensional squarearray of unsigned integers (array_one). Prompt the user to enter the number of rows and columns they want (maximum of 30) (rows and columns must be the same for a square array)
Pass the array to a function that will initialize the two dimensional array to random numbers between 0 and 4000 using the rand() library function. Here is the kicker: The array cannot have any repeated values!
Create another dynamic two dimensional array of the same size (array_transpose)
Pass both arrays to a function that will generate the transpose of array_one returning the values in array_transpose. (If you don’t already know the transpose swaps the rows and columns of an array.) Example: Suppose you have a 4 x 4 array of numbers (array_one). The transpose is shown below (array_transpose)
Array One Array Transpose
1 2 3 4 1 5 9 13
5 6 7 8 2 6 10 14
9 10 11 12 3 7 11 15
13 14 15 16 4 8 12 16
Pass each array to a print_array function that will print (to the screen or a file) the results of a test case with a 20 by 20 array.

Answers

Answer:

#include <iostream>

#include <cstdlib>

#include <ctime>

using namespace std;

int main(){

   int n;

   cout<< "Enter the row and column length: ";

   cin>> n;

   int array_one[n][n];

   int array_transpose[n][n];

   for (int i = 0; i < n; i++){

      for (int j= 0; j < n; j++){

           srand((unsigned) time(0));

           array_one[i][j] = (rand() % 4000)

           array_transpose[j][i] = array_one[i][j];

       }

   }

}

Explanation:

The C source code has three variables, 'array_one', array_transpose' (both of which are square 2-dimensional arrays), and 'n' which is the row and column length.

The program loops n time for each nth number of the n size to assign value to the two-dimensional array_one. the assign values to the array_transpose, reverse the 'i' and 'j' values to the two for statements for array_one to 'j' and 'i'.

Other Questions
Read the following sentence:"When you look at a basketball, what are you seeing?"Why might the author have started the passage with this question? ato give the reader an object to visualize before examining the role of light bbecause the main idea of the passage is about basketball cbecause the author wants to use the example of basketball to explain electromagnetic radiation dto show how important the color orange is to electromagnetic waves 56:51Collecting research data is the final step in the scientific method.True or false The function's only behavior should be to return the sum of array userVals' elements. What common error does the function make?Assume userVals always has exactly 10 elements. int SumArray Elements(int uservals[]) { for (i = 1; i Which of the following situations has more kinetic energy than potential energy?a rock at the edge of a cliffan archers bow that is drawn backa rolling bowling balla car waiting at a red light need help ASAP mid term . - 60 points Societies may use which of the following systems to organize the production and distribution of goods and services?A market systemB purchase systemC primary systemD labor system what is 266 divided by 14 In bio-medical science do i need to know how to read a finger-print? Isn't my cat pretty? What is the quotient of 1/10 and 9/10 WILL GIVE BRAINLIEST NEED HELP ASAP!!!Theodore Roosevelt's Square Deal and Woodrow Wilson's New Freedom shared the goal of___? What was Willam Cockerill's role in the spread of industrialization?He established the first railroad in Great Britain.He helped bring industrialization to continental Europe.He pioneered manufacturing methods in the United States.He developed efficient coal mining techniques. Susan is throwing a Halloween party at her house, but you've forgotten which house it is! You know that Laura does NOT live directly next to Susan. Kate and Eve are direct neighbors, and Laura lives further to the right of Eve. Which one is Susan's house? ........................ \ \ \ \ \ \ \ Doug is a salesperson at a retail store and earns $90 per week plus 5% of his weekly sales. If Doug makes $630 one week, what are his sales that week? According to Newtons third law of motion, what happens when you push against a wall?The wall does not resist at all.The wall pushes back at you with the same amount of force.The wall pushes back at you with half as much force as you push against it.The wall pushes back at you with twice as much force as you push against it. Select the documents below that set the legal precedent for the US Bill of Rights.Question 1 options:Virginia Declaration of RightsDeclaration of IndependenceEnglish Bill of Rights 1689Articles of ConfederationMagna Carta 1215US ConstitutionNorthwest Ordinances (1785 & 1787)The Olive Branch Petition What is the slope of the line on the graph below I need help with the 4.15 Project in history. I'll send you the picture for the question