-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchIdGUI.java
More file actions
167 lines (149 loc) · 8.48 KB
/
Copy pathSearchIdGUI.java
File metadata and controls
167 lines (149 loc) · 8.48 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import javax.swing.*;
import javax.swing.border.*;
import java.awt.event.*;
import java.rmi.RemoteException;
import java.security.spec.InvalidKeySpecException;
public class SearchIdGUI extends GUIPage implements ActionListener{
private String title = "Search ID";
private AuctionClient client;
// Page Components:
private JPanel inputPanel; // Search Box
private JPanel resultsPanel; // Results Box
private JLabel nametag; // Item Variable Names...
private JLabel bidtag;
private JLabel descriptiontag;
private JLabel conditiontag;
private JLabel name; // Item Variable Values...
private JLabel bid;
private JLabel condition;
private JLabel description;
private JTextField inputID; // Text input for ID
private JButton submitID; // Button to confirm input and display result
public SearchIdGUI(AuctionClient c) {
client = c;
buildPage();
}
public void buildPage() {
inputPanel = new JPanel();
inputID = new JTextField();
submitID = new JButton();
resultsPanel = new JPanel();
nametag = new JLabel("Name");
bidtag = new JLabel("Current Bid");
descriptiontag = new JLabel("Description");
conditiontag = new JLabel("Condition");
name = new JLabel("");
bid = new JLabel("");
condition = new JLabel("");
description = new JLabel("");
description.setVerticalAlignment(1);
inputID.setToolTipText("Enter Item ID");
submitID.addActionListener(this);
submitID.setText("Submit");
// Specifies Search Box Layout
Border loweredetched = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
inputPanel.setBorder(BorderFactory.createTitledBorder(loweredetched, "Search by Item ID"));
GroupLayout inputPanelLayout = new GroupLayout(inputPanel);
inputPanel.setLayout(inputPanelLayout);
inputPanelLayout.setHorizontalGroup(inputPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(inputPanelLayout.createSequentialGroup().addContainerGap()
.addComponent(inputID, GroupLayout.PREFERRED_SIZE, 112, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(submitID)
.addContainerGap(142, Short.MAX_VALUE))
);
inputPanelLayout.setVerticalGroup(inputPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(inputPanelLayout.createSequentialGroup().addContainerGap()
.addGroup(inputPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(inputID, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE)
.addComponent(submitID))
.addContainerGap(39, Short.MAX_VALUE))
);
// Specifies Results Box Layout
resultsPanel.setBorder(BorderFactory.createTitledBorder(loweredetched, "Result"));
GroupLayout resultsPanelLayout = new GroupLayout(resultsPanel);
resultsPanel.setLayout(resultsPanelLayout);
resultsPanelLayout.setHorizontalGroup(
resultsPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(resultsPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(resultsPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
.addComponent(conditiontag, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(descriptiontag, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(bidtag, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(nametag, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(resultsPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(condition, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(bid, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(name, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(description, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
resultsPanelLayout.setVerticalGroup(
resultsPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(resultsPanelLayout.createSequentialGroup()
.addGap(8, 8, 8)
.addGroup(resultsPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(nametag)
.addComponent(name))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(resultsPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(bidtag)
.addComponent(bid))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(resultsPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(conditiontag)
.addComponent(condition))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(resultsPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(resultsPanelLayout.createSequentialGroup()
.addComponent(descriptiontag)
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(description, GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE))
.addContainerGap())
);
// Orders input and results panels in parent container
GroupLayout thisLayout = new GroupLayout(this);
this.setLayout(thisLayout);
thisLayout.setHorizontalGroup(
thisLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(thisLayout.createSequentialGroup()
.addContainerGap()
.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(inputPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(resultsPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
thisLayout.setVerticalGroup(
thisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(thisLayout.createSequentialGroup()
.addContainerGap()
.addComponent(inputPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(resultsPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addContainerGap(25, Short.MAX_VALUE))
);
}
public String getTitle() {
return title;
}
@Override
public void actionPerformed(ActionEvent e) {
// Search by ID Button
if (e.getSource() == submitID) {
try {
// Remotely calls getSpec method to return Auciton Item
AuctionItem item = client.remoteGetSpec(Integer.parseInt(inputID.getText()));
if(item == null)
JOptionPane.showMessageDialog(null, "Item not found.");
// Fill results box with item details
name.setText(item.getTitle());
bid.setText(String.format("£%.2f", item.getPrice()));
condition.setText(item.getCondition());
description.setText("<html><p style=\"width:200px\">" + item.getDescription() + "</p></html>");
} catch (NumberFormatException | RemoteException | InvalidKeySpecException | NullPointerException e1) {
}
}
}
}