import java.awt.*;public class TestMultiPanel{
public static void main(String[] args){
MyFrame f = new MyFrame("test",300,300,400,300);
}
}public class MyFrame extends Frame{
MyFrame (String s,int x,int y,int w,int h){
setTitle(s);
setLayout(null);
Panel p1 = new Panel(null);
Panel p2 = new Panel(null);
Panel p3 = new Panel(null);
Panel p4 = new Panel(null);
p1.setBounds(0,0,w/2,h/2);
p2.setBounds(0,w/2,w/2,h/2);
p3.setBounds(w/2,0,w/2,h/2);
p4.setBounds(w/2,h/2,w/2,h/2);
p1.setBackground(Color.blue);
p2.setBackground(Color.green);
p3.setBackground(Color.yellow);
p4.setBackground(Color.red);
add(p1);
add(p2);
add(p3);
add(p4);
setBounds(x,y,w,h);
setVisible(true);
}
},编译的时候报错“类MyFrame是公共的,应在名为MyFrame.java的文件中声明”
public static void main(String[] args){
MyFrame f = new MyFrame("test",300,300,400,300);
}
}public class MyFrame extends Frame{
MyFrame (String s,int x,int y,int w,int h){
setTitle(s);
setLayout(null);
Panel p1 = new Panel(null);
Panel p2 = new Panel(null);
Panel p3 = new Panel(null);
Panel p4 = new Panel(null);
p1.setBounds(0,0,w/2,h/2);
p2.setBounds(0,w/2,w/2,h/2);
p3.setBounds(w/2,0,w/2,h/2);
p4.setBounds(w/2,h/2,w/2,h/2);
p1.setBackground(Color.blue);
p2.setBackground(Color.green);
p3.setBackground(Color.yellow);
p4.setBackground(Color.red);
add(p1);
add(p2);
add(p3);
add(p4);
setBounds(x,y,w,h);
setVisible(true);
}
},编译的时候报错“类MyFrame是公共的,应在名为MyFrame.java的文件中声明”
public class MyFrame extends Frame{
改成:
class MyFrame extends Frame{选择2:
把MyFrame放到另外一个文件MyFrame.java中。
你把第二类的public去掉吧。
把MyFrame放到另外一个文件MyFrame.java中