菜鸟在学GUI 请问我的程序哪里错了
Its an exercise from thinking java.
pls tell me whats wrong with the code as follow.
If someone could help me fix it, i will be really appreciated it.
thx.
import javax.swing.*;import java.awt.*;import static net.mindview.util.SwingConsole.*;public class Button1 extends JFrame{ /** * @param args */ private JButton b1 = new JButton("Button 1"), b2 = new JButton("Button 2"); public Button1(){ setLayout(new FlowLayout()); add(b1); add(b2); } public static void main(String[] args) { // TODO Auto-generated method stub run(new Button1(),400,600); }}import javax.swing.*;import java.awt.*;import java.awt.event.*;import net.mindview.util.SwingConsole;public class ex05 extends JFrame { /** * @param args */ private JButton b1 = new JButton("Button 1"), b2 = new JButton("Button 2"), b3 = new JButton("Button 3"); private JTextField txt = new JTextField(10); private ActionListener bl = new ActionListener(){ public void actionPerformed(ActionEvent e){ String name = ((JButton)e.getSource()).getText(); txt.setText(name); } }; public ex05(){ b1.addActionListener(bl); b2.addActionListener(bl); b3.addActionListener(bl); setLayout(new FlowLayout()); add(b1); add(b2); add(b3); } public static void main(String[] args) { // TODO Auto-generated method stub run(new ex05(), 400, 200); }}JFrame jf=new ex05();run(jf,400, 200);