-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStartGUI.java
84 lines (73 loc) · 2.37 KB
/
StartGUI.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
import java.awt.Container;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JComponent;
import java.awt.Component;
import java.awt.event.*;
import java.awt.Font;
import javax.sound.midi.*;
public class StartGUI extends JFrame implements ActionListener{
private JButton next;
private JComboBox inputDevice;
private JComboBox outputDevice;
private DanKey danKey;
public void initUI() {
setTitle("DanKey v0.0.1");
setSize(300,300);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
//create a new Keyboard
danKey = new DanKey();
//do some stuff
Container pane = getContentPane();
setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
//then add some components
pane.add(new JLabel("Please select an input device"));
inputDevice = new JComboBox(danKey.getDevices());
pane.add(inputDevice);
pane.add(new JLabel("Please select an output device"));
outputDevice = new JComboBox(danKey.getDevices());
pane.add(outputDevice);
next = new JButton("Next");
next.addActionListener(this);
pane.add(next);
//change the font size of everything and align to left
for (Component j:pane.getComponents()){
j.setFont(new Font("Arial", Font.PLAIN, 40));
((JComponent)j).setAlignmentX(Component.LEFT_ALIGNMENT);
}
}
public void actionPerformed(ActionEvent e){
//for now, we may assume that the action was the next button being pressed
//in which case, we want to set the input and output device, then call the
//next GUI (the main one)
//Also the following is a hack, only works if < 10 midi devices!
danKey.setInputOutputDevices((MidiDevice.Info)inputDevice.getSelectedItem(),
(MidiDevice.Info)outputDevice.getSelectedItem());
//actually start the playing
Thread playThread = new Thread(){
public void run(){
danKey.play();
}
};
playThread.start();
startMainGUI(danKey);
}
public void startMainGUI(DanKey dk){
MainGUI mg = new MainGUI();
mg.initUI(dk);
mg.pack();
mg.setVisible(true);
}
//just for testing purposes
public static void main(String[] a){
StartGUI sg = new StartGUI();
sg.initUI();
sg.pack();
sg.setVisible(true);
}
}