-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoughtsCrossesGUI.java
More file actions
55 lines (40 loc) · 1.21 KB
/
NoughtsCrossesGUI.java
File metadata and controls
55 lines (40 loc) · 1.21 KB
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
53
54
55
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
public class NoughtsCrossesGUI implements Runnable
{
NoughtsCrossesModel model;
private JFrame frame;
public NoughtsCrossesGUI(NoughtsCrossesModel model){
this.model = model;
}
@Override
public void run() {
// TODO Auto-generated method stub
NoughtsCrossesComponent comp = new NoughtsCrossesComponent(model);
// create the frame for the game
frame = new JFrame("Noughts and Crosses");
frame.setSize(400, 400);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); // Hiding the frame, not closing it
/*
* add event to check if the window had changed condition
*/
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
model.setInVisible(false); // set the user not in game
}
});
frame.add(comp);
frame.setVisible(false);
}
/*
* set the visibility of the GUI - show the frame and restart the game
*/
public void setVisibleGUI(boolean visible){
frame.setVisible(visible);
model.newGame();
}
public boolean getVisibleGUI(){
return frame.isVisible();
}
}