Forum :: Java :: รันโปรแกรมไม่ผ่าน Swing GUI

-
ณัฐญา กิติพิพัฒน์
- Badge 0 Following 0 Follower 0 Reference 1 Forum 0 Application 0 Book 0 Comment
- About Me
- เมื่อ 13 กุมภาพันธ์ 2019 เวลา 1 นาฬิกา 24 นาที
- 293 Read
- 0 Comment
- 0 Like
- 0 Follower
ผิดตรงไหนคะ หาไม่เจอ โปรแกรมรันไม่ผ่าน import javax.swing.*; public class JavaApplication3 { JFrame f; JPanel p; JTextField t,t1; JButton b; JLabel l,l1,l2,l3; JavaApplication3(){ l = new JLabel("Adition of two numbers",JLabel.CENTER); l1 = new JLabel("First number",JLabel.CENTER); l2 = new JLabel("Second number",JLabel.CENTER); p = new JPanel(); t = new JTextField(5); t1 = new JTextField(5); b = new JButton("Add"); } public void showFrame(){ p.setLayout(new GridLayout(2,2)); p.add(l1); p.add(t); p.add(l2); p.add(t1); Container c = f.getContentPane(); c.add(l,BorderLayout.NORTH); c.add(b,BorderLayout.SOUTH); c.add(p,BorderLayout.CENTER); f.setSize(150,150); f.setVisible(true); b.addActionListener(new Handler()); } class Handler implements ActionListener{ public void actionPerformed(ActionEvent e){ int a = Integer.parseInt(t.getText()); int z = Integer.parseInt(t1.getText()); int y =a+z; l3.setText("Sum is "+ y); } } public static void main(String[] args) { JavaApplication3 n = new JavaApplication3(); n.showFrame(); } }
0 Comment
- Have no comment.