-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNQueens.java
More file actions
46 lines (37 loc) · 1.08 KB
/
NQueens.java
File metadata and controls
46 lines (37 loc) · 1.08 KB
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
import javax.swing.JFrame;
import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.Color;
public class NQueens extends JFrame{
private ControlPanel controls;
private DisplayPanel display;
public NQueens() {
super("NQueens Genetic Algorithm");
setLayout(new BorderLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
setResizable(false);
display = new DisplayPanel();
controls = new ControlPanel(display);
add(controls, BorderLayout.WEST);
add(display, BorderLayout.EAST);
pack();
// Centers the window and sets it to be visible
setLocationRelativeTo(null);
setVisible(true);
}
public void start() {
while (true) {
controls.update();
// An error can occur if the user clicks restart too fast
try {
display.update();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void main(String args[]) {
NQueens window = new NQueens();
window.start();
}
}