-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewButtonClickListener.java
41 lines (34 loc) · 1.38 KB
/
ViewButtonClickListener.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
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
public class ViewButtonClickListener implements ActionListener{
private ControllerGUI myController;
private ControllerToView myView;
public ViewButtonClickListener(ControllerGUI myController,ControllerToView myView){
this.myController = myController;
this.myView = myView;
}
//listen to buttons pushed in the ViewGUI
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if( command.equals( "Enter" )){
char guess = myView.getNextGuess();
myView.eraseGuess(String.valueOf(guess));
if(guess!=' '){
myController.guessGiven(guess);
}
}else if(command.equals("Give Up")){
myView.playAgain(false, myController.getWord());
}else if(command.equals("Exit")){
myView.endInterface();
}else if(command.equals("Play Again")){
myController.playAgain();
}else{//alphabet button for ViewGUI2
//myView.eraseGuess(command); THIS DOES NOT DISABLE THE BUTTON FOR SOME REASON
//PLEASE LET ME KNOW IF YOU FIGURE IT OUT
JButton buttonPushed = (JButton)e.getSource();
buttonPushed.setEnabled( false );
myController.guessGiven(command.charAt(0));
}
}
}