area - //Set the title of the window setTitle("Area of...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.util.*; import java.lang.*; import java.io.*; import java.text.*; import java.math.*; import java.text.DecimalFormat; import javax.swing.*; import java.awt.*; import java.awt.event.*; i public class area extends JFrame { private JLabel RadiusL, areaL; private JTextField RadiusTF, areaTF; private JButton calculateB, exitB; private CalculateButtonHandler cbHandler; private ExitButtonHandler ebHandler; private static final int WIDTH = 400; private static final int HEIGHT = 300; public area() { //Create the four labels RadiusL = new JLabel("Enter the Radius: ", SwingConstants.LEFT); areaL = new JLabel("The area of a circle: ", SwingConstants.LEFT); //Create the four text fields RadiusTF = new JTextField(10); areaTF = new JTextField(10); //Create Calculate Button calculateB = new JButton("Calculate"); cbHandler = new CalculateButtonHandler(); calculateB.addActionListener(cbHandler); //Create Exit Button exitB = new JButton("Exit"); ebHandler = new ExitButtonHandler(); exitB.addActionListener(ebHandler);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: //Set the title of the window setTitle("Area of a Circle"); //Get the container Container pane = getContentPane(); //Set the layout pane.setLayout(new GridLayout(3, 2)); //Place the components in the pane pane.add(RadiusL); pane.add(RadiusTF); pane.add(areaL); pane.add(areaTF); pane.add(calculateB); pane.add(exitB); //Set the size of the window and display it setSize(WIDTH, HEIGHT); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); } private class CalculateButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { double Radius, area,pie=3.1416; Radius = Double.parseDouble(RadiusTF.getText()); R area = pie*(Math.pow(Radius,2)); areaTF.setText("" + area); } } private class ExitButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { System.exit(0); } } public static void main(String args) { area voObject = new area(); } }...
View Full Document

This note was uploaded on 06/17/2011 for the course COMP 2302 taught by Professor Staff during the Spring '11 term at Kennesaw.

Page1 / 2

area - //Set the title of the window setTitle("Area of...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online