如何在java中制作弹出窗口
- 作者: 咯没流量了
- 来源: 51数据库
- 2023-01-29
问题描述
我目前正在开发一个 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.**utton; import javax.swing.JFrame; import javax.swing.JOptionPane; public class CreateDialogFromOptionPane { public static void main(final String[] args) { final JFrame parent = new JFrame(); **utton button = new **utton(); 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); } }); } }
<小时>
推荐阅读