我正在Netbeans 7.1中构建一个GUI,它代表了医院设备项目的输液泵.按jButton1应显示某个jLabel,表示输液正在运行.再次按jButton1应该停止它.我唯一的问题是按钮需要在第一次工作之前点击两次.在那之后,它完全符合我希望它的工作方式.我在这个问题上搜索了多个线程,但其他解决方案似乎不起作用.谁能帮我?提前致谢!
package infusion;
public class Infusion {
static Interface screen;
public Infusion(){
screen = new Interface();
screen.setVisible(true);
screen.jLabel3.setVisible(true);
screen.jButton1.setVisible(true);
}
public static void main(String[] args) {
// TODO code application logic here
Infusion infusion = new Infusion();
}
}
Run Code Online (Sandbox Code Playgroud)
这是用户界面的代码(主要由Netbeans生成).jButton1ActionPerformed的实现是我调整过的唯一代码.
package infusion;
public class Interface extends javax.swing.JFrame {
boolean pump1Running = false;
/**
* Creates new form Interface
*/
public Interface() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* …Run Code Online (Sandbox Code Playgroud)