showmessagedialog.java
来自「Java与面向对象程序设计实验教学讲义.复数类的实现,复数类的复杂运算,身份证号」· Java 代码 · 共 75 行
JAVA
75 行
import javax.swing.*;
import java.awt.event.*;
public class ShowMessageDialog extends JFrame implements ActionListener{
int count=1;
public ShowMessageDialog(String s){
super( s );
}
public static void main(String[] args){
ShowMessageDialog frame = new ShowMessageDialog("Dialog test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton jb = new JButton("Show the next dialog");
jb.addActionListener( frame);
frame.getContentPane().add(jb);
frame.pack();
frame.setVisible(true);
}
public void actionPerformed( ActionEvent e){
switch(count++%6){
case 1:
// 带有“信息”(information)图标、标题为“消息”的对话框。
JOptionPane.showMessageDialog(this,
"Eggs aren't supposed to be green.");
break ;
case 2 :
// 带有“警告”图标的消息对话框。
JOptionPane.showMessageDialog(this,
"Eggs aren't supposed to be green.",
"Warning",
JOptionPane.WARNING_MESSAGE);
break;
case 3 :
// 带有“错误”图标的消息对话框。
JOptionPane.showMessageDialog(this,
"Eggs aren't supposed to be green.",
"Error",
JOptionPane.ERROR_MESSAGE);
break ;
case 4 :
// 带有“提问”图标的消息对话框。
JOptionPane.showMessageDialog(this,
"Eggs aren't supposed to be green.",
"Question",
JOptionPane.QUESTION_MESSAGE);
break;
case 5 :
//不带图标的对话框。
JOptionPane.showMessageDialog(this,
"Eggs aren't supposed to be green.",
"A plain message",
JOptionPane.PLAIN_MESSAGE);
break;
case 0:
//自定义图标的对话框。
JOptionPane.showMessageDialog(this,
"Eggs aren't supposed to be green.",
"Custom dialog",
JOptionPane.INFORMATION_MESSAGE,
new ImageIcon("dukesign.gif"));
break ;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?