gui.java
1 |
|
2 |
import java.util.*; |
3 |
|
4 |
class gui extends javax.swing.JFrame { |
5 |
public gui() { |
6 |
//Generating a couple of books: |
7 |
List<Boek> temp = new ArrayList<Boek>(); |
8 |
temp.add(new Boek("Fotocollage", 5, Boek.e_type.FOTOBOEK)); |
9 |
temp.add(new Boek("Vijftig tinten", 80, Boek.e_type.ROMAN)); |
10 |
temp.add(new Boek("De jacht op een voetbal", 2, Boek.e_type.STRIP)); |
11 |
setBoeken(temp); |
12 |
|
13 |
//Putting the books in a JList: |
14 |
DefaultListModel list = new DefaultListModel(); |
15 |
|
16 |
for(int i=0; i<temp.size(); i++) { |
17 |
list.addElement(temp.get(i).naam()); |
18 |
} |
19 |
|
20 |
final JList jlist = new JList(list); |
21 |
|
22 |
jlist.addListSelectionListener( //Dit voegt de listeners toe voor deze list. werk. (By Mannu) |
23 |
new javax.swing.event.ListSelectionListener() { |
24 |
public void valueChanged(javax.swing.event.ListSelectionEvent event) { |
25 |
viewBookDetails(event, jlist); } |
26 |
}); |
27 |
|
28 |
JPanel panel = new JPanel(); |
29 |
panel.add(jlist); |
30 |
JLabel label = new JLabel("Een test"); |
31 |
panel.add(label); |
32 |
|
33 |
JFrame frame = new JFrame("Stock management"); |
34 |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
35 |
|
36 |
frame.getContentPane().add(panel); |
37 |
|
38 |
|
39 |
frame.pack(); |
40 |
frame.setVisible(true); |
41 |
} |
42 |
|
43 |
public void viewBookDetails(javax.swing.event.ListSelectionEvent event, JList boeken) { |
44 |
Boek boek = boeken.getSelectedValue(); |
45 |
//Creating a new panel with book information: |
46 |
JPanel panel = new JPanel(); |
47 |
JLabel naam = new JLabel(boek.naam()); |
48 |
JLabel prijs = new JLabel(boek.prijs()); |
49 |
panel.add(naam); |
50 |
panel.add(prijs); |
51 |
frame().getContentPane.add(panel); |
52 |
|
53 |
frame.pack(); |
54 |
frame.setVisible(true); |
55 |
} |
56 |
|
57 |
|
58 |
|
59 |
private List<Boek> l_boeken; |
60 |
private JPanel m_jpanel; |
61 |
|
62 |
public List<Boek> boeken() { |
63 |
return l_boeken;} |
64 |
public void setBoeken(List<Boek> boeken) { |
65 |
l_boeken = boeken;} |
66 |
|
67 |
public JPanel jpanel() { |
68 |
return m_jpanel;} |
69 |
public void setPanel(JPanel jpanel) { |
70 |
m_jpanel = jpanel;} |
71 |
|
72 |
} |
73 |