-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.java
80 lines (65 loc) · 2.7 KB
/
main.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
import java.awt.Button;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.Box;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
public class main {
public static void main(String[] args){
System.out.println("===============================");
System.out.println("|~~ Simple Neural Network ~~|");
System.out.println("===============================");
Brain brain = new Brain();
// user drawing input.
UserDraw userDraw = new UserDraw();
// set background to white.
userDraw.clear();
// displays number guessed from user drawing.
NumberDraw numberDraw = new NumberDraw();
// set background to white.
numberDraw.clear();
JFrame frame = new JFrame("Simple Neural Network");
// houses submitBtn and clearBtn.
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.PAGE_AXIS));
// used to submit drawings to be evaluated by neuralNetwork.
JButton submitBtn = new JButton("Submit");
submitBtn.setMaximumSize(new Dimension(Integer.MAX_VALUE, submitBtn.getMinimumSize().height));
submitBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
numberDraw.clear();
numberDraw.paintNumber(brain.userTestNeural(userDraw.getImageString()));
}
});
// used to clear the UserDraw and numberDraw pannels.
JButton clearBtn = new JButton("Clear");
clearBtn.setMaximumSize(new Dimension(Integer.MAX_VALUE, clearBtn.getMinimumSize().height));
clearBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
userDraw.clear();
numberDraw.clear();
}
});
//add componets to frame.
buttonPanel.add(submitBtn);
buttonPanel.add(Box.createRigidArea(new Dimension(0, 10)));
buttonPanel.add(clearBtn);
buttonPanel.add(Box.createVerticalGlue());
frame.add(userDraw , BorderLayout.LINE_START);
frame.add(buttonPanel , BorderLayout.CENTER);
frame.add(numberDraw , BorderLayout.LINE_END);
frame.getRootPane().setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
//displaying frame.
frame.pack();
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}