2011-11-21 68 views
0

所以我有这个代码。如何从jOptionPane显示JFrame上的输入?

String input; 
input = JOptionPane.showInputDialog("Type words:"); 

如何显示在JFrame输入如果这个代码是我mouseListener里面?

我没有使用System.out.println(),因为它只能在控制台中打印。

+0

为了更快得到更好的帮助,请发布[SSCCE](http://sscce.org/)。 –

回答

3

this怎么样?

String input; 
input = JOptionPane.showInputDialog("Type words:"); 
JOptionPane.showMessageDialog(null, input); 

如果你真的需要它是一个新的JFrame所示,您可以创建一个新的JFrame并添加inputJLabel;

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); 
+0

感谢@mKorbel添加链接:) –

+0

我会试试你的代码! :D谢谢! – alicedimarco

+0

等一下,你建议我把这个放在哪里?主要?构造函数或其他方法?因为我不知道如何使它工作。我有一个Main,一个构造函数,一个放置所有JFrames和一些mousemotionlisters的方法。 – alicedimarco