Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

CS is smalltime

Name: Anonymous 2010-10-27 0:50

Game Designer here, CS degrees are small time. Enjoy your no job.

Name: Anonymous 2010-10-27 4:47

HTH, HAND

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Rectangle extends JFrame {
    private JLabel lengthL, widthL, areaL, perimeterL;
    private JTextField lengthTF, widthTF,areaTF, perimeterTF;
    private JButton calculateB, exitB;

    private static final int WIDTH = 400;
    private static final int HEIGHT = 300;

    public Rectangle () {
        lengthL = new JLabel("Enter the length: ", SwingConstants.RIGHT);
        widthL = new JLabel("Enter the width: ", SwingConstants.RIGHT);
        areaL = new JLabel("Area: ",SwingConstants.RIGHT);
        perimeterL = new JLabel("Perimeter: ", SwingConstants.RIGHT);

        lengthTF = new JTextField(10);
        widthTF = new JTextField(10);
        areaTF = new JTextField(10);
        perimeterTF = new JTextField(10);

        calculateB = new JButton("Calculate");
        calculateB.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                double width, length, area, perimeter;

                length = Double.parseDouble(lengthTF.getText());
                width = Double.parseDouble(widthTF.getText());
                area = length * width;
                perimeter = 2 * (length + width);

                areaTF.setText("" + area);
                perimeterTF.setText("" + perimeter);
            }
        });

        exitB = new JButton("Exit");
        exitB.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });

        setTitle("Area and Perimeter of a Rectangle");
       
        Container pane = getContentPane();
        pane.setLayout(new GridLayout(5,2));
        pane.add(lengthL);
        pane.add(lengthTF);
        pane.add(widthL);
        pane.add(widthTF);
        pane.add(areaL);
        pane.add(areaTF);
        pane.add(perimeterL);
        pane.add(perimeterTF);
        pane.add(calculateB);
        pane.add(exitB);

        setSize(WIDTH,HEIGHT);
        setVisible(true);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
        new Rectangle();
    }
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List