-
Notifications
You must be signed in to change notification settings - Fork 0
/
ButtonListener.java
52 lines (48 loc) · 1.58 KB
/
ButtonListener.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
/**
* ButtonListener.java
*
* Used when the button in the GUI is clicked.
* The resulting operation of the button is determined by the current state of the program.
*
* @author Shuhan Liu (sl1041) 154007082
* @author Nicole Heimbach (nsh43) 153002353
* @version RUBTClient Phase 2, 11/04/2015
*
*
*/
public class ButtonListener implements ActionListener{
JButton button;
ProcessHandler processes;
/**
* Constructor for objects of class ButtonListener.
* @param button the button this ButtonListener is added to
* @param processes used to determine the current state of the program and update it when the button is clicked
*/
public ButtonListener(JButton button, ProcessHandler processes){
this.button = button;
this.processes = processes;
}
/**
* Uses the current state of the program to determine the next operations to perform when the button is clicked
* @param ae a click on the button
*/
@Override
public void actionPerformed(ActionEvent ae) {
if (!processes.isStarted()){
button.setText("EXIT");
processes.restart();
/*if (processes.getTorrentSwingWorker().isDone()){
button.setText("Start");
processes.setStarted(false);
}*/
}
else{
processes.stop();
button.setText("Start");
System.out.println("---------------Stopped---------------");
}
}
}