JOptionPane对话框的使用
原创
©著作权归作者所有:来自51CTO博客作者laijimin1217的原创作品,请联系作者获取转载授权,否则将追究法律责任
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);
}
}
}