您的位置:首页 > 其它

SWING 学习笔记(1)

2007-05-01 00:01 344 查看
1.JTextArea:
setBorder(Border border )//设置边框
setLineWrap(boolean)//是否自动换行
setLineWrap(true) ;
setEditable(boolean) ;//是否可编辑
setFont(Font font) ;//设置字体
2.JScrollPane:
setViewportView(Component view )//将一个组件加入到JScrollPane中
setBorder (Border border)
setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
3.快捷键设定
为按钮设置快捷键:
accountsButton.setMnemonic('A');
将登录按钮设置成缺省操作:
frame.getRootPane().setDefaultButton(loginButton);
将焦点设在密码框:
swordField.requestFocusInWindow() ;
4.播放声音(只能是au文件)
public void playSound() {
try {
InputStream in =主类.class.getResourceAsStream("Res/msg.au");
AudioStream as = new AudioStream(in);
AudioPlayer.player.start(as);
try {
Thread.sleep(600);
}catch(InterruptedException e){
}

AudioPlayer.player.stop(as);
}catch (IOException ex) {
System.out.println(ex.getMessage()) ;
}
}
5. JOptionPane 实现标准对话框
1. 显示MessageDialog JOptionPane.showMessageDialog(null, "在对话框内显示的描述性的文字", "标题条文字串", JOptionPane.ERROR_MESSAGE);
2. 显示ConfirmDialog JOptionPane.showConfirmDialog(null, "choose one", "choose one", JOptionPane.YES_NO_OPTION);
3. 显示InputDialog 以便让用户进行输入 String inputValue = JOptionPane.showInputDialog("Please input a value");
6.Jar打包
MANIFEST.MF文件
Manifest-Version: 1.0
Created-By: 1.5.0 (Sun Microsystems Inc.)
Main-Class: 你的主类(冒号后留一个空格)
java运行class文件并不区别大小写,而打包后就严格的区分大小写了
对于资源文件,加载时用
URL = 主类.class.getResource(“Res/*.png”) ;
InputStream = 主类.class. getResourceAsStream("Res/msg.au");

注意:
是“/”,与平台无关

7. 使用当前系统外观
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception e) {
e.printStackTrace();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: