|
| 1 | +package gov.doe.jgi.boost.ui; |
| 2 | +import javax.swing.GroupLayout; |
| 3 | +import javax.swing.JButton; |
| 4 | +import javax.swing.JFrame; |
| 5 | +import javax.swing.JLabel; |
| 6 | +import javax.swing.JPasswordField; |
| 7 | +import javax.swing.JTextField; |
| 8 | +import javax.swing.SwingConstants; |
| 9 | + |
| 10 | +public class LoginFrame { |
| 11 | + |
| 12 | + public LoginFrame(){ |
| 13 | + JFrame frame = new JFrame("Login to BOOST"); |
| 14 | + frame.setSize(300, 150); |
| 15 | + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
| 16 | + placeComponents(frame); |
| 17 | + frame.setVisible(true); |
| 18 | + } |
| 19 | + |
| 20 | + private static void placeComponents(JFrame jFrame) { |
| 21 | + |
| 22 | + GroupLayout layout = new GroupLayout(jFrame.getContentPane()); |
| 23 | + jFrame.getContentPane().setLayout(layout); |
| 24 | + |
| 25 | + layout.setAutoCreateGaps(true); |
| 26 | + layout.setAutoCreateContainerGaps(true); |
| 27 | + |
| 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"); |
| 34 | + |
| 35 | + layout.setHorizontalGroup(layout.createSequentialGroup() |
| 36 | + .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) |
| 37 | + .addComponent(userLabel) |
| 38 | + .addComponent(passwordLabel) |
| 39 | + .addComponent(cancelButton)) |
| 40 | + .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)) |
| 41 | + .addComponent(userText) |
| 42 | + .addComponent(passwordText) |
| 43 | + .addComponent(loginButton) |
| 44 | + ); |
| 45 | + |
| 46 | + // we would like the buttons to be always the same size |
| 47 | + layout.linkSize(SwingConstants.HORIZONTAL, cancelButton, loginButton); |
| 48 | + |
| 49 | + layout.setVerticalGroup(layout.createSequentialGroup() |
| 50 | + .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) |
| 51 | + .addComponent(userLabel) |
| 52 | + .addComponent(userText)) |
| 53 | + .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) |
| 54 | + .addComponent(passwordLabel) |
| 55 | + .addComponent(passwordText)) |
| 56 | + .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) |
| 57 | + .addComponent(cancelButton) |
| 58 | + .addComponent(loginButton)) |
| 59 | + ); |
| 60 | + |
| 61 | + jFrame.pack(); |
| 62 | + jFrame.setLocationRelativeTo(null); |
| 63 | + jFrame.setResizable(true); |
| 64 | + } |
| 65 | +} |
0 commit comments