日期:2014-05-20 浏览次数:20794 次
package cn.puruidong.Test; import java.awt.*; public class Gui{ private Frame f; private Button b1; private Button b2; public static void main(String args[]){ Gui that = new Gui(); that.go(); } public void go(){ f = new Frame("GUI example"); f.setLayout(new FlowLayout()); //设置布局管理器为FlowLayout b1 = new Button("Press Me"); //按钮上显示字符"Press Me" b2 = new Button("Don't Press Me"); f.add(b1); f.add(b2); f.pack();//紧凑排列,其作用相当于setSize(),即让窗口尽量小,小到刚刚能够包容住b1、b2两个按钮 f.setVisible(true); } }