如何在java中制作弹出窗口
我目前正在开发一个 java 应用程序.
I am currently developing a java application.
我想显示一个包含文本区域和按钮的新窗口.
I want to show a new Window which contains a text area and a button.
你有什么想法吗?
推荐答案
同样的答案:JOptionpane 有一个例子:)
The same answer : JOptionpane with an example :)
package experiments;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class CreateDialogFromOptionPane {
public static void main(final String[] args) {
final JFrame parent = new JFrame();
JButton button = new JButton();
button.setText("Click me to show dialog!");
parent.add(button);
parent.pack();
parent.setVisible(true);
button.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
String name = JOptionPane.showInputDialog(parent,
"What is your name?", null);
}
});
}
}
<小时>
相关文章