日期:2014-05-20 浏览次数:20621 次
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class LanDian {
public static void main(String args[]) {
new LDFrame(800,500);
}
}
class LDFrame extends Frame {
public Tuxin tx = null;
private Panel p1=null,p2=null,p3=null;
TextArea ta = new TextArea("alajlfj",180,100);
Button b1,b2,b3,b4,b5;
LDFrame(int w,int h) {
super("123");
b1 = new Button("a");
b1.setBounds(7,0,70,h/5);
b2 = new Button("b");
b2.setBounds(7,h/5,70,h/5);
b3 = new Button("c");
b3.setBounds(7,2*(h/5),70,h/5);
b4 = new Button("d");
b4.setBounds(7,3*(h/5),70,h/5);
b5 = new Button("e");
b5.setBounds(7,4*(h/5),70,h/5);
Monitor1 m1 = new Monitor1();
Monitor2 m2 = new Monitor2();
Monitor3 m3 = new Monitor3();
Monitor4 m4 = new Monitor4();
Monitor5 m5 = new Monitor5();
b1.addActionListener(m1);
b2.addActionListener(m2);
b3.addActionListener(m3);
b4.addActionListener(m4);
b5.addActionListener(m5);
setLayout(new BorderLayout(15,0));
setBounds(0,0,w,h);
p1 = new Panel(null);
p1.setSize(w/9,h);
p2 = new Panel(null);
p3 = new Panel(null);
p2.setBackground(Color.RED);
p2.setSize(100,h);
p2.setLayout(new BorderLayout());
p2.add(ta);
p3.setBackground(Color.blue);
p3.setSize(320,h);
p1.setBackground(Color.green);
add(p1,BorderLayout.WEST);add(p2,BorderLayout.CENTER);add(p3,BorderLayout.EAST);
p1.add(b1);p1.add(b2);p1.add(b3);p1.add(b4);p1.add(b5);
setVisible(true);
addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
);
}
public void paint(Graphics g) {
if(tx != null) tx.draw(g); //这里,没等下面的注释执行就先执行
} // 这样就达不到我预想的效果。。