-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathView.java
77 lines (65 loc) · 3.59 KB
/
View.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
package simplesort;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class View {
JFrame frame;
JPanel firstPanel, secondPanel;
JButton startButton, stopButton;
Canvas canvas = new Canvas();
Sort_ sort_ = new Sort_();
public View() {
frame = new JFrame( "Simple Sort" );
// Frist panel parameters ==========================================================
firstPanel = new JPanel(); //
startButton = new JButton("Sort"); //
stopButton = new JButton("Pause"); //
firstPanel.setBorder(BorderFactory.createLineBorder(Color.BLUE)); //
firstPanel.setPreferredSize(new Dimension(100, 500)); //
startButton.setPreferredSize(new Dimension(96, 30)); //
startButton.addActionListener(new Sort()); //
stopButton.setPreferredSize(new Dimension(96, 30)); //
stopButton.addActionListener(new Pause()); //
firstPanel.add(startButton); //
firstPanel.add(stopButton); //
// =================================================================================
// Second panel parameters =========================================================
secondPanel = new JPanel(); //
secondPanel.setBorder(BorderFactory.createLineBorder(Color.BLUE)); //
secondPanel.setLayout(new BorderLayout()); //
secondPanel.setPreferredSize(new Dimension(200, 500)); //
secondPanel.add(canvas.canvas_, BorderLayout.CENTER); //
// =================================================================================
// Frame parameters ================================================================
frame.setSize(300, 550); // set frame size //
frame.setResizable(false); //
frame.setVisible(true); // display frame //
frame.setLayout(new BorderLayout()); //
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); //
// =================================================================================
// Add Panels to Frame =============================================================
frame.add(firstPanel, BorderLayout.WEST); //
frame.add(secondPanel, BorderLayout.CENTER); //
// =================================================================================
}
// First Handler =======================================================================
class Sort implements ActionListener { //
public void actionPerformed(ActionEvent ae) { //
canvas.timer.start(); //
} //
} //
// =====================================================================================
// Second Handler ======================================================================
class Pause implements ActionListener { //
public void actionPerformed(ActionEvent ae) { //
canvas.timer.stop(); //
} //
} //
// =====================================================================================
}