[英]How to display the input on JFrame from jOptionPane?
So I have this code. 所以我有这段代码。
String input;
input = JOptionPane.showInputDialog("Type words:");
How do I display the input in JFrame
if this code is inside my mouseListener
? 如果此代码位于我的
mouseListener
如何在JFrame
显示输入?
I did not use System.out.println()
because it only prints in the console. 我没有使用
System.out.println()
因为它仅在控制台中打印。
String input;
input = JOptionPane.showInputDialog("Type words:");
JOptionPane.showMessageDialog(null, input);
If you really need it to be shown on a new JFrame
, you can create a new JFrame
and add input
to JLabel
; 如果确实需要将其显示在新的
JFrame
,则可以创建一个新的JFrame
并将input
添加到JLabel
;
JFrame frame = new JFrame("The Title");
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setSize(100,100);
frame.getContentPane().add(new JLabel(input));
frame.setLocationRelativeTo(null);
frame.setVisible(true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.