From 18e499686d1c9991b65dc79272038b291bc14c5d Mon Sep 17 00:00:00 2001 From: Przemyslaw Date: Mon, 1 Apr 2024 09:01:24 +0200 Subject: Init --- src/ColorsMemory.java | 310 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/Field.java | 41 +++++++ 2 files changed, 351 insertions(+) create mode 100644 src/ColorsMemory.java create mode 100644 src/Field.java (limited to 'src') diff --git a/src/ColorsMemory.java b/src/ColorsMemory.java new file mode 100644 index 0000000..0e11fef --- /dev/null +++ b/src/ColorsMemory.java @@ -0,0 +1,310 @@ +import java.awt.*; // Toolkit +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +//import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JMenuBar; +import javax.swing.JMenu; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.Box; + +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import java.util.Timer; +import java.util.*; //Timer +import java.lang.*; + +public class ColorsMemory extends JPanel + implements ActionListener { + static JMenuBar menuBar; + JMenu menu, info; + JMenuItem menuItem, menuExit, menuInfo; + static final int NW=4, NH=4; // weight - height + static JFrame frame; + static Timer timer; + static Field [][]field = new Field[NH][NW]; + static int []tmpi = new int[2]; + static int []tmpj = new int[2]; + static boolean showColor=false; + static boolean press=false; + static boolean lockClick=false; + static int nmove=0; + static int nFields; // ilosc pozostalych pol do odkrycia + static JLabel label = new JLabel("Witaj w Colors Memory!"); + + public ColorsMemory() { + super(new GridBagLayout()); + GridBagLayout gridbag = (GridBagLayout)getLayout(); + GridBagConstraints c = new GridBagConstraints(); + int i; + int j; + // int x, y; + int k=0; + + menuBar = new JMenuBar(); + menu = new JMenu("Plik"); + menuBar.add(menu); + // przenosi INFO na prawa strone + menuBar.add(Box.createHorizontalGlue()); + info = new JMenu("Info"); + info.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); + menuBar.add(info); + menuItem = new JMenuItem("Nowa Gra", null); + menuItem.setActionCommand("NewGame"); + menuItem.addActionListener(this); + menuItem.setToolTipText("Rozpoczyna nowa gre"); + menu.add(menuItem); + menu.addSeparator(); + menuItem = new JMenuItem("Zakoncz", null); + menuItem.setActionCommand("Exit"); + menuItem.addActionListener(this); + menuItem.setToolTipText("Wyjscie z programu"); + menu.add(menuItem); + menuItem = new JMenuItem("O Programie", null); + menuItem.setActionCommand("About"); + menuItem.addActionListener(this); + menuItem.setToolTipText("Informacje o programie"); + info.add(menuItem); + + for (i=0;i