我想要的是:
我有一个 JPanel,上面有一个 JTextarea 和一个 JButton。按下按钮后,我希望在 JTextArea 中显示某个文本(根据 if-else 语句而变化)。
结构:
我有一个名为的字符串变量
yourphone
String yourphone;
在里面
ActionListener
,JButton
有 if-else 语句,像这样if(R==120) { yourphone = "Galaxy S4"; }
if(R==130) { yourphone = "Xperia Z ultra"; }这就是我的 JTextArea 的样子
JTextArea txtrphone = new JTextArea(); txtrphone.setText(yourphone); txtrphone.setRows(5); txtrphone.setBounds(68, 84, 285, 148); result.add(txtrphone);
问题
它不工作。
当我单击 时JBUtton
,没有任何反应。中没有出现任何内容JTextArea
。