主题:java 新手求助!
我编了个小程序,没有错误,可运行时右面的面板却什么也没有,请教高手。
import java.awt.*;
import javax.swing.*;
public class ERS_demo extends JFrame {
Panel p;
Mypanel mp;
public ERS_demo() {
Container con = getContentPane();
con.setLayout(new GridLayout(1, 2));
p = new Panel();
p.setBackground(Color.BLACK);
con.add(p);
mp = new Mypanel();
mp.b1.setBackground(Color.blue);
con.add(mp);
this.setSize(400, 300);
this.setVisible(true);
}
public static void main(String args[]) {
new ERS_demo();
}
}
class Mypanel extends Panel {
Panel p;
Label l1, l2;
TextField t1, t2;
Button b1, b2, b3, b4, b5;
public Mypanel() {
p = new Panel();
p.setLayout(new GridLayout(9, 1));
l1 = new Label("score");
p.add(l1);
t1 = new TextField("0");
t1.setEditable(false);
p.add(t1);
l2 = new Label("level");
p.add(l2);
t2 = new TextField("1");
t2.setEditable(false);
p.add(t2);
b1 = new Button("begin");
p.add(b1);
b2 = new Button("next level");
p.add(b2);
b3 = new Button("last level");
p.add(b3);
b4 = new Button("paulse");
p.add(b4);
b5 = new Button("quit");
p.add(b5);
}
}
import java.awt.*;
import javax.swing.*;
public class ERS_demo extends JFrame {
Panel p;
Mypanel mp;
public ERS_demo() {
Container con = getContentPane();
con.setLayout(new GridLayout(1, 2));
p = new Panel();
p.setBackground(Color.BLACK);
con.add(p);
mp = new Mypanel();
mp.b1.setBackground(Color.blue);
con.add(mp);
this.setSize(400, 300);
this.setVisible(true);
}
public static void main(String args[]) {
new ERS_demo();
}
}
class Mypanel extends Panel {
Panel p;
Label l1, l2;
TextField t1, t2;
Button b1, b2, b3, b4, b5;
public Mypanel() {
p = new Panel();
p.setLayout(new GridLayout(9, 1));
l1 = new Label("score");
p.add(l1);
t1 = new TextField("0");
t1.setEditable(false);
p.add(t1);
l2 = new Label("level");
p.add(l2);
t2 = new TextField("1");
t2.setEditable(false);
p.add(t2);
b1 = new Button("begin");
p.add(b1);
b2 = new Button("next level");
p.add(b2);
b3 = new Button("last level");
p.add(b3);
b4 = new Button("paulse");
p.add(b4);
b5 = new Button("quit");
p.add(b5);
}
}