Question

I need help writing this java program, here is what it wants me too code. Write...

I need help writing this java program, here is what it wants me too code.

Write a JavaFX application that draws a circle using a rubberbanding technique. The circle size is determined by a mouse drag. Use the initial mouse press location as the fixed center point of the circle. Compute the distance between the current location of the mouse pointer and the center point to determine the current radius of the circle.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.applet.Applet; import java.awt.Graphics; import java.util.Random; import java.awt.Color; import java.awt.event.MouseMotionListener; import java.awt.event.MouseListener; import java.awt.event.*; public class Rubberband extends Applet implements MouseMotionListener , MouseListener { int status; int x1=0; int x2=0; int y1=0; int y2=0; public void init() { addMouseListener(this); addMouseMotionListener(this); }     public void mouseMoved(MouseEvent e){} public void mouseClicked(MouseEvent e) { status=1; x1=e.getX(); y1=e.getY(); } public void mouseDragged(MouseEvent e) { x2=e.getX(); y2=e.getY(); repaint(); } public void mouseReleased(MouseEvent e){} public void mousePressed(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} // write paint() method to draw on applet window public void paint(Graphics g) { while(status==1) { g.setColor(Color.red); int dis=(int)Math. sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)); g.drawOval(x1-dis,y1-dis,2*dis,2*dis); } } }
Add a comment
Know the answer?
Add Answer to:
I need help writing this java program, here is what it wants me too code. Write...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Program for Java The MyRectangle2D class was defined in Exercise 10.12. Write an application that enables...

    Program for Java The MyRectangle2D class was defined in Exercise 10.12. Write an application that enables the user to specify the location and size of the rectangles and displays whether the two rectangles intersect, as shown in the following figure. Enable the user to point the mouse inside a rectangle and drag it. As the rectangle being dragged, the rectangle center coordinates in the text fields are updated. Program for JavaThe MyRectangle2D class was defined in Exercise 10.12. Write an...

  • This task is a program framework that you should complete. The program should allow the user...

    This task is a program framework that you should complete. The program should allow the user to move a circular figure with the mouse over a drawing area. The current position of the figure is displayed continuously: Given is the main program: import javafx.scene.Scene; import javafx.application.Application; import javafx.beans.value.*; import javafx.scene.*; import javafx.scene.paint.Color; import javafx.scene.text.Text; import javafx.stage.Stage; public class Main extends Application { private DraggableCircle dc; private Text text; private void updateText() { text.setText("("+dc.getCenterX()+", "+dc.getCenterY()+")"); } @Override public void start(final Stage...

  • Need help with java programming. Here is what I need to do: Write a Java program...

    Need help with java programming. Here is what I need to do: Write a Java program that could help test programs that use text files. Your program will copy an input file to standard output, but whenever it sees a “$integer”, will replace that variable by a corresponding value in a 2ndfile, which will be called the “variable value file”. The requirements for the assignment: 1.     The input and variable value file are both text files that will be specified in...

  • Can you help me to write a Java code for this: The program must satisfy the...

    Can you help me to write a Java code for this: The program must satisfy the following requirements: The program should ask the user the following information The site names for 6 locations (into an array) The cash donation for 6 locations (into an array) The food donations in pounds for 6 locations (into an array) Is there another test they want to process, meaning do they want to run the program again? Based on the input, the program will...

  • Please help me the JAVA program - Choose Your Operation Write a program that uses a...

    Please help me the JAVA program - Choose Your Operation Write a program that uses a WidgetView object to do the following: Generate two random integers between 1 and 9 (inclusive). Name one of them x, the other y. Display them to the user using JLabel objects. Create a JLabel object displaying the text "Enter an operation number." Create a JTextField for the user's input. Create a JButton displaying the text "Press here when you've entered your operation." Use addAndWait...

  • I need help writing this code for java class. Starter file: Project3.java and input file: dictionary.txt...

    I need help writing this code for java class. Starter file: Project3.java and input file: dictionary.txt Project#3 is an extension of the concepts and tasks of Lab#3. You will again read the dictionary file and resize the array as needed to store the words. Project#3 will require you to update a frequency counter of word lengths every time a word is read from the dictionary into the wordList. When your program is finished this histogram array will contain the following:...

  • I need help writing this C code. Here is the description: Let's say we have a...

    I need help writing this C code. Here is the description: Let's say we have a program called smart typing which does two things: The first letter of a word is always input manually by a keystroke. When a sequence of n letters has been typed: c1c2...cn and the set of words in the dictionary that start with that sequence also have c1c2...cnc then the smart typing displays c automatically. we would like to know,  for each word in the dictionary,...

  • I need help with turtle graphics assignment in python 3, please! Write a program named Lastname_firstname_clock.py to display a clock face with hands showing the current time. The radius of the clock...

    I need help with turtle graphics assignment in python 3, please! Write a program named Lastname_firstname_clock.py to display a clock face with hands showing the current time. The radius of the clock face (the distance from the center to the hour markers) is 150. The hour hand has length 100, and the minute hand has a length of 120 You may design the clock in one of three ways: using the square cursor shape (hint: stamp)) for the hour markers...

  • Can you help me with a Java Code: We are to write software for the checkout...

    Can you help me with a Java Code: We are to write software for the checkout system of a video game rental store. Note: You are not writing the entire checkout system. You are responsible for writing (and testing!) only the age-restricted part of the system. The specification for your system is as follows: At the start of each rental transaction, the system will first scan a barcode to do a customer lookup. (Assume other people in the company will...

  • Not too sure what my professor wants me to put down here... if you could help...

    Not too sure what my professor wants me to put down here... if you could help me with an outline and some examples from my points that would help.. thanks 3. You will have this question most every lab) On separate lines list each measurement name, average (or representative) value tuncertainty (state as readability reason for uncertainty) EXAMPLE Distance between t0024 lml each repeated the measurement four times and this was our (uscertainty) which came parallax.) Don't listan the measurements...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT