⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 showmessagedialog.java

📁 Java与面向对象程序设计实验教学讲义.复数类的实现,复数类的复杂运算,身份证号码的分析,图形界面设计
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -