Using Java, create the following GUI:
Java Program:
/* Java Program that calculates Average Grade */
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.Math.*;
public class RectangleGUI extends JFrame implements
ActionListener
{
//Labels
JLabel lblLength, lblWidth, lblArea, lblPerimeter;
//Text fields
JTextField tfLength, tfWidth, tfArea,
tfPerimeter;
//Button
JButton btn1, btn2;
RectangleGUI()
{
GridLayout grid = new
GridLayout(6,4);
setLayout(grid);
//Setting properties of frame
setVisible(true);
setSize(350, 250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle(" Area and Perimeter of Rectangle");
//Labels setting
lblLength = new JLabel(" Enter the length: ");
lblWidth = new JLabel(" Enter the width: ");
lblArea = new JLabel(" Area: ");
lblPerimeter = new JLabel(" Perimeter: ");
//Creating text field objects
tfLength = new JTextField();
tfWidth = new JTextField();
tfArea = new JTextField();
tfPerimeter = new
JTextField();
//Creating button object
btn1 = new JButton(" Calculate ");
btn2 = new JButton(" Exit ");
//Adding action listener
btn1.addActionListener(this);
// Exit button click event
btn2.addActionListener(new
ActionListener()
{
public void
actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
//Setting display position of
labels
lblLength.setBounds(80, 70, 200,
30);
lblWidth.setBounds(80, 110, 200, 30);
lblArea.setBounds(80, 150, 200, 30);
lblPerimeter.setBounds(80, 250, 200, 30);
//Setting display position of text
fields
tfLength.setBounds(300, 70, 200,
30);
tfWidth.setBounds(300, 110, 200,
30);
tfArea.setBounds(300, 150, 200, 30);
tfPerimeter.setBounds(300, 190, 200, 30);
//Setting display position of
button
btn1.setBounds(300, 300, 200,
200);
btn2.setBounds(400, 400, 200,
200);
//Adding to frame
add(lblLength);
add(tfLength);
add(lblWidth);
add(tfWidth);
add(lblArea);
add(tfArea);
add(lblPerimeter);
add(tfPerimeter);
add(btn1);
add(btn2);
}
//Button action event
public void actionPerformed(ActionEvent e)
{
double avg;
//Getting values from text
boxes
double len =
Double.parseDouble(tfLength.getText());
double wid =
Double.parseDouble(tfWidth.getText());
double area;
double perimeter;
//Calculating area and
perimeter
area = len*wid;
perimeter = 2*(len+wid);
//Displaying futureVal
tfArea.setText(String.format
("%.1f", area));
tfPerimeter.setText(String.format
("%.1f", perimeter));
}
//Main function
public static void main(String args[])
{
new RectangleGUI();
}
}
_____________________________________________________________________________________________________
Sample Run:
Using Java, create the following GUI: Area and Perimeter of a Rectangle Enter the lengttc 25...
Using Python Write the following well-documented (commented) program. Create a class called Shape that has a method for printing the area and the perimeter. Create three classes (Square, Rectangle, and Circle) which inherit from it. Square will have one instance variable for the length. Rectangle will have two instance variables for the width and height. Circle will have one instance variable for the radius. The three classes will have methods for computing the area and perimeter of its corresponding shape....
Description Create an object-oriented program that uses inheritance to perform calculations on a rectangle or a square. Sample Output (Your output should be similar to the text in the following box) Rectangle Calculator Rectangle or square? (r/s): r Height: 5 Width: 10 Perimeter: 30 Area: 50 Continue? (y/n): y Rectangle or square? (r/s): s Length: 5 Perimeter: 20 Area: 25 Continue? (y/n): n Thank you for using my app Specifications Use a Rectangle class that provides attributes to store the...
Q2) Interface Create a program that calculates the perimeter and the area of any given 2D shape. The program should dynamically assign the appropriate calculation for the given shape. The type of shapes are the following: • Quadrilateral 0 Square . Perimeter: 4xL • Area:LXL O Rectangle • Perimeter: 2(L+W) • Area:LxW Circle Circumference: I x Diameter (TT = 3.14) Area: (TT xD')/4 Triangle (assume right triangle) o Perimeter: a+b+c O Area: 0.5 x base x height (hint: the base...
java language Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectangle, Triangle which extend the Shape class and implements the abstract methods. A circle has a radius, a rectangle has width and height, and a triangle has three sides. Software Architecture: The Shape class is the abstract super class and must be instantiated by one of its concrete subclasses: Circle, Rectangle, or...
Go to the Java API and review the Rectangle class briefly. As directed below, create a subclass of the Rectangle class called BetterRectangle as described below. Create another class called RectangleTester, which fully tests the BetterRectangle, by displaying a menu that allows a user to process data for multiple rectangles until they choose to quit. Be sure to include sample runs as block comments in your tester source code file. P9.10 The Rectangle class of the standard Java library does...
This exercise guides you through the process of converting an Area and Perimeter application from a procedural application to an object-oriented application. Create and use an object 1. Open the project named ch04_ex2_Area and Perimeter that’s stored in the ex_starts folder. Then, review the code for the Main class. 2. Create a class named Rectangle and store it in the murach.rectangle package. 3. In the Rectangle class, add instance variables for length and width. The, code the get and set...
part A) using java methods calculate the area of rectangle. part B) modify to calculate the area of rectangle, circle, triangle and square this time using switch statement, input validation, loop for choices and document the program.
please answer all C. 2. What rectangle has the smallest perimeter, for a given area? Suppose you want a rectangle with area 200. What choice of length L and width W will give the smallest perimeter? a. Sketch a rectangle and label it as having length L and width W. b. Write the area in terms of length and width: A = Write the perimeter in terms of length and width: P = d. If L = 200 and W...
JAVA Create a simple Graphical User Interface (GUI) in java with the following requirements: The interface components will appear centered in the interface, and in two rows. o Row one will have a Label that reads “Please enter a valid integer:” and a Text Field to take in the integer from the user. o Row two will have a Button that when pressed converts the integer to binary The conversion will be completed using recursion – A separate...
Area Program – Build a Java Class to Calculate the area of a Figure(call it “Area.java”. The figure may be a circle, or a square or a rectangle. The user will enter the type of figure they want through a Scanner. If they enter a “C”, proceed to calculate the area of the Circle using values read in for radius. If they enter an “S”, then calculate the area of a Square using values read in for side. If they...