当前位置: 技术问答>java相关
怎样弹出一个对话框,我只知道在delphi里用showmessage('hello');,不知在java里怎么写?
来源: 互联网 发布时间:2015-09-07
本文导语: 怎样弹出一个对话框,我只知道在delphi里用showmessage('hello');,不知在java里怎么写? | import java.swing.*; JOptionPane.showMessageDialog(null,"请输入数字.","验证错误",JOptionPane.ERROR_MESSAGE); | ...
怎样弹出一个对话框,我只知道在delphi里用showmessage('hello');,不知在java里怎么写?
|
import java.swing.*;
JOptionPane.showMessageDialog(null,"请输入数字.","验证错误",JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null,"请输入数字.","验证错误",JOptionPane.ERROR_MESSAGE);
|
简单的用JOptionPane,复杂的用JDialog,用法自己看文档
|
看帮助文档
Examples:
Show an error dialog that displays the message, 'alert': JOptionPane.showMessageDialog(null, "alert", "alert", JOptionPane.ERROR_MESSAGE);
Show an internal information dialog with the message, 'information': JOptionPane.showInternalMessageDialog(frame, "information","information", JOptionPane.INFORMATION_MESSAGE);
Show an information panel with the options yes/no and message 'choose one': JOptionPane.showConfirmDialog(null, "choose one", "choose one", JOptionPane.YES_NO_OPTION);
Show an internal information dialog with the options yes/no/cancel and message 'please choose one' and title information: JOptionPane.showInternalConfirmDialog(frame, "please choose one", "information", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);
Show a warning dialog with the options OK, CANCEL, title 'Warning', and message 'Click OK to continue': Object[] options = { "OK", "CANCEL" };JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
Show a dialog asking the user to type in a String: String inputValue = JOptionPane.showInputDialog("Please input a value"); Show a dialog asking the user to select a String: Object[] possibleValues = { "First", "Second", "Third" };Object selectedValue = JOptionPane.showInputDialog(null, "Choose one", "Input", JOptionPane.INFORMATION_MESSAGE, null, possibleValues, possibleValues[0]);
Examples:
Show an error dialog that displays the message, 'alert': JOptionPane.showMessageDialog(null, "alert", "alert", JOptionPane.ERROR_MESSAGE);
Show an internal information dialog with the message, 'information': JOptionPane.showInternalMessageDialog(frame, "information","information", JOptionPane.INFORMATION_MESSAGE);
Show an information panel with the options yes/no and message 'choose one': JOptionPane.showConfirmDialog(null, "choose one", "choose one", JOptionPane.YES_NO_OPTION);
Show an internal information dialog with the options yes/no/cancel and message 'please choose one' and title information: JOptionPane.showInternalConfirmDialog(frame, "please choose one", "information", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);
Show a warning dialog with the options OK, CANCEL, title 'Warning', and message 'Click OK to continue': Object[] options = { "OK", "CANCEL" };JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
Show a dialog asking the user to type in a String: String inputValue = JOptionPane.showInputDialog("Please input a value"); Show a dialog asking the user to select a String: Object[] possibleValues = { "First", "Second", "Third" };Object selectedValue = JOptionPane.showInputDialog(null, "Choose one", "Input", JOptionPane.INFORMATION_MESSAGE, null, possibleValues, possibleValues[0]);
|
JOptionPane.showMessageDialog(null,"hello","title",JOptionPane.DEFAULT_OPTION,null);
|
JOptionPane.showConfirmDialog(this,"hello");
JOptionPane.showInputDialog(this,"hello");
JOptionPane.showMessageDialog(this,"hello");
JOptionPane.showInputDialog(this,"hello");
JOptionPane.showMessageDialog(this,"hello");
|
import javax.swing.*;
JOptionPane.showMessageDialog(null,“”);双引号中为要显示的字符。
null为对话框标题
JOptionPane.showMessageDialog(null,“”);双引号中为要显示的字符。
null为对话框标题
|
使用JOPtionPane是很方便的,但如果你的Dialog比较特殊,或者有更多的信息,可以继承JDialog自己做一个个性的Dialog。