// handles local buttons in this JFrame @Override public void actionPerformed(ActionEvent e) { JButton button = (JButton) e.getSource(); if (button == btnLogin) { // show the login UI as another JFrame. multiple access is optional UILogin uiLogin = new UILogin(this); uiLogin.setVisible(true); } if (button == btnThread) { // manually stop/start the cleaning thread if (btnThread.getText().equals("Stop cleaner thread")) { // request to stop when thread in alive state stopTimer(); btnThread.setText("Start cleaner thread"); btnThread.setForeground(Color.BLUE); } else if (btnThread.getText().equals("Start cleaner thread")) { // request to start when thread in dead state startTimer(); btnThread.setText("Stop cleaner thread"); btnThread.setForeground(Color.RED); } } }