11package gov .doe .jgi .boost .ui ;
2+ import java .awt .event .ActionEvent ;
3+ import java .awt .event .ActionListener ;
4+
25import javax .swing .GroupLayout ;
36import javax .swing .JButton ;
47import javax .swing .JFrame ;
710import javax .swing .JTextField ;
811import 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