预览加载中,请您耐心等待几秒...
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10

亲,该文档总共12页,到这已经超出免费预览范围,如果喜欢就直接下载吧~

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

??????????? ?????www.365xueyuan.com ????????????? 本文由bing050802贡献 doc1。 JAVASE应用程序设计第12章GUI程序设计源代码 12-1第一个GUI应用程序源文件TestFrame.javaimportjava.awt.Frame; publicclassTextFrame{publicstaticvoidmain(String[]args){Framef =newFrame("Hello,GUI");f.setSize(200,100);f.setVisible(true);}}12-2 将组件添加到容器源文件TestFrameWithPanel.javaimportjava.awt.Frame;imp ortjava.awt.Panel;importjava.awt.Color;publicclassTestFramePanel{p ublicstaticvoidmain(String[]args){Framef=newFrame("MyTest");Pane lpan=newPanel();f.setSize(200,170);f.setBackground(Color.cyan);f.setL ayout(null);pan.setSize(80,80);pan.setBackground(Color.green);pan.setLo cation(40,40);f.setLocation(300,300);f.setVisible(true);}}12-3使用L ayout布局管理器源文件TestFlowLayout.javaimportjava.awt.Frame;import java.awt.Button;importjava.awt.FlowLayout;publicclassTestFlowLayout{ 预览1 预览2 publicstaticvoidmain(String[]args){Framef=newFrame("FlowLayou t");Buttonbutton1=newButton("Ok");Buttonbutton2=newButton("Open");B uttonButton3=newButton("Close");f.setLayout(newFlowLayout());f.add(bu tton1);f.add(button2);f.add(Button3);f.setSize(100,100);f.setVisible(t rue);}} 预览312-4使用BorderLayout布局管理器源文件TestBorderLayout.java importjava.awt.Frame;importjava.awt.Button;publicclassTestBorderLay out{publicstaticvoidmain(String[]args){Framef=newFrame("BorderLa yout");Buttonbn=newButton("BN");Buttonbs=newButton("BS");Buttonbw= newButton("BW");Buttonbe=newButton("BE");Buttonbc=newButton("BC"); f.add(bn,"North");f.add(bs,"South");f.add(bw,"West");f.add(be,"East"); f.add(bc,"Center");f.setSize(200,200); f.setVisible(true);}} 预览4使用GridLayout布局管理器源文件TestGridLayout.javaimportj ava.awt.Frame;importjava.awt.Button;importjava.awt.GridLayout;public classTestGridLayout{publicstaticvoidmain(String[]args){Framef=ne wFrame("GridLayout");Buttonb1=newButton("b1");Buttonb2=newButton("b 2");Buttonb3=newButton("b3");Buttonb4=newButton("b4");Buttonb5=new Button("b5");Buttonb6=newButton("b6");f.setLayout(newGridLayout(3,2) );f.add(b1);f.add(b2);f.add(b3);f.add(b4);f.add(b5);f.add(b6)