日期:2014-05-20 浏览次数:20853 次
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import javax.swing.*;
public class tests extends JFrame {
public void showBorderayout(){
Container mycontainer=getContentPane();
BorderLayout layout =new BorderLayout();
mycontainer.setLayout(layout);
JPanel p1=new JPanel();
JPanel p2=new JPanel();
p1.setLayout(new GridLayout(4,3));
p2.setLayout(layout);
for (int i=1;i<10;i++)
p1.add(new JButton (""+i));
p1.add(new JButton (""+0));
p1.add(new JButton ("start"));
p1.add(new JButton ("stop"));
p2.add(p1,BorderLayout.CENTER);
p2.add(new JTextField("Time to be displayed"), BorderLayout.NORTH);
mycontainer.add(p2,BorderLayout.EAST);
mycontainer.add(new JButton("Food to be placed here"),BorderLayout.CENTER);
}
/* mycontainer.add(new JButton("CENTRAL"),BorderLayout.CENTER);
mycontainer.add(new JButton("WEST"),BorderLayout.WEST);
mycontainer.add(new JButton("EAST"),BorderLayout.EAST);
mycontainer.add(new JButton("NORTH"),BorderLayout.NORTH);
mycontainer.add(new JButton("SOUTH"),BorderLayout.SOUTH);
}
*/
public static void main(String[] args){
tests mytest=new tests();
mytest.showBorderayout();
mytest.setSize(400,250);
mytest.setVisible(true);
mytest.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mytest.setLocation(200,200);
}
}