JOptionPane对话框的使用

JOptionPane对话框的使用

import java.awt.event.*;
import javax.swing.*;
class MyFrame extends JFrame
{
 JButton b1;
 public static void main(String args[])
 {
  MyFrame f = new MyFrame();
 }
 public MyFrame()
 {
  /* super() method is used to invoke the     base class constructor */
  super("Window Title");
  b1=new JButton("Click Here");
  getContentPane().add("Center",b1);
  //Register the listener for the button
  ButtonListener blisten= new  ButtonListener();
  b1.addActionListener(blisten);
  setSize(200,200);
  setVisible(true);  
 }
 //The Listener class
 class ButtonListener implements ActionListener
 {
  public void actionPerformed(ActionEvent evt)
  {
   JButton source = (JButton)evt.getSource();
   source.setText("Button clicked");
   JOptionPane.showMessageDialog(MyFrame.this,"Button

clicked","information",JOptionPane.INFORMATION_MESSAGE);
  }
 }
}

阅读更多

没有更多推荐了,返回首页