Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: I'm trying to open a "FileOpenDialog"

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    20
    Thanks
    13
    Thanked 1 Time in 1 Post

    Default I'm trying to open a "FileOpenDialog"

    I'm trying to open a "FileOpenDialog" but am getting two err msgs:

    1) openFileButton cannot be resolved or is not a field RTTCPSortSimMain.java

    2) RTTCPSortSimMain cannot be resolved to a variable
    public class OpenFileButtonListener implements ActionListener {
    		@Override
    		public void actionPerformed(ActionEvent e) {
    			if (e.getSource() == this.openFileButton) { // 1
    				final JFileChooser fc = new JFileChooser();
    				int returnVal = fc.showOpenDialog(RTTCPSortSimMain); //2
    				if (returnVal == JFileChooser.APPROVE_OPTION) {
    					File file = fc.getSelectedFile();
    					// This is where a real application would open the file.
    					// log.append("Opening: " + file.getName() + "." + newline);
    				} else {
    					// log.append("Open command cancelled by user." + newline);
    				}
    			}
    		}
    	}
    1) "openFileButton" is the name of the JButton
    2) "RTTCPSortSimMain" is the name of the class this all lives in

    What should I be using in these places instead?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I'm trying to open a "FileOpenDialog"

    This thread has been cross posted here:

    http://www.java-forums.org/new-java/46215-im-trying-open-fileopendialog.html#post220738

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting


  3. #3
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: I'm trying to open a "FileOpenDialog"

    ok, well you are saying this.openFileButton. I believe your problem is you are misinterpretting what this is referencing to. The keyword this references to the class that contains the keyword. So, when you have a nested class (such as the one I assume you have above), this is referring to the nested class, not the outer class.

    Look at the code below:
    public class OuterClass
    {	
    	int var = 0;
     
    	public OuterClass()
    	{
    		System.out.println(this.var); //References OuterClass's var variable
    	}
    	public class InnerClass
    	{
    		int var = 0;
     
    		public InnerClass()
    		{
    			System.out.println(this.var); //References InnerClass's var variable
    		}
    		public class InnerInnerClass
    		{
    			int var = 0;
     
    			public InnerInnerClass()
    			{
    				System.out.println(this.var); //References InnerInnerClass's var variable
    			}
    		}
    	}
    }

    Now, if you wanted to reference OuterClass's var variable from inside the InnerClass (by using the keyword this), you would have to say:
    public class OuterClass
    {	
    	int var = 0;
     
    	public OuterClass()
    	{
    		System.out.println(this.var); //References OuterClass's var variable
    	}
    	public class InnerClass
    	{
    		int var = 0;
     
    		public InnerClass()
    		{
    			System.out.println(OuterClass.this.var); //References OuterClass's var variable
    		}
    	}
    }

    Does that make sense? And could that be your problem?
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  4. The Following User Says Thank You to aussiemcgr For This Useful Post:

    Blackbird (July 8th, 2011)

Similar Threads

  1. Suddenly getting "Too Many Open File" error
    By newbie14 in forum Java Networking
    Replies: 4
    Last Post: December 12th, 2010, 11:12 PM
  2. Replies: 6
    Last Post: November 12th, 2010, 04:40 AM
  3. Java says:"Hello World". I say:"It works!"
    By Davidovic in forum Member Introductions
    Replies: 4
    Last Post: June 29th, 2010, 07:13 AM
  4. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM
  5. Replies: 4
    Last Post: August 13th, 2009, 05:54 AM