Java 如何使用JOptionPane.showInputDialog中的输入作为消息使用?
因此,我需要以我从中获得的输入为例Java 如何使用JOptionPane.showInputDialog中的输入作为消息使用?,java,eclipse,swing,input,joptionpane,Java,Eclipse,Swing,Input,Joptionpane,因此,我需要以我从中获得的输入为例 JOptionPane.showInputDialog(null, "text"); 如果用户输入一些文本,比如说,hello,它将被用作 JOptionPane.showMessageDialog(null, "Hello"); 我想我必须使用一个变量,比如: 变量=JOptionPane.showInputDialognull,文本 但是如何连接这两个变量以及变量的类型是什么?请阅读Oracle文档。然后查阅JOptionPane的 S
JOptionPane.showInputDialog(null, "text");
如果用户输入一些文本,比如说,hello,它将被用作
JOptionPane.showMessageDialog(null, "Hello");
我想我必须使用一个变量,比如:
变量=JOptionPane.showInputDialognull,文本
但是如何连接这两个变量以及变量的类型是什么?请阅读Oracle文档。然后查阅JOptionPane的
String message = JOptionPane.showInputDialog(null, "text");
JOptionPane.showMessageDialog(null, message);
JOptionPane.showInputDialogProvide输入;此语句返回可用于传入showMessageDialog的字符串值。参考下面的代码
String ans=JOptionPane.showInputDialog("Give some input");
JOptionPane.showMessageDialog(null, ans);
您可以将其添加到一行中
JOptionPane.showMessageDialog(null,JOptionPane.showInputDialog(null,"Please enter a message"));
或者,您可以创建一个字符串来保存消息:
String message = JOptionPane.showInputDialog(null,"Enter a message");
JOptionPane.showMessageDialog(null,message);
请注意,第一个参数可能为null,在这种情况下,默认帧用作父帧,对话框将根据L&F在屏幕上居中
阅读那么,您在不知道如何使用变量的情况下使用Swing?这就像驾驶波音飞机而不知道左右的区别。从基础开始。阅读Java入门,甚至是编程书籍或教程,在熟悉基本编程内容之后的基本OO内容之前,不要触摸Swing。请选择正确答案并关闭问题。