-
Notifications
You must be signed in to change notification settings - Fork 0
/
Board.java
executable file
·122 lines (76 loc) · 3 KB
/
Board.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.awt.*;
import java.util.*;
/**
*
* @author Srikarran Sowrirajan
*/
public class Board extends javax.swing.JFrame { //javax.swing.ActionListener {
private JFrame mainFrame;
public static JPanel jPanel1 , jPanel2;
public static LinkedList listNew;
public static JButton jBut1;
private static final long serialVersionUID = 1L; ;
public static GameTree game;
private JLabel headerLabel;
public Board (){
mainFrame = new JFrame("8 Puzzle");
mainFrame.setSize(280,280);
mainFrame.setLayout(new BorderLayout() );
headerLabel = new JLabel("",JLabel.CENTER );
jPanel1 = new JPanel(new GridLayout(1,1));
jPanel1.setSize(60, 60);
jPanel2 = new JPanel(new GridLayout(3,3));
jPanel2.setSize(180, 180);
Container c = this.getContentPane();
c.add(this.jPanel1, "Center");
jBut1 = new JButton();
jBut1.setText("Start");
jBut1.setSize(50, 100);
c.add(this.jBut1, "West");
//this.pack();
game = new GameTree();
jBut1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBut1ActionPerformed(evt);
}
});
try {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}
catch (Exception e) {
}
jPanel1.add(jBut1);
mainFrame.add(jPanel1, BorderLayout.NORTH);
mainFrame.add(jPanel2, BorderLayout.SOUTH);
mainFrame.add(headerLabel);
//mainFrame.pack();
mainFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
mainFrame.setVisible(true);
}
private static void jBut1ActionPerformed(java.awt.event.ActionEvent evt) {
int [] Array = game.getList().getNode().getArray();
game.percolate();
jPanel2.setLayout(new GridLayout(3, 3));
jPanel2.removeAll();
jBut1.setText("Next Move");
JButton button1;
int number = 0;
for (int i = 1; i <= 3; i ++) {
for (int j = 1; j <= 3; j ++) {
button1 = new JButton();
button1.setPreferredSize(new Dimension(60, 60));
jPanel2.add(button1);
button1.setText(Integer.toString(Array[number]));
number ++;
}
}
jPanel2.revalidate();
jPanel2.repaint();
}
public static void main(String args[]) {
Board board = new Board();
}
}