如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
Swing图形界面设计学习目标AWT回顾Swing特性Swing特性678Swing特性Swing特性Swing特性Swing特性Swing特性Swing特性Swing特性有关Swing的包有关Swing的包javax.swingSwingdemoSwingApplication/*在顶层容器及其内容之间放置空间的常用办法是把内容添加到Jpanel上,而Jpanel本身没有边框的。*/
JPanelpane=newJPanel();
pane.setBorder(BorderFactory.createEmptyBorder(
30,//top
30,//left
10,//bottom
30)//right
);
pane.setLayout(newGridLayout(0,1));//单列多行
pane.add(button);
pane.add(label);
returnpane;
}publicstaticvoidmain(String[]args){
try{
UIManager.setLookAndFeel(
UIManager.getCrossPlatformLookAndFeelClassName());
}catch(Exceptione){}//设置窗口风格
//创建顶层容器并添加内容.
JFrameframe=newJFrame("SwingApplication");
SwingApplicationapp=newSwingApplication();
Componentcontents=app.createComponents();
frame.getContentPane().add(contents,BorderLayout.CENTER);
//窗口设置结束,开始显示frame.addWindowListener(newWindowAdapter(){
//匿名类用于注册监听器
publicvoidwindowClosing(WindowEvente){
System.exit(0);
}
});
frame.pack();
frame.setVisible(true);
}
}
运行结果SwingApplication程序结构SwingApplication2、选择“外观和感觉”
publicstaticvoidmain(String[]args){
try{
UIManager.setLookAndFeel(
UIManager.getCrossPlatformLookAndFeelClassName());
}catch(Exceptione){}
//Createthetop-levelcontainerandaddcontentstoit.
JFrameframe=newJFrame("SwingApplication");
SwingApplicationapp=newSwingApplication();
Componentcontents=app.createComponents();
frame.getContentPane().add(contents,BorderLayout.CENTER);3、设置顶级容器
//Createthetop-levelcontainerandaddcontentstoit.
JFrameframe=newJFrame("SwingApplication");
SwingApplicationapp=newSwingApplication();
Componentcontents=app.createComponents();
frame.getContentPane().add(contents, BorderLayout.CENTER);
……
frame.pack();
frame.setVisible(true);
4、设置按钮和标签
JButtonbutton=newJButton("I'maSwingbutton!");
button.setMnemonic(KeyEvent.VK_I);
button.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
numClicks++;
label.setText(labelPrefix+numClicks);
}
});
label.setLabelFor(button);5、向容器中添加组件
/*Aneasywaytoputspacebetweenatop-levelcontainer
*anditscontentsistoputthecontentsinaJP
yy****24
实名认证
内容提供者
最近下载