Area Calculator Program using Java AWT
Here you will learn and get the example code to make an area calculator program using java AWT(Abstract Window Toolkit) that supports Graphical User Interface (GUI) programming.
Example of Area Calculator
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | import java.awt.*; import java.awt.event.*; public class AreaCalculator extends Frame implements ActionListener{ Label l1, l2,l3; TextField t1, t2,t3; Button b, b5; Frame f=new Frame(); AreaCalculator(){ setLayout(new FlowLayout()); l1 = new Label("Enter Length : "); t1 = new TextField(10); l2 = new Label("Enter Breadth : "); t2 = new TextField(10); l3 = new Label("Area : "); t3 = new TextField(10); add(l1); add(t1); add(l2); add(t2); add(l3); add(t3); b = new Button("Calculate"); add(b); b.addActionListener(this); b5 = new Button("Exit"); add(b5); b5.addActionListener(this); setTitle("Area Calculator"); setSize(250,220); setVisible(true); } public void actionPerformed(ActionEvent e){ int length = Integer.parseInt(t1.getText()); int breadth = Integer.parseInt(t2.getText()); int area = length * breadth; t3.setText(String.valueOf(area)); if(e.getSource()==b5) { System.exit(0); } } public static void main(String args[]){ AreaCalculator ac = new AreaCalculator(); } } |
Output
Check out our other Java Programming Examples