-
Notifications
You must be signed in to change notification settings - Fork 0
/
BandWindow.java
78 lines (78 loc) · 1.88 KB
/
BandWindow.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
import model.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class BandWindow extends JFrame
{
private Band band;
public BandWindow(Band band)
{ super("Band Window");
setup();
this.band = band;
build();
setVisible(true);
}
private void setup()
{
setSize(450, 100);
setLayout(new GridLayout(2, 1));
}
private void build()
{
add(new BandPanel());
}
private void close()
{
setVisible(false);
}
private class BandPanel extends JPanel implements MyObserver
{
private JTextField name = new JTextField(20);
private JTextField cost = new JTextField(6);
private JButton button = new JButton("Set");
public BandPanel()
{
setup();
build();
}
private void build()
{
addPair("Name", name);
addPair("Cost", cost);
add(button);
}
public void addPair(String label, JTextField field)
{
add(new JLabel(label));
add(field);
}
private void setup()
{
BandListener listener = new BandListener();
button.addActionListener(listener);
}
public String name()
{
return name.getText();
}
public double cost()
{
return Double.parseDouble(cost.getText());
}
public void update()
{
}
private class BandListener implements ActionListener
{
public BandListener()
{
}
public void actionPerformed(ActionEvent e)
{
band.setup(name(), cost());
close();
}
}
}
}