0

My JFrame Login Window has the Textfields "Benutzername" and "Passwort". So if i wanna enter my username and password I must first delete these two Textfields. How can i implement these as a "Hiddentext" or "Ghosttext" that it stands in the Background but isn't really there.

Here is the important part of my Code

public class GUI extends JFrame {

public static JFrame JFrame1 = new JFrame();
public static JFrame JFrame2 = new JFrame();
public static JFrame JFrame3 = new JFrame();
public static JFrame JFrame4 = new JFrame();
public static JTextField tfName;
public static JTextField tfPassword;
public static String inputName;
public static String inputPassword;
static HashMap<String, String> hmap;
static HashMap<String, String> times;
public static JLabel label2;
public static JPanel panel2;
public static JPanel panel3;
public static JPanel panel4;
public static File file;

public static void main(String[] args) {

    setProtocol();
    sethmp();
    setJFrame1();

}


public static void setProtocol() {

    SimpleDateFormat date = new SimpleDateFormat("MM.dd.yyyy");
    date.toString();

    file = new File (date+".txt");

}


public static void setJFrame1() {

    // Programming the login Screen

    JFrame1.setResizable(false);
    JFrame1.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    tfName = new JTextField("Benutzername", 20);
    JFrame1.setTitle("Zeiterfassungsytem");
    JFrame1.setSize(250, 200);
    JFrame1.setLocationRelativeTo(null);

    JPanel panel = new JPanel();
    JLabel labelname = new JLabel("Ihre Daten:");
    panel.add(labelname);
    JFrame1.getContentPane().add(panel);

    panel.add(tfName);

    tfPassword = new JTextField("Passwort", 20);
    panel.add(tfPassword);
    JFrame1.getContentPane().add(panel);

    // Creating login Button
    JButton buttonanmelden = new JButton("Anmelden");
    panel.add(buttonanmelden);
    buttonanmelden.addActionListener(new Login());

    JFrame1.setVisible(true);

}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
C.Ser
  • 1
  • 1
    1) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) 3) Lose every `static` declaration unless you can explain why it ***has to be*** `static`. – Andrew Thompson May 21 '18 at 11:49
  • Check out the `Text Prompt` found in: https://stackoverflow.com/a/44615728/131872 – camickr May 21 '18 at 14:46

0 Answers0