Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

These require you to explore the NetBeans interface. Feel free to explore around, use the help features, use the NetBeans tutorials, etc. to discover how

These require you to explore the NetBeans interface. Feel free to explore around, use the help features, use the NetBeans tutorials, etc. to discover how to do them.

  1. Align the text fields on the right, which is typical for numbers.

  2. Make the Area and Circumference text boxes uneditable.

  3. Format the area and circumference values with two decimal places. (Read more about different ways to format numbers in Java.

  4. After the clear button is clicked, put the insertion point in the radius text box. (HINT: this is a focus event)

  5. Instead of making the calculations within the method, add a Circle.java class to the project and create a circle object. Use the methods we wrote earlier to calculate the area and circumference in your button click events instead of doing the calculations there directly. (HINT: right-click the package and add a new Java class called Circle.java, then copy and paste your code into that file) This uses a technique called Model-View-Controller where we separate out the GUI code from the classes that model objects in the application.

circle.java

public class Circle { //data members private int radius; private int x; private int y; //constructors /** * Creates a circle with a specified radius centered at (0,0) * @param r the radius in pixels **/ public Circle(int r) { setRadius(r); setCenter(0, 0); } /** * Creates a circle with a specified radius and center * @param r the radius in pixels * @param center the (X,Y) coordinate to position the circle at **/ public Circle(int r, int x, int y) { setRadius(r); setCenter(x, y); } //accessor & modifier methods /** * Returns the radius * @return radius length in pixels **/ public int getRadius() { return this.radius; } /** * Returns the x location of the center of the circle * @return location of center of circle **/ public int getX() { return this.x; } /** * Returns the y location of the center of the circle * @return location of center of circle **/ public int getY() { return this.y; } /** * Sets a new radius value for the circle * @param radius length in pixels **/ public void setRadius(int radius) { if(radius>0) this.radius = radius; } /** * Sets a new x coordintate for the center point for the circle * @param x the x coordinate for the center **/ public void setX(int x) { this.x = x; } /** * Sets a new y coordintate for the center point for the circle * @param y the y coordinate for the center **/ public void setY(int y) { this.y = y; } /** * Sets a new center point for the circle * @param x the x coordinate for the center (0 or greater) * @param y the y coordinate for the center (0 or greater) **/ public void setCenter(int x, int y) { setX(x); setY(y); } /** * Calculates the area of the circle * @returns the area of the circle in pixels **/ public double area() { return Math.PI * radius * radius; }

/** * Calculates the circumference of the circle * @returns the circumference of the circle in pixels **/ public double circumference() { return Math.PI * 2 * radius; } /** * Creates a text representation of the circle * @return a string representing the circle **/ public String toString() { String description = "This circle has a radius of " + this.radius + " pixels and is located at (" + x + ", " + y + ")"; return description; }

}//end of Circle class

Include UI code if possible

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

Students also viewed these Databases questions

Question

=+1 What would you do if you were the IHR manager?

Answered: 1 week ago