-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
245 additions
and
1 deletion.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
src/test/java/il/ac/bgu/cs/bp/bpjs/TicTacToe/TTTDisplay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package il.ac.bgu.cs.bp.bpjs.TicTacToe; | ||
|
||
import java.awt.BorderLayout; | ||
import java.awt.GridLayout; | ||
import java.awt.Point; | ||
|
||
import javax.swing.JButton; | ||
import javax.swing.JFrame; | ||
import javax.swing.JLabel; | ||
import javax.swing.JPanel; | ||
import javax.swing.SwingConstants; | ||
|
||
import il.ac.bgu.cs.bp.bpjs.bprogram.runtimeengine.BProgram; | ||
|
||
/** | ||
* Class that implements the display of the game | ||
*/ | ||
public class TTTDisplay { | ||
private JFrame window = new JFrame("Tic-Tac-Toe"); | ||
public JButton buttons[][] = new JButton[3][]; | ||
public JLabel message = new JLabel(); | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
|
||
public TTTDisplay(BProgram bp) { | ||
|
||
// Create window | ||
window.setSize(150, 150); | ||
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
window.setLayout(new BorderLayout()); | ||
window.setLocation(new Point(550,100)); | ||
|
||
// The board | ||
JPanel board = new JPanel(); | ||
board.setLayout(new GridLayout(3, 3)); | ||
// The message label | ||
message.setHorizontalAlignment(SwingConstants.CENTER); | ||
|
||
// Create buttons | ||
for (int i = 0; i < 3; i++) { | ||
buttons[i] = new JButton[3]; | ||
for (int j = 0; j < 3; j++) { | ||
buttons[i][j] = new TTTButton(i, j); | ||
board.add(buttons[i][j]); | ||
// buttons[i][j].addActionListener(this); | ||
buttons[i][j].setEnabled(false); | ||
} | ||
} | ||
|
||
// Add the board and the message component to the window | ||
window.add(board, BorderLayout.CENTER); | ||
window.add(message, BorderLayout.SOUTH); | ||
|
||
// Make the window visible | ||
//window.setVisible(true); | ||
} | ||
|
||
// /** | ||
// * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) | ||
// */ | ||
// public void actionPerformed(ActionEvent a) { | ||
// final TTTButton btt = ((TTTButton) a.getSource()); | ||
// BThread sc = new ClickHandler(btt.row,btt.col); | ||
// bp.add(sc,20.0); | ||
// sc.startBThread(); | ||
// | ||
// } | ||
|
||
/** | ||
* A button that remembers its position on the board | ||
*/ | ||
@SuppressWarnings("serial") | ||
class TTTButton extends JButton { | ||
int row; | ||
int col; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param row | ||
* The row of the button. | ||
* @param col | ||
* The column of the button. | ||
*/ | ||
public TTTButton(int row, int col) { | ||
super(); | ||
this.row = row; | ||
this.col = col; | ||
} | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
src/test/java/il/ac/bgu/cs/bp/bpjs/TicTacToe/TTTListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package il.ac.bgu.cs.bp.bpjs.TicTacToe; | ||
|
||
import java.awt.BorderLayout; | ||
import java.awt.GridLayout; | ||
import java.awt.Point; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
|
||
import javax.swing.JButton; | ||
import javax.swing.JFrame; | ||
import javax.swing.JLabel; | ||
import javax.swing.JPanel; | ||
import javax.swing.SwingConstants; | ||
|
||
import il.ac.bgu.cs.bp.bpjs.bprogram.runtimeengine.BProgram; | ||
|
||
/** | ||
* Class that implements the Graphical User Interface for the game | ||
*/ | ||
public class TTTListener implements ActionListener { | ||
private JFrame window = new JFrame("Tic-Tac-Toe"); | ||
public JButton buttons[][] = new JButton[3][]; | ||
public JLabel message = new JLabel(); | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
|
||
public TTTListener(BProgram bp) { | ||
|
||
// Create window | ||
window.setSize(150, 150); | ||
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
window.setLayout(new BorderLayout()); | ||
window.setLocation(new Point(600,100)); | ||
|
||
// The board | ||
JPanel board = new JPanel(); | ||
board.setLayout(new GridLayout(3, 3)); | ||
// The message label | ||
message.setHorizontalAlignment(SwingConstants.CENTER); | ||
|
||
// Create buttons | ||
for (int i = 0; i < 3; i++) { | ||
buttons[i] = new JButton[3]; | ||
for (int j = 0; j < 3; j++) { | ||
buttons[i][j] = new TTTButton(i, j); | ||
board.add(buttons[i][j]); | ||
buttons[i][j].addActionListener(this); | ||
} | ||
} | ||
|
||
// Add the board and the message component to the window | ||
window.add(board, BorderLayout.CENTER); | ||
window.add(message, BorderLayout.SOUTH); | ||
|
||
// Make the window visible | ||
window.setVisible(true); | ||
} | ||
|
||
/** | ||
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) | ||
*/ | ||
public void actionPerformed(ActionEvent a) { | ||
// final TTTButton btt = ((TTTButton) a.getSource()); | ||
// BThread sc = new ClickHandler(btt.row,btt.col); | ||
// bp.add(sc,20.0); | ||
// sc.startBThread(); | ||
} | ||
|
||
/** | ||
* A button that remembers its position on the board | ||
*/ | ||
@SuppressWarnings("serial") | ||
class TTTButton extends JButton { | ||
int row; | ||
int col; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param row | ||
* The row of the button. | ||
* @param col | ||
* The column of the button. | ||
*/ | ||
public TTTButton(int row, int col) { | ||
super(); | ||
this.row = row; | ||
this.col = col; | ||
} | ||
|
||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/test/java/il/ac/bgu/cs/bp/bpjs/TicTacToe/TicTacToeGameMain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package il.ac.bgu.cs.bp.bpjs.TicTacToe; | ||
|
||
import java.awt.BorderLayout; | ||
import java.awt.GridLayout; | ||
import java.awt.Point; | ||
import java.awt.event.*; | ||
import javax.swing.*; | ||
|
||
import il.ac.bgu.cs.bp.bpjs.bprogram.runtimeengine.BProgram; | ||
import il.ac.bgu.cs.bp.bpjs.bprogram.runtimeengine.BProgramRunner; | ||
import il.ac.bgu.cs.bp.bpjs.bprogram.runtimeengine.SingleResourceBProgram; | ||
import il.ac.bgu.cs.bp.bpjs.bprogram.runtimeengine.listeners.StreamLoggerListener; | ||
|
||
class TicTacToeGameMain extends JFrame { | ||
|
||
// GUI for interactively playing the game | ||
public static TTTListener TTTlistener; | ||
|
||
// Add GUI for watching the model-checking run. | ||
public static TTTDisplay TTTdisplay; | ||
|
||
public static void main(String[] args) throws InterruptedException { | ||
// Create a program | ||
final SingleResourceBProgram bprog = new SingleResourceBProgram("BPJSTicTacToe.js"); | ||
JFrame f = new TicTacToeGameMain(); | ||
//f.setVisible(true); | ||
|
||
TTTdisplay = new TTTDisplay(bprog); | ||
TTTlistener = new TTTListener(bprog); | ||
|
||
BProgramRunner rnr = new BProgramRunner(bprog); | ||
rnr.addListener( new StreamLoggerListener() ); | ||
rnr.start(); | ||
|
||
} | ||
|
||
} | ||
|
||
@SuppressWarnings("serial") | ||
class TTTButton extends JButton { | ||
int row; | ||
int col; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param row | ||
* The row of the button. | ||
* @param col | ||
* The column of the button. | ||
*/ | ||
public TTTButton(int row, int col) { | ||
super(); | ||
this.row = row; | ||
this.col = col; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters