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);
blyd.BorderLayoutDemo();
blyd.pack();
blyd.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
public Dimension getPerferredSzie(){
return new Dimension(400,200);
}
}
构建一个容器 把图像放在容器里 然后再构造一个BorderLayout实例
把你先前构造的容器添加布局就好了
?
把图像加到JPanel里