import java.awt.*;
public class TestFrame { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new MyFrame ();说是这里有错
} private class MyFrame extends Frame {
MyFrame(){
没有引用父类的构造方法,有问题没
setSize(10,10)
setLocation(20,20);
setBackground(Color.RED);
for (int i = 0;i<=3;i++){
add(new Button("button"+i));
}
}
}}
public class TestFrame { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new MyFrame ();说是这里有错
} private class MyFrame extends Frame {
MyFrame(){
没有引用父类的构造方法,有问题没
setSize(10,10)
setLocation(20,20);
setBackground(Color.RED);
for (int i = 0;i<=3;i++){
add(new Button("button"+i));
}
}
}}
import java.awt.*;
public class TestFrame { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new TestFrame().new MyFrame();
}
private class MyFrame extends Frame {
MyFrame(){
setSize(10,10);
setLocation(20,20);
setBackground(Color.RED);
for (int i = 0;i <=3;i++){
add(new Button("button"+i));
}
}
} }
[/code]
// TODO Auto-generated method stub
new MyFrame(); // 调用的类一般是要放在外部的
}
}class MyFrame extends Frame {
MyFrame() {
setSize(100, 100);
setLocation(20, 20);
setBackground(Color.RED);
for (int i = 0; i <= 3; i++) {
add(new Button("button" + i));
}
addWindowListener(new WindowAdapter() { //注册关闭窗口事件
public void windowClosing(WindowEvent e) {
System.exit(-1);
}
});
this.setVisible(true); //少了这一句,你是看不到运行生成的窗口的
}
}
public static void main(String[] args) { new TestFrame().new MyFrame();
}
或者像5楼那样做做GUi的时候最后一定要设置窗体为可见this.setVisible(true);