Changeset 289 in tmcsimulator for trunk


Ignore:
Timestamp:
03/02/2019 12:56:15 PM (7 years ago)
Author:
jdalbey
Message:

Login.java Clear prompt from username field in VisiCAD when user starts typing. Fixes #96.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/client/cadclientgui/screens/Login.java

    r59 r289  
    77import java.awt.event.ActionEvent; 
    88import java.awt.event.ActionListener; 
     9import java.awt.event.KeyEvent; 
     10import java.awt.event.KeyListener; 
    911import javax.swing.Box; 
    1012import javax.swing.BoxLayout; 
     
    2426 * @author Vincent 
    2527 */ 
    26 public class Login extends JFrame 
     28public class Login extends JFrame implements KeyListener 
    2729{ 
    2830    private Box login; 
     
    125127 
    126128        Box leftBox = new Box(BoxLayout.Y_AXIS); 
    127         leftBox.setMaximumSize(new Dimension(350, 50)); 
    128         leftBox.setMinimumSize(new Dimension(350, 50)); 
    129         leftBox.setPreferredSize(new Dimension(350, 50)); 
     129        leftBox.setMaximumSize(new Dimension(350, 90)); 
     130        leftBox.setMinimumSize(new Dimension(350, 90)); 
     131        leftBox.setPreferredSize(new Dimension(350, 90)); 
    130132        leftBox.setAlignmentX(LEFT_ALIGNMENT); 
    131133 
     
    133135        userNameLabel.setForeground(Color.WHITE); 
    134136        userNameField = new JTextField(kNamePrompt); 
     137        userNameField.addKeyListener(this); 
     138        userNameField.setForeground(Color.GRAY); 
    135139        Box userNameBox = new Box(BoxLayout.X_AXIS); 
    136140        userNameBox.setAlignmentX(LEFT_ALIGNMENT); 
     
    143147        passwordLabel.setForeground(Color.WHITE); 
    144148        passwordField = new JTextField("Not required"); 
     149        passwordField.setEnabled(false); 
    145150        Box passwordBox = new Box(BoxLayout.X_AXIS); 
    146151        passwordBox.setAlignmentX(LEFT_ALIGNMENT); 
     
    207212        setVisible(true); 
    208213    } 
     214 
     215    /**  
     216     * This keylistener removes the prompt displayed in the username text box 
     217     * the first time the user presses a key.  Fixes #96 
     218     * @author jdalbey 
     219     * @param evt  
     220     */ 
     221    public void keyPressed(KeyEvent evt)  
     222    { 
     223        // See if the text in the box is the initial prompt 
     224        // If so, the user hasn't typed anything yet, this is the 1st keypress 
     225        // Even the shift key will be caught here. 
     226        if (userNameField.getText().equals(kNamePrompt)) 
     227        { 
     228            userNameField.setText(""); 
     229            // Change the text color from gray to black 
     230            userNameField.setForeground(Color.BLACK); 
     231        } 
     232    } 
     233 
     234    public void keyReleased(KeyEvent e) {} 
     235    public void keyTyped(KeyEvent e) {} 
    209236} 
Note: See TracChangeset for help on using the changeset viewer.