本文主要是介绍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);
}
}
}
这篇关于JOptionPane对话框的使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!