0

I am writing a program, which represents a clock, and also has a textfield, which I instantiate with :

JTextField tfield = new JTextField();

So, I want the user to fill the textfield with a String like 12 34 56 (which should set off the alarm of the clock at that given time).

My main method executes the following:

public static void main(String[] args)  {
    createAndShowGui();
}

...where createAndShowGui() creates Panel and Frame (plus Textfield and Buttons) and calls the other function which I use to display the current time.

clock

Gopi
  • 620
  • 8
  • 16
Skerre
  • 5
  • 2

2 Answers2

0

so to clarify my question :

The user should be able to add a String to a Textfield within my frame. The program should write the entered String to a txt.file and also open it when restarted. Thats it !

Greetings !

Skerre
  • 5
  • 2
0

JTextField by default allows the user to enter text into it. Its getText() method retrieves the text it contains.

Writing to a text file in java is accomplished via one of the Writer classes, for example class FileWriter.

Since Swing is event driven, you need to decide which event will call method getText() and write that text to a file. I would suggest one of the buttons in your GUI.

Abra
  • 19,142
  • 7
  • 29
  • 41