Question

Write a program that allows the user to specify a circle by clicking on the center...

Write a program that allows the user to specify a circle by clicking on the center and then typing the radius in the JOptionPane dialog box. No other capabilities are required. Circle are drawn upon clicking the center position and entering the value of the radius.Write a program that allows the user to specify a

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Note: the programming specifications are not clear. I implemented as per the sentences provided at the top of the image

Java code:

import javax.swing.*;

import java.awt.*;

import java.awt.geom.*;

import javax.swing.JOptionPane;

//CLASS name DrawingColorCircle

public class DrawingColorCircle

{

//METHOD main

public static void main(String[] args)

{

                    //JOptionpane is getting radius

         JOptionPane.showInputDialog("Enter radius: ");

        DrawingColorCircle c =new DrawingColorCircle();

}

//constructor for circle

public DrawingColorCircle()

{

    //setting frame components

    JFrame frameVal = new JFrame("DRAWING CIRCLE");

    frameVal.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frameVal.getContentPane().add(new MyCircleComponent());

    frameVal.setSize(400,400);

    frameVal.setVisible(true);

}

//CIRCLE COMPONENTS CLASS

public class MyCircleComponent extends JComponent

{

//METHOD PAINT

   public void paint(Graphics g1)

{

              int radius = 2* 100;

            int x1 = 0;

              int y1 = 0;

Graphics2D g3= (Graphics2D) g1;

Ellipse2D.Double circle1 = new

Ellipse2D.Double( x1, y1, radius, radius);

              g1.setColor(Color.black);

              g3.draw(circle1);

     }

}

}

Add a comment
Know the answer?
Add Answer to:
Write a program that allows the user to specify a circle by clicking on the center...
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
  • write pseudocode to represent the logic of a program that allows the user to enter a...

    write pseudocode to represent the logic of a program that allows the user to enter a value for the radius of a circle. The program calculates the diameter by multiplying the radius by 2, and then calculates the circumference by multiplying the diameter by 3.14. The program outputs both the diameter and the circumference.

  • Write a console program in Java that allows the user to specify a text file, opens...

    Write a console program in Java that allows the user to specify a text file, opens the file, and prints a two-column table consisting of all the words in the file together with the number of times that each word appears. Words are space-delimited and case-sensitive. The table should list the words in alphabetical order. Proper code documentation should be included in the source code.

  • Need help on following Java GUI problem: Write a program that lets a user display and...

    Need help on following Java GUI problem: Write a program that lets a user display and modify pictures. Create a window. Add four buttons so that clicking a particular button will shift the image by a small amount in the north, south, east or west direction inside the window. Add a menu bar with two menus: File and Image. The File menu should contain an Open menu item that the user can select to display JPEG and PNG files from...

  • Write a java program that compute the circumference and area of a circle from the user...

    Write a java program that compute the circumference and area of a circle from the user input for a radius.

  • Write a Java program which allows the user to perform simple tasks on a calculator. A...

    Write a Java program which allows the user to perform simple tasks on a calculator. A series of methods allows the user to select an operation to perform and then enter operands. The first method displays a menu, giving the user the choice of typing in any one of the following: +, -, *, /, or % representing the usual arithmetic operators (Each operation should be done on numbers negative(-) to positive(+), positive(+) to negative(-), negative(-) to negative(-), and positive(+)...

  • Please write in JAVA ONLY Please use a dialog box to prompt the user to enter...

    Please write in JAVA ONLY Please use a dialog box to prompt the user to enter the radius for a circle (radius should be a double). Then, use a Message Box to display the Radius, Area and Circumference of the circle with that Radius. You will use the Math class constant Math.PI to calculate the Area and Circumference.

  • NOTE: Use JOptionPane NOT Scanner Please Write an application that allows a user to enter the...

    NOTE: Use JOptionPane NOT Scanner Please Write an application that allows a user to enter the names and birthdates of up to 10 friends. Continue to prompt the user for names and birthdates until the user enters the sentinel value ZZZ for a name or has entered 10 names, whichever comes first. When the user is finished entering names, produce a count of how many names were entered, and then display the names. In a loop, continuously ask the user...

  • Write a program that will allow the user to specify how many times the program will...

    Write a program that will allow the user to specify how many times the program will loop and display the title of the program include your name in the title, print from in the loop a string and count. -Assembly Language MASM 8086

  • Write a program that allows a user to view a table of temperature conversion. The user...

    Write a program that allows a user to view a table of temperature conversion. The user should be able to enter a starting value and an ending value in to textboxes. Your program will display a list of temperature conversion from Celsius to Fahrenheit in a text area like the example below: You can choose any color, design and font for this interface. Use javafx scene builder for program. When you click on "Display" button it read values from text...

  • *KEEP IT SIMPLE PLEASE* Write a program that allows the user to convert any integer number...

    *KEEP IT SIMPLE PLEASE* Write a program that allows the user to convert any integer number to Roman numeral and the other way around. - You should create and print a menu that allows the user to select either Roman to Int or Int to Roman. - If one option is selected then you should promote the user to enter the number and then you print the equivalence in the other system. - Validate input, i.e Roman numerals should be...

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