import java.awt.GridLayout;
import java.awt.event.*;
import javax.swing.*;
public class SWINGDemo extends JFrame {
JLabel jl;
JButton jb;
JTextField jtf1, jtf2, jtf3;
public SWINGDemo() {
jl = new JLabel("+");
jb = new JButton("=");
jtf1 = new JTextField(5);
jtf1.setText("1");
jtf2 = new JTextField(5);
jtf2.setText("2");
jtf3 = new JTextField(5);
JPanel jp = new JPanel(new GridLayout(1, 5));
jp.add(jtf1);
jp.add(jl);
jp.add(jtf2);
jp.add(jb);
jp.add(jtf3);
add(jp);
setTitle("çªå£æ é¢");
setBounds(300, 200, 300, 80);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
jb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int a = Integer.parseInt(jtf1.getText());
int b = Integer.parseInt(jtf2.getText());
jtf3.setText(a+b+"");
}
});
}
public static void main(String[] args) {
new SWINGDemo();
}
}