下面的java代码怎么不会显示图形界面?哪里出错了?
importjava.awt.*;importjava.applet.Applet;publicclassmyPanelextendsPanel{publicvoidin...
import java.awt.*;
import java.applet.Applet;
public class myPanel extends Panel{
public void init(){
setLayout(new BorderLayout());
setForeground(Color.red);
add("North",new Label("this is a label",Label.CENTER));
Panel p1 = new Panel();
p1.setBackground(Color.blue);
p1.setForeground(Color.green);
p1.setLayout(new BorderLayout());
p1.add("West", new Button("West"));
p1.add("Center", new Button("Center"));
p1.add("East", new Button("East"));
Panel p2 = new Panel();
p2.setBackground(Color.black);
p1.setLayout(new BorderLayout());
p2.add("North",new Button("North"));
p2.add("South",new Button("South"));
add("West",p1);
add("East",p2);
}
public static void main(String args[]){
myPanel p = new myPanel();
p.init();
}
} 展开
import java.applet.Applet;
public class myPanel extends Panel{
public void init(){
setLayout(new BorderLayout());
setForeground(Color.red);
add("North",new Label("this is a label",Label.CENTER));
Panel p1 = new Panel();
p1.setBackground(Color.blue);
p1.setForeground(Color.green);
p1.setLayout(new BorderLayout());
p1.add("West", new Button("West"));
p1.add("Center", new Button("Center"));
p1.add("East", new Button("East"));
Panel p2 = new Panel();
p2.setBackground(Color.black);
p1.setLayout(new BorderLayout());
p2.add("North",new Button("North"));
p2.add("South",new Button("South"));
add("West",p1);
add("East",p2);
}
public static void main(String args[]){
myPanel p = new myPanel();
p.init();
}
} 展开
1个回答
展开全部
在main方法这么写行吗~
public static void main(String args[]){
TestPaint p = new TestPaint();
p.init();
JFrame frame=new JFrame("00");
frame.add(p);
frame.setSize(600,500);
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public static void main(String args[]){
TestPaint p = new TestPaint();
p.init();
JFrame frame=new JFrame("00");
frame.add(p);
frame.setSize(600,500);
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询