You are on page 1of 2

import java.awt.*; this.

add(main);

import java.awt.event.*; this.pack();

import javax.swing.*; this.setVisible(true);

public class Addition extends JFrame }


implements ActionListener
public void addComponents(){
{
JPanel P1 = new JPanel();
JPanel main;
P1.setLayout(new
JLabel L1,L2,L3, L4; BorderLayout());

JButton B1; L1 = new JLabel("First


Number");
JTextField TF1, TF2, TF3;
TF1 = new
public static void main (String[] args) {
JTextField("");
new Addition();
L2 = new JLabel("+");
}

public Addition(){

super("Addition");
P1.add(L1,
createGUI(); BorderLayout.WEST);

addListener(); P1.add(TF1,
BorderLayout.CENTER);
}
P1.add(L2,
public void createGUI(){ BorderLayout.SOUTH);
main = new JPanel();

addComponents();

this.setSize(new JPanel P2 = new JPanel();


Dimension(400,200));
P2.setLayout(new
this.addWindowListener(new BorderLayout());
WindowAdapter(){
L3 = new
public void JLabel("Second Number");
windowClosing(WindowEvent we){
TF2 = new
System.exit(0); JTextField("");
}

});
P2.add(L3, main.add(P4);
BorderLayout.WEST);
//main.add(P5);
P2.add(TF2,
BorderLayout.CENTER);
}

public void addListener(){


JPanel P3 = new JPanel();
B1.addActionListener(this);
P3.setLayout(new
BorderLayout()); TF1.addActionListener(this);
L4 = new JLabel("="); TF2.addActionListener(this);

//TF3.addActionListener(this);
P3.add(L4,
BorderLayout.WEST);

}
JPanel P4 = new JPanel();

P4.setLayout(new
BorderLayout());

B1 = new
JButton("Sum");

TF3 = new
JTextField("");

P4.add(B1,
BorderLayout.WEST);

P4.add(TF3,
BorderLayout.CENTER);

main.setLayout(new GridLayout(4,1));

main.add(P1);

main.add(P2);

main.add(P3);

You might also like