Skip to content

Commit 54a49d7

Browse files
committed
Event listener added to JWTAuthenticationFrame and LoginFrame
1 parent b93643e commit 54a49d7

2 files changed

Lines changed: 65 additions & 17 deletions

File tree

src/main/java/gov/doe/jgi/boost/ui/JWTAuthenticationFrame.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package gov.doe.jgi.boost.ui;
22

3+
import java.awt.event.ActionEvent;
4+
import java.awt.event.ActionListener;
5+
36
import javax.swing.GroupLayout;
47
import javax.swing.JButton;
58
import javax.swing.JFrame;
@@ -8,7 +11,12 @@
811
import javax.swing.JTextField;
912
import javax.swing.SwingConstants;
1013

11-
public class JWTAuthenticationFrame {
14+
public class JWTAuthenticationFrame implements ActionListener{
15+
16+
private JLabel jWTTokenText;
17+
private JTextField tokenText;
18+
private JButton submitButton;
19+
private JButton cancelButton;
1220

1321
public JWTAuthenticationFrame(){
1422
JFrame frame = new JFrame("JWTAuthentication");
@@ -18,18 +26,21 @@ public JWTAuthenticationFrame(){
1826
frame.setVisible(true);
1927
}
2028

21-
private static void placeComponents(JFrame jFrame) {
29+
private void placeComponents(JFrame jFrame) {
2230

2331
GroupLayout layout = new GroupLayout(jFrame.getContentPane());
2432
jFrame.getContentPane().setLayout(layout);
2533

2634
layout.setAutoCreateGaps(true);
2735
layout.setAutoCreateContainerGaps(true);
2836

29-
JLabel jWTTokenText = new JLabel("Please peovide your JWT Token:");
30-
JTextField tokenText = new JTextField(25);
31-
JButton submitButton = new JButton("Submit");
32-
JButton cancelButton = new JButton("Cancel");
37+
jWTTokenText = new JLabel("Please peovide your JWT Token:");
38+
tokenText = new JTextField(25);
39+
submitButton = new JButton("Submit");
40+
cancelButton = new JButton("Cancel");
41+
42+
submitButton.addActionListener(this);
43+
cancelButton.addActionListener(this);
3344

3445
layout.setHorizontalGroup(layout.createSequentialGroup()
3546
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
@@ -56,4 +67,14 @@ private static void placeComponents(JFrame jFrame) {
5667
jFrame.setLocationRelativeTo(null);
5768
jFrame.setResizable(true);
5869
}
70+
71+
@Override
72+
public void actionPerformed(ActionEvent event) {
73+
Object source = event.getSource();
74+
if (source == submitButton) {
75+
System.out.println("Submit button was clicked");
76+
} else if (source == cancelButton) {
77+
System.out.println("Cancel button was clicked");
78+
}
79+
}
5980
}
Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
package gov.doe.jgi.boost.ui;
2+
import java.awt.event.ActionEvent;
3+
import java.awt.event.ActionListener;
4+
25
import javax.swing.GroupLayout;
36
import javax.swing.JButton;
47
import javax.swing.JFrame;
@@ -7,7 +10,17 @@
710
import javax.swing.JTextField;
811
import javax.swing.SwingConstants;
912

10-
public class LoginFrame {
13+
import gov.doe.jgi.boost.client.constants.BOOSTConstants;
14+
import gov.doe.jgi.boost.client.utils.UIUtils;
15+
16+
public class LoginFrame implements ActionListener{
17+
18+
private JLabel userLabel;
19+
private JTextField userText;;
20+
private JLabel passwordLabel;
21+
private JPasswordField passwordText;
22+
private JButton submitButton;
23+
private JButton cancelButton;
1124

1225
public LoginFrame(){
1326
JFrame frame = new JFrame("Login to BOOST");
@@ -17,20 +30,23 @@ public LoginFrame(){
1730
frame.setVisible(true);
1831
}
1932

20-
private static void placeComponents(JFrame jFrame) {
33+
private void placeComponents(JFrame jFrame) {
2134

2235
GroupLayout layout = new GroupLayout(jFrame.getContentPane());
2336
jFrame.getContentPane().setLayout(layout);
2437

2538
layout.setAutoCreateGaps(true);
2639
layout.setAutoCreateContainerGaps(true);
2740

28-
JLabel userLabel = new JLabel("User Name");
29-
JTextField userText = new JTextField(20);
30-
JLabel passwordLabel = new JLabel("Password");
31-
JPasswordField passwordText = new JPasswordField(20);
32-
JButton loginButton = new JButton("Submit");
33-
JButton cancelButton = new JButton("Cancel");
41+
userLabel = new JLabel("User Name");
42+
userText = new JTextField(20);
43+
passwordLabel = new JLabel("Password");
44+
passwordText = new JPasswordField(20);
45+
submitButton = new JButton("Submit");
46+
cancelButton = new JButton("Cancel");
47+
48+
submitButton.addActionListener(this);
49+
cancelButton.addActionListener(this);
3450

3551
layout.setHorizontalGroup(layout.createSequentialGroup()
3652
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
@@ -40,11 +56,11 @@ private static void placeComponents(JFrame jFrame) {
4056
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING))
4157
.addComponent(userText)
4258
.addComponent(passwordText)
43-
.addComponent(loginButton)
59+
.addComponent(submitButton)
4460
);
4561

4662
// we would like the buttons to be always the same size
47-
layout.linkSize(SwingConstants.HORIZONTAL, cancelButton, loginButton);
63+
layout.linkSize(SwingConstants.HORIZONTAL, cancelButton, submitButton);
4864

4965
layout.setVerticalGroup(layout.createSequentialGroup()
5066
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
@@ -55,11 +71,22 @@ private static void placeComponents(JFrame jFrame) {
5571
.addComponent(passwordText))
5672
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
5773
.addComponent(cancelButton)
58-
.addComponent(loginButton))
74+
.addComponent(submitButton))
5975
);
6076

6177
jFrame.pack();
6278
jFrame.setLocationRelativeTo(null);
6379
jFrame.setResizable(true);
6480
}
81+
82+
@Override
83+
public void actionPerformed(ActionEvent event) {
84+
Object source = event.getSource();
85+
if (source == submitButton) {
86+
System.out.println("Submit button was clicked");
87+
} else if (source == cancelButton) {
88+
System.out.println("Cancel button was clicked");
89+
}
90+
}
6591
}
92+

0 commit comments

Comments
 (0)