SlideShare a Scribd company logo
Othello.java
package othello;
import core.Game;
import userInterface.OthelloUi;
public class Othello {
// main is "static" because it's going to be called by the java interpreter
// before any objects are created, thus, it does not need to be in an
// instance of the Othello class to be called, it can simply be called
// whenever.
public static void main(String[] args) {
Game game = new Game();
OthelloUi othelloUi = new OthelloUi(game);
}
}
OthelloUi.java
package userInterface;
import core.Game;
import userInterface.GameUi;
import userInterface.BoardUi;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
public class OthelloUi extends JFrame {
private Game game;
private GameUi gameUi;
private BoardUi boardUi;
public OthelloUi(Game game) {
this.game = game;
// Create components and put them in JFrame upon class
// instantiation.
initComponents();
}
private void initComponents() {
this.setPreferredSize(new Dimension(600, 600));
this.setMinimumSize(new Dimension(600, 600));
// This is done to close the actual application once the
// UI is closed via X.
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gameUi = new GameUi();
boardUi = new BoardUi();
// By default, JFrame uses BorderLayout as its LayoutManager,
// which is responsible for managing how UI components are placed
// within framses/panels.
this.add(gameUi, BorderLayout.NORTH);
this.add(boardUi, BorderLayout.CENTER);
this.setVisible(true);
}
}
GameUi.java
package userInterface;
import java.awt.Dimension;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class GameUi extends JPanel {
public GameUi() {
// Creates components and puts them in the JPanel on
// instantiation.
initComponents();
}
private JLabel nameOne;
private JLabel nameTwo;
private JLabel scoreOne;
private JLabel scoreTwo;
private void initComponents() {
// Set dimensions for JPanel.
this.setPreferredSize(new Dimension(200, 100));
this.setMinimumSize(new Dimension(200, 100));
// Label components.
nameOne = new JLabel("Player One");
nameTwo = new JLabel("Player Two");
scoreOne = new JLabel("0");
scoreTwo = new JLabel("0");
nameOne.setMinimumSize(new Dimension(100, 50));
nameTwo.setMinimumSize(new Dimension(100, 50));
scoreOne.setMinimumSize(new Dimension(100, 50));
scoreTwo.setMinimumSize(new Dimension(100, 50));
// JPanel uses FlowLayout layout manager, which adds components
// left to right in a row, until it runs out of space and creates
// a new row.
this.add(nameOne);
this.add(scoreOne);
this.add(nameTwo);
this.add(scoreTwo);
}
}
BoardUi.java
package userInterface;
import core.Constants;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
public class BoardUi extends JPanel {
private JButton[][] board;
private BoardListener listener;
public BoardUi() {
initComponents();
}
private void initComponents() {
int i, j;
this.setPreferredSize(new Dimension(400, 400));
this.setMinimumSize(new Dimension(400, 400));
// Default layout is FlowLayout, which is not what we want for
// how the game board will look, so override the layout to GridLayout.
this.setLayout(new GridLayout(Constants.ROWS, Constants.COLUMNS));
board = new JButton[Constants.ROWS][Constants.COLUMNS];
listener = new BoardListener();
for(i = 0; i
Solution
Othello.java
package othello;
import core.Game;
import userInterface.OthelloUi;
public class Othello {
// main is "static" because it's going to be called by the java interpreter
// before any objects are created, thus, it does not need to be in an
// instance of the Othello class to be called, it can simply be called
// whenever.
public static void main(String[] args) {
Game game = new Game();
OthelloUi othelloUi = new OthelloUi(game);
}
}
OthelloUi.java
package userInterface;
import core.Game;
import userInterface.GameUi;
import userInterface.BoardUi;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
public class OthelloUi extends JFrame {
private Game game;
private GameUi gameUi;
private BoardUi boardUi;
public OthelloUi(Game game) {
this.game = game;
// Create components and put them in JFrame upon class
// instantiation.
initComponents();
}
private void initComponents() {
this.setPreferredSize(new Dimension(600, 600));
this.setMinimumSize(new Dimension(600, 600));
// This is done to close the actual application once the
// UI is closed via X.
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gameUi = new GameUi();
boardUi = new BoardUi();
// By default, JFrame uses BorderLayout as its LayoutManager,
// which is responsible for managing how UI components are placed
// within framses/panels.
this.add(gameUi, BorderLayout.NORTH);
this.add(boardUi, BorderLayout.CENTER);
this.setVisible(true);
}
}
GameUi.java
package userInterface;
import java.awt.Dimension;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class GameUi extends JPanel {
public GameUi() {
// Creates components and puts them in the JPanel on
// instantiation.
initComponents();
}
private JLabel nameOne;
private JLabel nameTwo;
private JLabel scoreOne;
private JLabel scoreTwo;
private void initComponents() {
// Set dimensions for JPanel.
this.setPreferredSize(new Dimension(200, 100));
this.setMinimumSize(new Dimension(200, 100));
// Label components.
nameOne = new JLabel("Player One");
nameTwo = new JLabel("Player Two");
scoreOne = new JLabel("0");
scoreTwo = new JLabel("0");
nameOne.setMinimumSize(new Dimension(100, 50));
nameTwo.setMinimumSize(new Dimension(100, 50));
scoreOne.setMinimumSize(new Dimension(100, 50));
scoreTwo.setMinimumSize(new Dimension(100, 50));
// JPanel uses FlowLayout layout manager, which adds components
// left to right in a row, until it runs out of space and creates
// a new row.
this.add(nameOne);
this.add(scoreOne);
this.add(nameTwo);
this.add(scoreTwo);
}
}
BoardUi.java
package userInterface;
import core.Constants;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
public class BoardUi extends JPanel {
private JButton[][] board;
private BoardListener listener;
public BoardUi() {
initComponents();
}
private void initComponents() {
int i, j;
this.setPreferredSize(new Dimension(400, 400));
this.setMinimumSize(new Dimension(400, 400));
// Default layout is FlowLayout, which is not what we want for
// how the game board will look, so override the layout to GridLayout.
this.setLayout(new GridLayout(Constants.ROWS, Constants.COLUMNS));
board = new JButton[Constants.ROWS][Constants.COLUMNS];
listener = new BoardListener();
for(i = 0; i

More Related Content

PDF
Hi my question pretains to Java programing, What I am creating is a .pdf
PDF
This is Java, What I am creating is a multi lab pacman type game.T.pdf
PPTX
GUI Programming with Java
PDF
Java!!!!!Create a program that authenticates username and password.pdf
PDF
correct the error import javaxswingJFrame import javaxs.pdf
PDF
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
PPTX
it's about the swing programs in java language
PPT
Hi my question pretains to Java programing, What I am creating is a .pdf
This is Java, What I am creating is a multi lab pacman type game.T.pdf
GUI Programming with Java
Java!!!!!Create a program that authenticates username and password.pdf
correct the error import javaxswingJFrame import javaxs.pdf
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
it's about the swing programs in java language

Similar to Othello.javapackage othello;import core.Game; import userInter.pdf (20)

PDF
From Swing to JavaFX
PDF
correct the error and add code same in the pic import jav.pdf
PDF
Main class --------------------------import java.awt.FlowLayout.pdf
PDF
package net.codejava.swing.mail;import java.awt.Font;import java.pdf
PDF
import javaxswing import javaawtevent import javai.pdf
PDF
I am getting a syntax error. I cant seem to find whats causing t.pdf
PDF
import java.awt.event.ActionEvent; import java.awt.event.ActionLis.pdf
TXT
Maze
PDF
This is Java,I am currently stumped on how to add a scoreboard for.pdf
DOCX
20-Arid-850 Ali Haider Cheema BSSE(5A) Evening MPL Assignement 08.docx
PDF
In Java Write a GUI application to simulate writing out a check. The.pdf
PPT
2009 Hackday Taiwan Yui
PDF
Write a GUI application to simulate writing out a check. The value o.pdf
PDF
Groovy-er Desktop Applications With Griffon
PDF
Groovy-er desktop applications with Griffon
PPTX
swings.pptx
PPTX
Awt, Swing, Layout managers
PPT
What do you mean it needs to be Java based? How jython saved the day.
PDF
Deep dive into Oracle ADF
From Swing to JavaFX
correct the error and add code same in the pic import jav.pdf
Main class --------------------------import java.awt.FlowLayout.pdf
package net.codejava.swing.mail;import java.awt.Font;import java.pdf
import javaxswing import javaawtevent import javai.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdf
import java.awt.event.ActionEvent; import java.awt.event.ActionLis.pdf
Maze
This is Java,I am currently stumped on how to add a scoreboard for.pdf
20-Arid-850 Ali Haider Cheema BSSE(5A) Evening MPL Assignement 08.docx
In Java Write a GUI application to simulate writing out a check. The.pdf
2009 Hackday Taiwan Yui
Write a GUI application to simulate writing out a check. The value o.pdf
Groovy-er Desktop Applications With Griffon
Groovy-er desktop applications with Griffon
swings.pptx
Awt, Swing, Layout managers
What do you mean it needs to be Java based? How jython saved the day.
Deep dive into Oracle ADF
Ad

More from arccreation001 (20)

PDF
SOURCE CODEimport java.util.Iterator;public class CircularLinke.pdf
PDF
2) In Autocrine signalling, reception of a signal released by the sa.pdf
PDF
Volatility Distillation separates out different .pdf
PDF
The first one has Van der Waals interactions sinc.pdf
PDF
Supersaturated actually. There is more solvent th.pdf
PDF
In optics, a virtual image is an image in which t.pdf
PDF
1) Political orientation and ideas are the main reasons behind count.pdf
PDF
Molarity = moles volume in L Molarity = 0.0342.pdf
PDF
The tracheal system in insects and gills in fishes are both helps th.pdf
PDF
The answer is D. ChemoorganoheterotrophCow is a chemoorganohetero.pdf
PDF
The A and B chains of human insulin are cloned in separate plasmids .pdf
PDF
Question 1How many parameters does a default constructor haveAn.pdf
PDF
Rio de Janeiro is a city located on Brazils south-east coast. It i.pdf
PDF
1.Types of Computer Information SystemsThere are four basic type.pdf
PDF
Microbiome of human bodyResearchers currently studying human norm.pdf
PDF
Na2SeO3 --- 2 Na+ + SeO32- 0.08              0.16       0.08 .pdf
PDF
It is an important to understand the early stages of reproduction. W.pdf
PDF
Let the normal gene be represented by P, and the two mutations be re.pdf
PDF
Imagine you are an Information Systems Security Officer for a medium.pdf
PDF
Each water molecule has 4 hydrogen bonds holding .pdf
SOURCE CODEimport java.util.Iterator;public class CircularLinke.pdf
2) In Autocrine signalling, reception of a signal released by the sa.pdf
Volatility Distillation separates out different .pdf
The first one has Van der Waals interactions sinc.pdf
Supersaturated actually. There is more solvent th.pdf
In optics, a virtual image is an image in which t.pdf
1) Political orientation and ideas are the main reasons behind count.pdf
Molarity = moles volume in L Molarity = 0.0342.pdf
The tracheal system in insects and gills in fishes are both helps th.pdf
The answer is D. ChemoorganoheterotrophCow is a chemoorganohetero.pdf
The A and B chains of human insulin are cloned in separate plasmids .pdf
Question 1How many parameters does a default constructor haveAn.pdf
Rio de Janeiro is a city located on Brazils south-east coast. It i.pdf
1.Types of Computer Information SystemsThere are four basic type.pdf
Microbiome of human bodyResearchers currently studying human norm.pdf
Na2SeO3 --- 2 Na+ + SeO32- 0.08              0.16       0.08 .pdf
It is an important to understand the early stages of reproduction. W.pdf
Let the normal gene be represented by P, and the two mutations be re.pdf
Imagine you are an Information Systems Security Officer for a medium.pdf
Each water molecule has 4 hydrogen bonds holding .pdf
Ad

Recently uploaded (20)

PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
master seminar digital applications in india
PDF
Complications of Minimal Access Surgery at WLH
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Cell Structure & Organelles in detailed.
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Lesson notes of climatology university.
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
master seminar digital applications in india
Complications of Minimal Access Surgery at WLH
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
O7-L3 Supply Chain Operations - ICLT Program
Final Presentation General Medicine 03-08-2024.pptx
Cell Structure & Organelles in detailed.
STATICS OF THE RIGID BODIES Hibbelers.pdf
Lesson notes of climatology university.
VCE English Exam - Section C Student Revision Booklet
FourierSeries-QuestionsWithAnswers(Part-A).pdf
human mycosis Human fungal infections are called human mycosis..pptx
Anesthesia in Laparoscopic Surgery in India
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf

Othello.javapackage othello;import core.Game; import userInter.pdf

  • 1. Othello.java package othello; import core.Game; import userInterface.OthelloUi; public class Othello { // main is "static" because it's going to be called by the java interpreter // before any objects are created, thus, it does not need to be in an // instance of the Othello class to be called, it can simply be called // whenever. public static void main(String[] args) { Game game = new Game(); OthelloUi othelloUi = new OthelloUi(game); } } OthelloUi.java package userInterface; import core.Game; import userInterface.GameUi; import userInterface.BoardUi; import java.awt.BorderLayout; import java.awt.Dimension; import javax.swing.JFrame; public class OthelloUi extends JFrame { private Game game; private GameUi gameUi; private BoardUi boardUi; public OthelloUi(Game game) { this.game = game; // Create components and put them in JFrame upon class
  • 2. // instantiation. initComponents(); } private void initComponents() { this.setPreferredSize(new Dimension(600, 600)); this.setMinimumSize(new Dimension(600, 600)); // This is done to close the actual application once the // UI is closed via X. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); gameUi = new GameUi(); boardUi = new BoardUi(); // By default, JFrame uses BorderLayout as its LayoutManager, // which is responsible for managing how UI components are placed // within framses/panels. this.add(gameUi, BorderLayout.NORTH); this.add(boardUi, BorderLayout.CENTER); this.setVisible(true); } } GameUi.java package userInterface; import java.awt.Dimension; import javax.swing.JLabel; import javax.swing.JPanel; public class GameUi extends JPanel { public GameUi() { // Creates components and puts them in the JPanel on // instantiation. initComponents();
  • 3. } private JLabel nameOne; private JLabel nameTwo; private JLabel scoreOne; private JLabel scoreTwo; private void initComponents() { // Set dimensions for JPanel. this.setPreferredSize(new Dimension(200, 100)); this.setMinimumSize(new Dimension(200, 100)); // Label components. nameOne = new JLabel("Player One"); nameTwo = new JLabel("Player Two"); scoreOne = new JLabel("0"); scoreTwo = new JLabel("0"); nameOne.setMinimumSize(new Dimension(100, 50)); nameTwo.setMinimumSize(new Dimension(100, 50)); scoreOne.setMinimumSize(new Dimension(100, 50)); scoreTwo.setMinimumSize(new Dimension(100, 50)); // JPanel uses FlowLayout layout manager, which adds components // left to right in a row, until it runs out of space and creates // a new row. this.add(nameOne); this.add(scoreOne); this.add(nameTwo); this.add(scoreTwo); } }
  • 4. BoardUi.java package userInterface; import core.Constants; import java.awt.Color; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JPanel; public class BoardUi extends JPanel { private JButton[][] board; private BoardListener listener; public BoardUi() { initComponents(); } private void initComponents() { int i, j; this.setPreferredSize(new Dimension(400, 400)); this.setMinimumSize(new Dimension(400, 400)); // Default layout is FlowLayout, which is not what we want for // how the game board will look, so override the layout to GridLayout. this.setLayout(new GridLayout(Constants.ROWS, Constants.COLUMNS)); board = new JButton[Constants.ROWS][Constants.COLUMNS]; listener = new BoardListener(); for(i = 0; i Solution
  • 5. Othello.java package othello; import core.Game; import userInterface.OthelloUi; public class Othello { // main is "static" because it's going to be called by the java interpreter // before any objects are created, thus, it does not need to be in an // instance of the Othello class to be called, it can simply be called // whenever. public static void main(String[] args) { Game game = new Game(); OthelloUi othelloUi = new OthelloUi(game); } } OthelloUi.java package userInterface; import core.Game; import userInterface.GameUi; import userInterface.BoardUi; import java.awt.BorderLayout; import java.awt.Dimension; import javax.swing.JFrame; public class OthelloUi extends JFrame { private Game game; private GameUi gameUi; private BoardUi boardUi; public OthelloUi(Game game) { this.game = game; // Create components and put them in JFrame upon class // instantiation.
  • 6. initComponents(); } private void initComponents() { this.setPreferredSize(new Dimension(600, 600)); this.setMinimumSize(new Dimension(600, 600)); // This is done to close the actual application once the // UI is closed via X. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); gameUi = new GameUi(); boardUi = new BoardUi(); // By default, JFrame uses BorderLayout as its LayoutManager, // which is responsible for managing how UI components are placed // within framses/panels. this.add(gameUi, BorderLayout.NORTH); this.add(boardUi, BorderLayout.CENTER); this.setVisible(true); } } GameUi.java package userInterface; import java.awt.Dimension; import javax.swing.JLabel; import javax.swing.JPanel; public class GameUi extends JPanel { public GameUi() { // Creates components and puts them in the JPanel on // instantiation. initComponents(); }
  • 7. private JLabel nameOne; private JLabel nameTwo; private JLabel scoreOne; private JLabel scoreTwo; private void initComponents() { // Set dimensions for JPanel. this.setPreferredSize(new Dimension(200, 100)); this.setMinimumSize(new Dimension(200, 100)); // Label components. nameOne = new JLabel("Player One"); nameTwo = new JLabel("Player Two"); scoreOne = new JLabel("0"); scoreTwo = new JLabel("0"); nameOne.setMinimumSize(new Dimension(100, 50)); nameTwo.setMinimumSize(new Dimension(100, 50)); scoreOne.setMinimumSize(new Dimension(100, 50)); scoreTwo.setMinimumSize(new Dimension(100, 50)); // JPanel uses FlowLayout layout manager, which adds components // left to right in a row, until it runs out of space and creates // a new row. this.add(nameOne); this.add(scoreOne); this.add(nameTwo); this.add(scoreTwo); } } BoardUi.java
  • 8. package userInterface; import core.Constants; import java.awt.Color; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JPanel; public class BoardUi extends JPanel { private JButton[][] board; private BoardListener listener; public BoardUi() { initComponents(); } private void initComponents() { int i, j; this.setPreferredSize(new Dimension(400, 400)); this.setMinimumSize(new Dimension(400, 400)); // Default layout is FlowLayout, which is not what we want for // how the game board will look, so override the layout to GridLayout. this.setLayout(new GridLayout(Constants.ROWS, Constants.COLUMNS)); board = new JButton[Constants.ROWS][Constants.COLUMNS]; listener = new BoardListener(); for(i = 0; i