-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUIStorage.java
More file actions
119 lines (101 loc) · 3.45 KB
/
GUIStorage.java
File metadata and controls
119 lines (101 loc) · 3.45 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package koebmand;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
public class GUIStorage extends JFrame
{
private JFrame jf = new JFrame();
private JPanel topPanel;
private JTable table;
private JScrollPane scrollPane;
private ArrayList<Goods> storList = new ArrayList<>();
private Storage stored = new Storage();
//Makes the GUI for storage.
public GUIStorage()
{ // Instance attributes used in this example
// Set the frame characteristics
this.setTitle( "Simple Table Application" );
this.setSize( 300, 200 );
this.setBackground( Color.GRAY );
// Create a panel to hold all other components
topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
this.getContentPane().add( topPanel );
// Create columns names
String columnNames[] = { "ID", "Item", "Supply number" };
// Create some data
String dataValues[][] =
{
};
storList.addAll(stored.getList());
for (Goods g : storList) {
dataValues[1][g.getID()] = "" + g.getID();
dataValues[2][g.getID()] = g.getName();
dataValues[3][g.getID()] = "" + g.getQuantity();
}
// Create a new table instance
table = new JTable( dataValues, columnNames );
// Add the table to a scrolling pane
scrollPane = new JScrollPane( table );
topPanel.add( scrollPane, BorderLayout.CENTER );
}
//Add buttons to add, remove and make a new item.
private JLabel button()
{
JLabel jl = new JLabel();
Storage store = new Storage();
JButton addX = new JButton("Add x");
addX.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String temp;
Goods good;
temp = JOptionPane.showInputDialog("What vil you add?");
for (Goods g : storList) {
if(g.getName().equalsIgnoreCase(temp))
{
good = g;
}
}
temp = JOptionPane.showInputDialog("How much will you add?");
int number = Integer.parseInt(temp);
// store.addQuantity(good ,number);
}
});
JButton removeX = new JButton("Remove x");
addX.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String temp;
Goods good;
temp = JOptionPane.showInputDialog("What vil you add?");
for (Goods g : storList) {
if(g.getName().equalsIgnoreCase(temp))
{
good = g;
}
}
temp = JOptionPane.showInputDialog("How much will you add?");
int number = Integer.parseInt(temp);
// store.addQuantity(good ,number);
}
});
JButton addNew = new JButton("Add new item");
addX.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// makeANew();
}
});
jl.add(addX, BorderLayout.WEST);
jl.add(removeX, BorderLayout.EAST);
jl.add(addNew, BorderLayout.CENTER);
return jl;
}
//Add a new item to the storage.
private void makeANew(String name, int price, int quantity)
{
storList.add(new Goods((storList.size() + 1), name, price, quantity));
}
}