java中borderlayout布局显示
来源:百度知道 编辑:UC知道 时间:2024/09/12 19:20:14
import java.awt.event.*;
public class BorderLayoutDemo extends Frame{
public void BorderLayoutDemo(){
this.add(new Button("1"),BorderLayout.EAST);
this.add(new Button("2"),BorderLayout.CENTER);
this.add(new Button("3"),BorderLayout.NORTH);
this.add(new Button("4"),BorderLayout.WEST);
add(new Label("this is a borderlayout"),BorderLayout.SOUTH);
}
public static void main(String args[]){
BorderLayoutDemo blyd=new BorderLayoutDemo();
blyd.setTitle("this is a borderlayout");
blyd.setVisible(true);
blyd.pack();
blyd.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
public Dimension getPerferredSzie(){
return new Dimension(400,200);
}
}
为什么运行的时候,框架里什么也
就差了一句话!呵呵……修改后如下:
import java.awt.*;
import java.awt.event.*;
public class BorderLayoutDemo extends Frame{
public void BorderLayoutDemo(){
this.add(new Button("1"),BorderLayout.EAST);
this.add(new Button("2"),BorderLayout.CENTER);
this.add(new Button("3"),BorderLayout.NORTH);
this.add(new Button("4"),BorderLayout.WEST);
add(new Label("this is a borderlayout"),BorderLayout.SOUTH);
}
public static void main(String args[]){
BorderLayoutDemo blyd=new BorderLayoutDemo();
blyd.setTitle("this is a borderlayout");
blyd.setVisible(true);
///就多加这么一句就OK啦~~!呵呵……你忘记执行那个添加控件的方法了!
blyd.BorderLayoutDemo();
blyd.pack();
blyd.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
public Dimension getP