Results 1 to 3 of 3
  1. #1
    BennyJass is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default Saving objects problem

    I'm not sure if this is the correct section, but I'll go ahead and post. I have 3 button groups, consisting of 2 JRadioButtons. I have Two JTextFields. How do I get it so after the first time the person presses the set up Button (Which brings up to all the components above), it will save what I put in the text fields, and which buttons I press? I'm just trying to get one down, I'll get the rest. In one of the text fields, you have to enter a method name(this is a utility program).

    I also set up a static int so it increments itself everytime you click the apply button (closes the window).

    When you click the set up button and opens the set up window:
    Java Code:
    		if (setUpClick >= 1) {
    			try {
    				FileInputStream setUpInfo = new FileInputStream("Set Up Info.ser");
    				ObjectInputStream setUpObject = new ObjectInputStream(setUpInfo);
    				String theMethodName = (String) setUpObject.readObject();
    				setUpObject.close();
    			} catch (ClassNotFoundException e) {
    				e.printStackTrace();
    			} catch (IOException ex) {
    				ex.printStackTrace();
    			}
    			methodName.setText(theMethodName);
    		}
    When I click the apply button:
    Java Code:
    	public class ApplyButton implements ActionListener {
    		public void actionPerformed(ActionEvent event) {
    			try {
    				FileOutputStream setUpWriting = new FileOutputStream("Set Up Info.ser");
    				ObjectOutputStream objectSetUp = new ObjectOutputStream(setUpWriting);
    				objectSetUp.writeObject(theMethodName);
    				objectSetUp.close();
    			} catch (IOException ex) {
    				ex.printStackTrace();
    			}
    			setUpClick++;
    			setUpFrame.dispose();
    		}
    	}
    This doesn't work. I don't know why.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    I'm not sure that I fully understand your question, but perhaps you don't want to dispose of your GUI window but rather call setVisible(false) on it. Then if you are to display it again, first check if it is null and if so, create the gui window, but if not, call setVisible(true) on it -- in other words do a lazy initialization of it.

  3. #3
    BennyJass is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default

    Oh man, I never thought of doing it that way. By setting it to false that sets the frame to null correct? So setting it back to visible would have all these options still there? Sounds much easier. Thanks. Yes, you answered the question.

Similar Threads

  1. regarding saving files or objects in database
    By sandeepsai39 in forum New To Java
    Replies: 10
    Last Post: 08-28-2010, 06:09 AM
  2. problem in saving file
    By jogendar in forum Advanced Java
    Replies: 2
    Last Post: 01-23-2010, 04:28 PM
  3. Saving Objects Permanently?
    By ethann_91 in forum New To Java
    Replies: 1
    Last Post: 01-20-2010, 08:03 AM
  4. help needed in saving objects
    By sandeepsai17 in forum New To Java
    Replies: 6
    Last Post: 06-30-2009, 04:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •