📄 joptionpaneexample1.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JOptionPaneExample1 extends JFrame implements ActionListener {
static JButton b1,b2,b3,b4;
public JOptionPaneExample1()
{
super("hello,JOptionPane Dialog");
// setSize(200,200);
setVisible(true);
b1=new JButton("message_dialog");
b2=new JButton("confirm_dialog");
b3=new JButton("input_dialog");
b4=new JButton("unKnown");
Container container=getContentPane();
container.setLayout(new GridLayout(5,0));
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
container.add(b1);
container.add(b2);
container.add(b3);
container.add(b4);
pack();
container.setBackground(Color.blue);
}
public static void main(String [] args)
{
setDefaultLookAndFeelDecorated(true);
JOptionPaneExample1 jpe= new JOptionPaneExample1();
jpe.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b1)
JOptionPane.showMessageDialog(this,"hello,message_dialog");
else if(ae.getSource()==b2)
JOptionPane.showConfirmDialog(this, "hello, confirm dialog");
else if(ae.getSource()==b3)
JOptionPane.showInputDialog(this,"hello,input dialog");
else
JOptionPane.showMessageDialog(this, "hello", "world", JOptionPane.PLAIN_MESSAGE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -