📄 joptiondemo.java
字号:
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
/**
* Demonstrate JOptionPane
*
* @author Ian Darwin
*/
public class JOptionDemo extends JFrame {
// Constructor
JOptionDemo(String s) {
super(s);
Container cp = getContentPane();
cp.setLayout(new FlowLayout());
JButton b = new JButton("Give me a message");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(JOptionDemo.this,
"This is your message: etaoin shrdlu", "Coded Message",
JOptionPane.INFORMATION_MESSAGE);
}
});
cp.add(b);
b = new JButton("Goodbye!");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
cp.add(b);
// size the main window
pack();
}
public static void main(String[] arg) {
JOptionDemo x = new JOptionDemo("Testing 1 2 3...");
x.setVisible(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -