joptiondemo.java
来自「这个是Java的swing相关的典型的源码」· Java 代码 · 共 52 行
JAVA
52 行
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 + =
减小字号Ctrl + -
显示快捷键?