-
Writing text to a file.
I've tried:
Code:
connPort = port.getText();
serverIP = server.getText();
configF.setVisible(false);
try
{
BufferedWriter w = new BufferedWriter(new FileWriter(new File("sys/conf.txt")));
w.write(server.getText().concat("\n"));
w.write(port.getText());
w.write("This works!");
configL.setText("Save successful.");
}
catch(Throwable t)
{
configL.setText("Save unsucessful.");
}
Where server and port are JTextAreas holding the server and port, and configL is the label for the window. The label's set to "Save Successful.", but the file is blank after this runs. Can someone please tell me why?
EDIT 2: Above problem has been fixed. w.close(); Heh.
EDIT: configF is the JFrame holding all of this, and it should dissappear when I call configF.setVisible(false); but it doesn't. How should I go about making it dissappear?
Last edited by freeone3000; 10-20-2005 at 06:55 PM.
Reason: Fixed first problem.
-
Could you post more code? setVisible(false) should work! Try adding a call to dispose().
-
Code:
public JPanel createConfigPane()
{
final JPanel configPane = new JPanel(new GridBagLayout());
final JTextField server = new JTextField(serverIP);
final JTextField port = new JTextField(connPort);
server.setPreferredSize(nameSize);
port.setPreferredSize(nameSize);
JButton save = new JButton("Save");
JButton cancel = new JButton("Cancel");
save.setPreferredSize(new Dimension(70, 30));
cancel.setPreferredSize(new Dimension(90, 30));
JLabel portL = new JLabel("Port:");
JLabel serverL = new JLabel("Server address:");
final JLabel configL = new JLabel("Hiya!");
final GameGUI g = new GameGUI(new JFrame());
save.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
connPort = port.getText();
serverIP = server.getText();
configF.setVisible(false);
try
{
BufferedWriter w = new BufferedWriter(new FileWriter(new File("sys/conf.dat")));
w.write(server.getText().concat("\n"));
w.write(port.getText());
configL.setText("Save successful.");
w.close();
}
catch(Throwable t)
{
configL.setText("Save unsucessful.");
}
}
});
cancel.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
configF.setVisible(false);
configL.setText("...Ehm, bye?");
configF.dispose();
}
});
//GridBagLayout junk.
return configPane;
}
I hit "Cancel", and I see "..Ehm, bye?" up on top, where the JLabel is, after I click the "Cancel" button.
-
What is your question now?
Yes the button's actionlistener puts that text into the configL component.
-
Well, yes. But that's AFTER I dispose of the frame, and AFTER I set it to be invisible.
It should be set, but I shouldn't be able to see it.
Question would be: "How do I make JFrames go away?"
Last edited by freeone3000; 10-22-2005 at 05:57 PM.
Reason: added question
-
Cant' explain it. If what you've shown is being execture, setVisible(false) should make close the frame.
I can only guess that the code isn't executing as you think it is.
Add some println()s to see where it is executing and when.
-
Code:
configF.setVisible(false);
System.out.println("It should be invisible.");
configL.setText("...Ehm, bye?");
configF.dispose();
System.out.println("It should be gone.");
It is printing out those two bolded lines, but the frame's still visible.
Last edited by freeone3000; 10-23-2005 at 12:47 PM.
Reason: Clarifing
-
Only looking at a small part of the program, its hard to say.
Does configF refer to the ONLY frame? Are there any others?
-
There are a few other frames, else I would just call System.exit(0);. Generic "frame", which contains the main application frame. It's the only one "there" right now. The other frames are loginF, creditF, helpF, and charF, which are the login screen, credit screen, help screen, and characater creation screen, all uninitialized at this point.
createConfigPane() is called from a generic ActionListener set to a JButton, config, in the main "frame".
Similar Threads
-
By Mark in forum Database
Replies: 0
Last Post: 07-03-2001, 11:00 AM
-
By Matt Lake in forum VB Classic
Replies: 0
Last Post: 03-13-2001, 08:10 PM
-
By Hian Chew in forum VB Classic
Replies: 0
Last Post: 03-06-2001, 12:28 PM
-
By Paolo in forum VB Classic
Replies: 3
Last Post: 01-08-2001, 08:59 AM
-
By deborah in forum authorevents.kurata
Replies: 0
Last Post: 04-17-2000, 01:33 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|