Results 1 to 11 of 11
- 07-07-2011, 11:55 PM #1
Senior Member
- Join Date
- Jul 2011
- Posts
- 100
- Rep Power
- 0
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);
}
}
}
}
openFileButton is the name of the JButton
RTTCPSortSimMain is the name of the class this all lives in
What should I be using in these places instead?
- 07-08-2011, 12:03 AM #2
Where is openFileButton defined? Is it in scope where you are trying to use it? The this. reference changes the scope to the current class. What class is that code in? It looks like an inner class. Try removing the this.Java Code:== this.openFileButton)
What data type is RTTCPSortSimMain?Java Code:showOpenDialog(RTTCPSortSimMain)
What does the API doc for the showOpenDialog() method say is the type of its argument?
- 07-08-2011, 12:06 AM #3
Cross posted at I'm trying to open a "FileOpenDialog"
- 07-08-2011, 04:16 AM #4
Thanks Norm. I won't waste my time here then...
db
- 07-08-2011, 04:03 PM #5
Senior Member
- Join Date
- Jul 2011
- Posts
- 100
- Rep Power
- 0
Removing the "this" alone didn't change the err msg, but moving its declaration "up" did.
I did have it being declared and instantiated (by copying the template code for the other button) inside the "go()" method:
...but now I declare it in the outer class, and then instantiate it in the inner class:Java Code:JButton openFileButton = new JButton("Open File"); openFileButton.addActionListener(new OpenFileButtonListener());
Java Code:public class RTTCPSortSimMain { . . . JButton openFileButton; + public void go() { . . . JButton sendButton = new JButton("Send and Receive"); sendButton.addActionListener(new SendButtonListener()); // above is the legacy (copied from a book) code; below is "my" button openFileButton = new JButton("Open File"); openFileButton.addActionListener(new OpenFileButtonListener());
- 07-08-2011, 04:27 PM #6
Senior Member
- Join Date
- Jul 2011
- Posts
- 100
- Rep Power
- 0
- 07-08-2011, 04:28 PM #7
Senior Member
- Join Date
- Jul 2011
- Posts
- 100
- Rep Power
- 0
- 07-08-2011, 04:31 PM #8
What data type is RTTCPSortSimMain?
It looks like the name of your class. What data type does the showOpenDialog() method take as an argument?It's the parent,
In some locations of your code, "this" could have a data type of RTTCPSortSimMain. But how is that any use when calling the showOpenDialog() method???
- 07-08-2011, 04:33 PM #9
Cross posting without notification that you are doing it means that we're wasting time answering a question that is already answered on another forum. Many of us don't like that.
- 07-08-2011, 04:41 PM #10
Senior Member
- Join Date
- Jul 2011
- Posts
- 100
- Rep Power
- 0
Sorry for the confusion - what I meant by "It's the parent" is that's what should be pased to JFileChooser. You're right, I originally had the class name there (I was just guessing what should go there based on an example I had, rather than really thinking it through - I know, that was my first mistake. Actually, my Nth mistake, but we won't talk about that.
- 07-08-2011, 04:42 PM #11
Senior Member
- Join Date
- Jul 2011
- Posts
- 100
- Rep Power
- 0
Similar Threads
-
Hwlp with "Open", "Save", "Save as..."
By trill in forum New To JavaReplies: 3Last Post: 11-02-2010, 09:26 AM -
connection = DriverManager.getConnection(DATABASE_URL,'"+userid +"','"+password+"');
By renu in forum New To JavaReplies: 3Last Post: 10-12-2010, 04:21 PM -
MoneyOut.println("It took you (whats wrong?>",year,"<WW?) years to repay the loan")
By soc86 in forum New To JavaReplies: 2Last Post: 01-24-2009, 06:56 PM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM -
Open "Save Page As" Dialog Box
By Anubha in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 12-12-2007, 09:27 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks