所以我有这个代码。如何从jOptionPane显示JFrame上的输入?
String input;
input = JOptionPane.showInputDialog("Type words:");
如何显示在JFrame
输入如果这个代码是我mouseListener
里面?
我没有使用System.out.println()
,因为它只能在控制台中打印。
所以我有这个代码。如何从jOptionPane显示JFrame上的输入?
String input;
input = JOptionPane.showInputDialog("Type words:");
如何显示在JFrame
输入如果这个代码是我mouseListener
里面?
我没有使用System.out.println()
,因为它只能在控制台中打印。
this怎么样?
String input;
input = JOptionPane.showInputDialog("Type words:");
JOptionPane.showMessageDialog(null, input);
如果你真的需要它是一个新的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);
感谢@mKorbel添加链接:) –
我会试试你的代码! :D谢谢! – alicedimarco
等一下,你建议我把这个放在哪里?主要?构造函数或其他方法?因为我不知道如何使它工作。我有一个Main,一个构造函数,一个放置所有JFrames和一些mousemotionlisters的方法。 – alicedimarco
为了更快得到更好的帮助,请发布[SSCCE](http://sscce.org/)。 –