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);
}}/* output Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
The method run(ex05, int, int) is undefined for the type ex05 at ex05.main(ex05.java:31)[that is {run(new ex05(), 400, 200);}]
thx guys!

解决方案 »

  1.   

    //: net/mindview/util/SwingConsole.java
    //Tool for running Swing demos from the
    //console, both applets and JFrames.
    package net.mindview.util;
    import javax.swing.*;public class SwingConsole {
    public static void
    run(final JFrame f, final int width, final int height) {
     SwingUtilities.invokeLater(new Runnable() {
       public void run() {
         f.setTitle(f.getClass().getSimpleName());
         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         f.setSize(width, height);
         f.setVisible(true);
       }
     });
    }
    } ///:~
      

  2.   

    The first section code is wrong. pls see the first floor. many thx.
      

  3.   

    很简单啊,你声明run方法的时候写的形式参数第一个是JFrame类,但是传参的时候实际参数是ex05类的,虽然它是JFrame的子类,但是肯定类型不匹配,你可以这样
    JFrame jf=new ex05();
    run(jf,400, 200);
      

  4.   


    i have tried, but it still does not work.....i dont think this is a type matching problem because the code section1  public class Button1 extends JFrame{}is able to be compiled.help me guy!
      

  5.   

    哦,抱歉,前面3楼说错了,是可以把子类的对象当参数传给需要父类对象当参数的方法的
    你的错误是由于没有在ex05中定义run方法,或许你的意思是想使用SwingConsole中的run方法,那么应该把那句话改成这样
    SwingConsole.run(new ex05(),400,200);
    另外,Button1不知道你那为什么能编译通过,我这里也是报undefined错误,原因跟ex05一样
    PS:既然继承的是JFrame,最好不要起名叫Button,程序规模大了之后很容易混淆
      

  6.   


    Hey dude.i know the reason, that is i should quote the package net.mindview.xxxxx.xxx by static. haha, anyway thx for ur help!