import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* Write a description of class MyFrame here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class MyFrame extends JFrame implements ActionListener
{
/**
* The container
*/
private Container c;
/**
* JLabel
*/
private JLabel massLabel;
/**
*
*/
private JTextField massInput;
/**
*
*/
private JButton calculate;
/**
* Initial all frame features
*/
public MyFrame()
{
// The basic features
this.setSize(400, 300);
this.setLocation(300, 300);
this.setTitle("My Frame");
// You can layout provided by Java
// Get container first
this.c = this.getContentPane();
// No layout
this.c.setLayout(null);
this.massLabel = new JLabel("Mass");
this.massLabel.setBounds(100, 100, 50, 30);
this.c.add(this.massLabel);
this.massInput = new JTextField();
this.massInput.setBounds(200, 100, 200, 25);
this.c.add(this.massInput);
this.calculate = new JButton("Press Me");
this.calculate.addActionListener(this);
//this.calculate.addActionListener(new ButtonEvent());
this.calculate.setBounds(200, 150, 100, 50);
this.c.add(this.calculate);
this.setVisible(true);
}
/**
*
*/
public void actionPerformed(ActionEvent e)
{
System.out.println("Hello, I am herer");
String myWeight = this.massInput.getText();
//String s = "170";
double ss = Double.parseDouble(myWeight);
// What you need to know in AP computer Science Test
// Math, Integer, Double, String, StringTokenizer
int radius = 5;
double area = Math.PI*radius*radius;
if(area > 50)
JOptionPane.showInternalConfirmDialog(null, "This area is greater then 50",
"Area", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
else
JOptionPane.showInternalConfirmDialog(null, "This area is less then 50",
"Area", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE);
System.out.println(ss/2);
}
}
make changes of this program