#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

    Eclipse Help PLEASE


    Hi, I am new to programming and this might not be the right place to place this but I was wondering if someone could show me or repost the program with a bigger font of X and O inside the program. The font of the X and O inside the Program for tic tac toe is really small and I need it to be bigger

    java Code:
     
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Image;
     
    import javax.swing.ImageIcon;
    public class TicTacToe1 implements ActionListener {
     
    public static void main(String[] args) {
    new TicTacToe1();
    }
     
     
     
    final String VERSION = "Final";
     
    JFrame window = new JFrame("Tic-Tac-Toe " + VERSION);
     
    JMenuBar mnuMain = new JMenuBar();
    JMenuItem mnuNewGame = new JMenuItem("NEW GAME"),
    mnuInstruction = new JMenuItem("INSTRUCTIONS"),
    mnuExit = new JMenuItem("EXIT"),
    mnuAbout = new JMenuItem("");
     
    JButton btn1v1 = new JButton("START PvP"),
     
    btnBack = new JButton("< BACK");
    JButton btnEmpty[] = new JButton[10];
     
    JPanel pnlNewGame = new JPanel(),
    pnlNorth = new JPanel(),
    pnlSouth = new JPanel(),
    pnlTop = new JPanel(),
    pnlBottom = new JPanel(),
    pnlPlayingField = new JPanel();
    JLabel lblTitle = new JLabel("Tic-Tac-Toe");
    JTextArea txtMessage = new JTextArea();
     
    final int winCombo[][] = new int[][] {
    {1, 2, 3}, {1, 4, 7}, {1, 5, 9},
    {4, 5, 6}, {2, 5, 8}, {3, 5, 7},
    {7, 8, 9}, {3, 6, 9}
     
    };
    final int X = 700, Y = 700, color1 = 190;
    boolean inGame = false;
    boolean win = false;
    boolean btnEmptyClicked = false;
    String message;
    int turn = 1;
    int wonNumber1 = 1, wonNumber2 = 1, wonNumber3 = 1;
     
    public TicTacToe1() { 
    window.setSize(X, Y);
    window.setLocation(0, 0);
    window.setResizable(false);
    window.setLayout(new BorderLayout());
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
     
    pnlNewGame.setLayout(new GridLayout(2, 1, 2, 10));
    pnlNorth.setLayout(new FlowLayout(FlowLayout.CENTER));
    pnlSouth.setLayout(new FlowLayout(FlowLayout.CENTER));
     
    pnlNorth.setBackground(new Color(color1, color1-110, color1-100));
    pnlSouth.setBackground(new Color(color1, color1-110, color1-100));
     
    pnlTop.setBackground(new Color(color1, color1-110, color1-100));
    pnlBottom.setBackground(new Color(color1, color1-110, color1-100));
     
    pnlTop.setLayout(new FlowLayout(FlowLayout.CENTER));
    pnlBottom.setLayout(new FlowLayout(FlowLayout.CENTER));
    pnlNewGame.setBackground(new Color(color1, color1-110, color1-100));
     
     
    mnuMain.add(mnuNewGame);
    mnuMain.add(mnuInstruction);
    mnuMain.add(mnuExit);
     
     
    pnlNewGame.add(btn1v1);
     
     
    mnuNewGame.addActionListener(this);
    mnuExit.addActionListener(this);
    mnuInstruction.addActionListener(this);
    btn1v1.addActionListener(this);
     
    btnBack.addActionListener(this);
     
     
    pnlPlayingField.setLayout(new GridLayout(3, 3, 2, 2));
    pnlPlayingField.setBackground(Color.green);
    for(int i=1; i<=9; i++) {
    btnEmpty[i] = new JButton();
    btnEmpty[i].setBackground(new Color(color1, color1-110, color1-100));
    btnEmpty[i].addActionListener(this);
    pnlPlayingField.add(btnEmpty[i]);
    }
     
    pnlNorth.add(mnuMain);
    pnlSouth.add(lblTitle);
     
     
    window.add(pnlNorth, BorderLayout.NORTH);
    window.add(pnlSouth, BorderLayout.CENTER);
    window.setVisible(true);
     
    }
     
    public void actionPerformed(ActionEvent click) {
    Object source = click.getSource();
    for(int i=1; i<=9; i++) {
    if(source == btnEmpty[i] && turn < 10) {
    btnEmptyClicked = true;
    if(!(turn % 2 == 0))
     
    btnEmpty[i].setText("X");
    else
    btnEmpty[i].setText("O");
    btnEmpty[i].setEnabled(true);
    pnlPlayingField.requestFocus();
    turn++;
    }
    }
    if(btnEmptyClicked) {
    checkWin();
    btnEmptyClicked = false;
    }
    if(source == mnuNewGame) {
    clearPanelSouth();
    pnlSouth.setLayout(new GridLayout(2, 1, 2, 5));
    pnlTop.add(pnlNewGame);
    pnlBottom.add(btnBack);
    pnlSouth.add(pnlTop);
    pnlSouth.add(pnlBottom);
     
    }
    else if(source == btn1v1) {
    if(inGame) {
    int option = JOptionPane.showConfirmDialog(null, "Quit Current Game?",
    "Quit Game?" ,JOptionPane.YES_NO_OPTION);
    if(option == JOptionPane.YES_OPTION) {
    inGame = false;
    }
    }
    if(!inGame) {
    btnEmpty[wonNumber1].setBackground(new Color(color1, color1-110, color1-100));
    btnEmpty[wonNumber2].setBackground(new Color(color1, color1-110, color1-100));
    btnEmpty[wonNumber3].setBackground(new Color(color1, color1-110, color1-100));
    turn = 1;
    for(int i=1; i<10; i++) {
    btnEmpty[i].setText("");
    btnEmpty[i].setEnabled(true);
    }
    win = false;
    showGame();
     
    }
    }
    else if(source == btn1v1) {
     
    }
    else if(source == mnuExit) {
    int option = JOptionPane.showConfirmDialog(null, "Are you sure you want to exit?",
    "Exit Game" ,JOptionPane.YES_NO_OPTION);
    if(option == JOptionPane.YES_OPTION)
    System.exit(0);
    }
    else if(source == mnuInstruction) {
    clearPanelSouth();
    String message = "";
    txtMessage.setBackground(new Color(color1, color1-110, color1-100));
    if(source == mnuInstruction) {
    message = "Instructions:\n\n" +
    "Your goal is to be the first player to get 3 X's or O's in a\n" +
    "row. (horizontally, diagonally, or vertically)";
    } else {
     
    }
    txtMessage.setEditable(false);
    txtMessage.setText(message);
    pnlSouth.setLayout(new GridLayout(2, 1, 2, 5));
    pnlTop.add(txtMessage);
    pnlBottom.add(btnBack);
    pnlSouth.add(pnlTop);
    pnlSouth.add(pnlBottom);
    }
    else if(source == btnBack) {
    if(inGame)
    showGame();
    else {
    clearPanelSouth();
    pnlSouth.setLayout(new FlowLayout(FlowLayout.CENTER));
    pnlNorth.setVisible(true);
    pnlSouth.add(lblTitle);
    }
    }
    pnlSouth.setVisible(false);
    pnlSouth.setVisible(true);
    }
     
    public void showGame() { 
    clearPanelSouth();
    inGame = true;
    pnlSouth.setLayout(new BorderLayout());
    pnlSouth.add(pnlPlayingField, BorderLayout.CENTER);
    pnlPlayingField.requestFocus();
    }
     
    public void checkWin() { 
    for(int i=0; i<8; i++) {
    if(
    !btnEmpty[winCombo[i][0]].getText().equals("") &&
    btnEmpty[winCombo[i][0]].getText().equals(btnEmpty[winCombo[i][1]].getText()) &&
     
    btnEmpty[winCombo[i][1]].getText().equals(btnEmpty[winCombo[i][2]].getText())
     
    ) {
    win = true;
    wonNumber1 = winCombo[i][0];
    wonNumber2 = winCombo[i][1];
    wonNumber3 = winCombo[i][2];
    btnEmpty[wonNumber1].setBackground(Color.white);
    btnEmpty[wonNumber2].setBackground(Color.white);
    btnEmpty[wonNumber3].setBackground(Color.white);
    break;
    }
    }
    if(win || (!win && turn>9)) {
    if(win) {
    if(turn % 2 == 0)
    message = "X has won!";
    else
    message = "O has won!";
    win = false;
    } else if(!win && turn>9) {
    message = "Both players have tied!\nBetter luck next time.";
    }
    JOptionPane.showMessageDialog(null, message);
    for(int i=1; i<=9; i++) {
    btnEmpty[i].setEnabled(false);
    }
    }
    }
     
    public void clearPanelSouth() { 
    pnlSouth.remove(lblTitle);
    pnlSouth.remove(pnlTop);
    pnlSouth.remove(pnlBottom);
    pnlSouth.remove(pnlPlayingField);
    pnlTop.remove(pnlNewGame);
    pnlTop.remove(txtMessage);
    pnlBottom.remove(btnBack);
    }
     
    }
    Last edited by requinix; May 10th, 2013 at 02:44 PM. Reason: code tags
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,864
    Rep Power
    6351
    Please choose an appropriate forum for your posts. Your thread has been moved to Java Help.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo