JOptionPane.showMessageDialog(null,"消息框内容","消息框标题",JOptionPane.OK_CANCEL_OPTION);

解决方案 »

  1.   


    import java.awt.event.*;
    import javax.swing.*;class ShowDemo extends JFrame implements ActionListener
    {
     JButton buttonMessage,buttonFrame;
     JFrame frame;
     JPanel pane;
     
     ShowDemo()
     {
      super("Frame show");
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
      buttonMessage=new JButton("´ò¿ªÏûÏ¢¿ò");
      buttonMessage.addActionListener(this);
      
      buttonFrame=new JButton("´ò¿ªForm2");
      buttonFrame.addActionListener(this);
      pane=new JPanel();
      pane.add(buttonMessage);
      pane.add(buttonFrame);
      getContentPane().add(pane);
      setSize(300,300);
      show();
      
      frame=new JFrame("Form2");
      frame.setSize(200,200);
      frame.setVisible(false);
     }
     
     public static void main(String[] arguments)
     {
      ShowDemo sd=new ShowDemo();
     }  
     
     public void actionPerformed(ActionEvent evt)
     {
      if(evt.getSource()==buttonFrame)
      {
       frame.setVisible(true); 
      }
      else
      {
       JOptionPane.showMessageDialog(null,"我是消息框!");
      }  
     }
    }
      

  2.   

    不好意思我的中文显示有问题,重贴:
    import java.awt.event.*;
    import javax.swing.*;class ShowDemo extends JFrame implements ActionListener
    {
     JButton buttonMessage,buttonFrame;
     JFrame frame;
     JPanel pane;
     
     ShowDemo()
     {
      super("Frame show");
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
      buttonMessage=new JButton("打开消息框");
      buttonMessage.addActionListener(this);
      
      buttonFrame=new JButton("打开Form2");
      buttonFrame.addActionListener(this);
      pane=new JPanel();
      pane.add(buttonMessage);
      pane.add(buttonFrame);
      getContentPane().add(pane);
      setSize(300,300);
      show();
      
      frame=new JFrame("Form2");
      frame.setSize(200,200);
      frame.setVisible(false);
     }
     
     public static void main(String[] arguments)
     {
      ShowDemo sd=new ShowDemo();
     }  
     
     public void actionPerformed(ActionEvent evt)
     {
      if(evt.getSource()==buttonFrame)
      {
       frame.setVisible(true); 
      }
      else
      {
       JOptionPane.showMessageDialog(null,"我是消息框!");
      }  
     }
    }
      

  3.   

    哈。javax.swing.JOptionPane就这个类