熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

java swing標准對話框具體實現

2022-06-13   來源: JSP教程 
這篇文章介紹了swing標准對話框的具體實現方法有需要的朋友可以參考一下   復制代碼 代碼如下:

  
package test;
import javaawteventActionEvent;
import javaawteventActionListener;
import javaxswingJButton;
import javaxswingJFrame;
import javaxswingJOptionPane;
import javaxswingJToolBar;
public class TestJOptionPane implements ActionListener{
private JFrame jf = new JFrame("標准對話框測試");
/**
* @param args
*/
public static void main(String[] args) {
// TODO Autogenerated method stub
new TestJOptionPane()createUI();
}
public void createUI(){
JToolBar jtb = new JToolBar();
String[] s = {"錯誤" "退出確認" "退出確認" "警告" "輸入" "選擇"};
int size = slength;
JButton[] button = new JButton[size];
for(int i = ; i < size; i++){
button[i] = new JButton(s[i]);
button[i]addActionListener(this);
jtbadd(button[i]);
}
jfadd(jtb "North");
jfsetSize( );
jfsetLocation( );
jfsetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
jfsetVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Autogenerated method stub
String s = egetActionCommand();
if(sequals("錯誤")){
JOptionPaneshowMessageDialog(null "要顯示的錯誤信息"
"錯誤提示"JOptionPaneERROR_MESSAGE);
}
else if(sequals("退出確認")){
int result = JOptionPaneshowConfirmDialog(null
"推出前是否保存程序?");
if(result == JOptionPaneYES_OPTION){
Systemoutprintln("保存程序");
Systemexit();
}
else if(result == JOptionPaneNO_OPTION){
Systemexit();
}
}
else if(sequals("退出確認")){
int result = JOptionPaneshowConfirmDialog(null "退出前是否保存程序?");
if(result == JOptionPaneYES_OPTION){
Systemoutprintln("保存程序");
Systemexit();
}
else if(result == JOptionPaneNO_OPTION){
Systemexit();
}
}
else if(sequals("警告")){
Object[] options = {"繼續" "撤銷"};
int result = JOptionPaneshowOptionDialog(null
"本操作可能導致數據丟失""Warning" JOptionPaneDEFAULT_OPTION
JOptionPaneWARNING_MESSAGE null options options[]);
if(result == ){
Systemoutprintln("繼續操作");
}
}
else if(sequals("輸入")){
String name = JOptionPaneshowInputDialog("請輸入您的姓名");
if(name != null){
Systemoutprintln("姓名" + name);
}
}
else if(sequals("選擇")){
Object[] possibleValues = {"體育" "政治" "經濟" "文化"};
Object selectedValue = JOptionPaneshowInputDialog(null
"Choose one""Input" JOptionPaneINFORMATION_MESSAGE null
possibleValues possibleValues[]);
String choose = (String)selectedValue;
if(choose != null){
Systemoutprintln("你選擇的是"+ choose);
}
}
}
}


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20143.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.