Create a 2D board game using java AWT and mouse event. Original and simple example please!
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.FlowLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.*;
public class Game extends JPanel implements MouseListener
{
private Grid g = new Grid(5,5);
public Game()
{
JFrame frame = new JFrame("Boardgame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new FlowLayout()); frame.setLayout(new FlowLayout()); frame.setPreferredSize(new Dimension(500,500)); frame.pack(); frame.setVisible(true); frame.addMouseListener(this);
}
Step by step
Solved in 4 steps