3 import java.awt.event.*;
7 * Graphical representation of a MIDI note.
9 * @author Andersson, Andreen, Lanneskog, Pehrson
13 public class MooNoteProp extends JDialog{
16 private JOptionPane optionPane;
17 private JTextField pitch;
18 private JTextField velocity;
19 private JTextField length;
22 * Creates a new note preference dialog.
23 * @param mn The note that will be graphically represented
25 public MooNoteProp(MooNote mn) {
26 super((JFrame)null, true);
28 setTitle("Note properties");
30 pitch = new JTextField(new Integer(note.getPitch()).toString(),3);
31 JPanel pitchpanel = new JPanel();
32 pitchpanel.add(new Label("Pitch: "));
33 pitchpanel.add(pitch);
36 velocity = new JTextField(new Integer(note.getVelocity()).toString(),3);
37 JPanel velocitypanel = new JPanel();
38 velocitypanel.add(new Label("Velocity: "));
39 velocitypanel.add(velocity);
41 length = new JTextField(new Integer(note.getDuration()).toString(),5);
42 JPanel lengthpanel = new JPanel();
43 lengthpanel.add(new Label("Length: "));
44 lengthpanel.add(length);
46 Object[] array = {"Set the note properties",
51 final String btnString1 = "Enter";
52 final String btnString2 = "Cancel";
53 Object[] options = {btnString1, btnString2};
55 optionPane = new JOptionPane(array,
56 JOptionPane.QUESTION_MESSAGE,
57 JOptionPane.YES_NO_OPTION,
61 setContentPane(optionPane);
62 setDefaultCloseOperation(EXIT_ON_CLOSE);
64 textField.addActionListener(new ActionListener() {
65 public void actionPerformed(ActionEvent e) {
66 optionPane.setValue(btnString1);
70 optionPane.addPropertyChangeListener(new PropertyChangeListener() {
71 public void propertyChange(PropertyChangeEvent e) {
72 String prop = e.getPropertyName();
75 && (e.getSource() == optionPane)
76 && (prop.equals(JOptionPane.VALUE_PROPERTY) ||
77 prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
78 Object value = optionPane.getValue();
80 if (value == JOptionPane.UNINITIALIZED_VALUE) {
85 // Reset the JOptionPane's value.
86 // If you don't do this, then if the user
87 // presses the same button next time, no
88 // property change event will be fired.
90 JOptionPane.UNINITIALIZED_VALUE);
92 if (value.equals(btnString1)) {
93 note.setPitch(Integer.parseInt(pitch.getText()));
94 note.setVelocity(Integer.parseInt(velocity.getText()));
95 note.setDuration(Integer.parseInt(length.getText()));
98 } else { // user closed dialog or clicked cancel
107 public static void main(String[] args){
109 MooNote n = new MooNote(0,0,10,20,0,30);
110 MooNoteProp prop = new MooNoteProp(n);
111 prop.setVisible(true);
112 prop = new MooNoteProp(n);
113 prop.setVisible(true);