https://github.com/dmlloyd/openjdk
okay, on this occasion I will make a simple game on netbeans, game that I mean is TicTacToe game. in the process of making this game we will create two programs that are in one package. okay we just go to the process.
for the first class you name it with * game.java * and below is the code you should write in this class. you can download it on this gist:full code link
okay, I'll explain a few important parts of the above program.
these are some of the classes we use in the process of making this game that is for the process of making a panel, frame, and grid.
import java.awt.Component;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.GridLayout;
public class Game extends JFrame { this is the declaration of the class nameJPanel p = new JPanel();this is the declaration of the object panel we created, and we initialize it with the letter P.XOButton buttons[] = new XOButton[9]; and this is for the creation of buttons that will display the X and O symbols.setSize(400, 400);
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE); this serves to set the process of opening and closing windows.p.setLayout(new GridLayout(3,3)); and this serves to set the layout and lines that will divide the layout into 3X3.for (int i=0; i<9; i++) {
buttons[i] = new XOButton();
Component add = p.add(buttons[i]);
import javax.swing.JButton;
import javax.swing.ImageIcon;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JButton; enable button functionimport javax.swing.ImageIcon; this class we use because we use images in this program.import java.awt.event.ActionListener; This serves to activate the action when we click.public class XOButton extends JButton implements ActionListener{
ImageIcon x,o;
byte value =0;
x = new ImageIcon(this.getClass().getResource("/GameMain/xx.png"));
o = new ImageIcon(this.getClass().getResource("/GameMain/oo.png"));
this.addActionListener(this);
https://gist.github.com/andilapulga/2d332d5537457744a5071a028bf66a5c