1 package com
.github
.puzzles
.gui
;
3 import java
.awt
.EventQueue
;
4 import java
.awt
.FlowLayout
;
5 import java
.awt
.event
.MouseAdapter
;
6 import java
.awt
.event
.MouseEvent
;
8 import javax
.swing
.BoxLayout
;
9 import javax
.swing
.JDialog
;
10 import javax
.swing
.JFrame
;
11 import javax
.swing
.JMenu
;
12 import javax
.swing
.JMenuBar
;
13 import javax
.swing
.JMenuItem
;
14 import javax
.swing
.JPanel
;
16 import com
.github
.puzzles
.core
.FlippingPuzzle
;
17 import com
.github
.puzzles
.core
.SlidingPuzzle
;
19 public class MainWindow
{
22 private FlippingPuzzle flippingPuzzle
;
23 private SlidingPuzzle sliddingPuzzle
;
24 private JPanel mainPanel
;
25 private JPanel puzzlePanel
;
28 * Launch the application.
30 public static void main(String
[] args
) {
31 EventQueue
.invokeLater(new Runnable() {
34 MainWindow window
= new MainWindow();
35 window
.frame
.setVisible(true);
36 } catch (Exception e
) {
44 * Create the application.
51 * Initialize the contents of the frame.
53 private void initialize() {
56 frame
.setDefaultCloseOperation(JFrame
.EXIT_ON_CLOSE
);
58 frame
.setBounds(0, 0, 800, 600);
60 JMenuBar topMenuBar
= new JMenuBar();
61 frame
.setJMenuBar(topMenuBar
);
63 JMenu menuFile
= new JMenu("File");
64 topMenuBar
.add(menuFile
);
66 JMenu newPuzzleMenu
= new JMenu("New puzzle");
67 menuFile
.add(newPuzzleMenu
);
69 JMenuItem flippingPuzzle
= new JMenuItem("Flipping Puzzle");
70 flippingPuzzle
.addMouseListener(new MouseAdapter() {
72 public void mouseReleased(MouseEvent e
) {
74 JDialog flippingPuzzleDialog
= new FlippingPuzzleDialog(
77 .setDefaultCloseOperation(JDialog
.DISPOSE_ON_CLOSE
);
78 flippingPuzzleDialog
.setAlwaysOnTop(true);
79 flippingPuzzleDialog
.setModal(true);
80 flippingPuzzleDialog
.setVisible(true);
83 * if(MainWindow.this.flippingPuzzle != null){
84 * puzzlePanel.add(new FlippingPuzzlePanel(MainWindow.this));
86 * frame.revalidate(); frame.repaint(); } //
90 newPuzzleMenu
.add(flippingPuzzle
);
92 JMenuItem slidingPuzzle
= new JMenuItem("Sliding Puzzle");
93 slidingPuzzle
.addMouseListener(new MouseAdapter() {
95 public void mouseReleased(MouseEvent e
) {
96 JDialog slidingPuzzleDialog
= new SlidingPuzzleDialog(
99 .setDefaultCloseOperation(JDialog
.DISPOSE_ON_CLOSE
);
100 slidingPuzzleDialog
.setAlwaysOnTop(true);
101 slidingPuzzleDialog
.setModal(true);
102 slidingPuzzleDialog
.setVisible(true);
106 newPuzzleMenu
.add(slidingPuzzle
);
108 JMenu helpMenu
= new JMenu("Help");
109 topMenuBar
.add(helpMenu
);
111 JMenuItem aboutMenu
= new JMenuItem("About me");
112 aboutMenu
.addMouseListener(new MouseAdapter() {
114 public void mouseReleased(MouseEvent e
) {
115 JDialog aboutMeDialog
= new AboutMeDialog();
116 aboutMeDialog
.setAlwaysOnTop(true);
117 aboutMeDialog
.setModal(true);
118 aboutMeDialog
.setVisible(true);
121 helpMenu
.add(aboutMenu
);
122 frame
.getContentPane().setLayout(
123 new FlowLayout(FlowLayout
.CENTER
, 5, 5));
125 mainPanel
= new JPanel();
126 frame
.getContentPane().add(mainPanel
);
127 mainPanel
.setLayout(new BoxLayout(mainPanel
, BoxLayout
.PAGE_AXIS
));
129 puzzlePanel
= new JPanel();
130 mainPanel
.add(puzzlePanel
);
131 puzzlePanel
.setLayout(new BoxLayout(puzzlePanel
, BoxLayout
.PAGE_AXIS
));
135 public void reset() {
136 flippingPuzzle
= null;
137 sliddingPuzzle
= null;
138 // frame.remove(puzzlePanel);
139 // frame.removeAll();
140 puzzlePanel
.removeAll();
146 public FlippingPuzzle
getFlippingPuzzle() {
147 return flippingPuzzle
;
150 public void setFlippingPuzzle(FlippingPuzzle flippingPuzzle
) {
151 this.flippingPuzzle
= flippingPuzzle
;
154 public SlidingPuzzle
getSliddingPuzzle() {
155 return sliddingPuzzle
;
158 public void setSliddingPuzzle(SlidingPuzzle sliddingPuzzle
) {
159 this.sliddingPuzzle
= sliddingPuzzle
;
162 public JPanel
getMainPanel() {
166 public JPanel
getPanel() {
170 public JPanel
getPuzzlePanel() {
174 public void setPuzzlePanel(JPanel puzzlePanel
) {
175 this.puzzlePanel
= puzzlePanel
;
178 public JFrame
getFrame() {