samplepopup.java
来自「这个是Java的swing相关的典型的源码」· Java 代码 · 共 45 行
JAVA
45 行
/*
Definitive Guide to Swing for Java 2, Second Edition
By John Zukowski
ISBN: 1-893115-78-X
Publisher: APress
*/
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class SamplePopup {
public static void main(String args[]) {
JFrame frame = new JFrame("Sample Popup");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton button = new JButton("Ask");
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
Component source = (Component) actionEvent.getSource();
Object response = JOptionPane.showInputDialog(source,
"Where would you like to go to lunch?",
"Select a Destination", JOptionPane.QUESTION_MESSAGE,
null, new String[] { "Burger King", "McDonalds",
"Pizza Hut", "Taco Bell", "Wendy's" },
"McDonalds");
System.out.println("Response: " + response);
}
};
button.addActionListener(actionListener);
Container contentPane = frame.getContentPane();
contentPane.add(button, BorderLayout.SOUTH);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?