【发布时间】:2016-03-17 04:26:56
【问题描述】:
当用户单击应用程序运行的 jbutton1 并且 jbutton1 的文本从“连接”更改为“断开连接”时,我的 jbutton1 具有文本“连接”。现在再次当用户单击 jbutton1 并且文本是“断开连接”时,应用程序应该关闭。
我在这里给出的代码不会检查它会自动关闭我不想要的应用程序的任何内容。我想检查按钮的文本,如果它是连接的,我应该做一个不同的过程,如果它是断开的,它应该在单击按钮时关闭我的应用程序。
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
if(jComboBox2.getSelectedItem()==null)
{
System.out.println("Select one name");
}
else
{
try {
Runtime r = Runtime.getRuntime();
p = Runtime.getRuntime().exec("C:\\Program Files");
AS a4sObj = new AS(new String[]{jComboBox2.getSelectedItem().toString()});
} catch (IOException ex) {
Logger.getLogger(serialportselection.class.getName()).log(Level.SEVERE, null, ex);
}
jButton1.setText("Disconnect"); //This sets connect button to disconnect
if(jButton1.getText()== "Disconnect") // I wanted to change this line of code
{
System.exit(0);
}
【问题讨论】:
-
不确定 javascript 标签是否应该存在...
-
使用和
if-else声明