import javax.swing.JOptionPane;
import java.awt.GridLayout;
public class TicTacToe
{
static int zeilen, spalten;
public static void main(String[] args)
{
MyFrame frame = new MyFrame();
String a = JOptionPane.showInputDialog("Anzahl der Zeilen eingeben");
String b = JOptionPane.showInputDialog("Anzahl der Spalten eingeben");
zeilen = Integer.parseInt(a);
spalten = Integer.parseInt(b);
frame.setLayout(new GridLayout(zeilen, spalten));
MyPanel[] panel = new MyPanel[zeilen * spalten];
for(int i = 0; i < zeilen * spalten; ++i)
{
panel[i] = new MyPanel();
frame.add(panel[i]);
}
frame.setVisible(true);
}
public int getSize() { return zeilen * spalten; }
}
import javax.swing.JFrame;
import javax.swing.ImageIcon;
public class MyFrame extends JFrame
{
ImageIcon icon = new ImageIcon("icon\\icon.png");
MyFrame()
{
super("TicTacToe");
this.setSize(600, 400);
this.setLocationRelativeTo(null);
this.setResizable(true);
this.setIconImage(icon.getImage());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class MyPanel extends JPanel implements MouseListener
{
static int count = 0;
JLabel label;
boolean bool;
MyPanel()
{
addMouseListener(this);
setBorder(BorderFactory.createLineBorder(Color.BLACK));
System.out.println(getSize());
label = new JLabel();
label.setFont(new Font("Courier", Font.BOLD,50));
add(label);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
if(count % 2 == 0)
{
g.setColor(Color.GREEN);
g.fillOval(100, 100, 50, 50);
} else {
g.setColor(Color.BLUE);
g.fillOval(50, 50, 100, 100);
}
}
public void mouseClicked(MouseEvent e)
{
if(!bool)
{
if(count % 2 == 0)
{
repaint();
bool = true;
++count;
} else {
repaint();
bool = true;
++count;
}
}
}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
}