wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes actionPerformed in frame problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "actionPerformed in frame problem" Watch "actionPerformed in frame problem" New topic
Author

actionPerformed in frame problem

Pepo moussa
Ranch Hand

Joined: Mar 20, 2008
Posts: 36
i got a problem with this 2 codes..everytime i try to compile it give me an error and says it can find the printClass method ? any idea what is wrong.




Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

If the actionPerformed method is not inside the Viewer class, you will need to get a reference to a Viewer instance first, then call printClass on that instance.

Alternatively, you can make the printClass method static and call it as Viewer.printClass(...). You can do this in this case since the printClass does not use any instance variables, only local variables and its parameters.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

By the way, please check your private messages.
Pepo moussa
Ranch Hand

Joined: Mar 20, 2008
Posts: 36
i think i will go with getting a reference to a Viewer instance, so how this could be done like if you have any links for example or tutorial that would be great
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

The general method is create an instance variable, and then set it:

You can also pass the viewer to your constructor and set it there, but I've chosen not to do this since you will need to update all code that calls such a constructor.

Please also note the check against null - this will prevent errors in case you forget to set the Viewer.
Pepo moussa
Ranch Hand

Joined: Mar 20, 2008
Posts: 36
i got what you mean ..well i got another problem relater.this code compile and runs fine but it suppose to display the data..which does not get displayed.also if i took off the object "textArea1" i get this exception any idea what this could be ?





Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

The error is in line 53 of FileOpener.java. Could you tell us which line that is? Possibly it is the list.beginIterating; I can't see any of the other lines causing any problems.


You do know that you create a new JTextArea and JTextField each time, then discard them, right? You probably want to use existing controls; these should then be instance variables too. You initialize them once, then reuse them each time.
I'm also a bit troubled by the "filechooser.showOpenDialog(null)" call; please use the button or frame as the component to center the file chooser for. That will make it modal too.
Pepo moussa
Ranch Hand

Joined: Mar 20, 2008
Posts: 36
i sorry that i did not tell you what us line 53


the exception happens on line 53 only when i use that instance variable "textArea". also i sure now that the problem with the append or settext methods, if you try to take line 53 off the same exception happends on line 63 " the append text area".

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

Apparently, textArea is never initialized to any non-null value. That means you call the FileOpener constructor with a null JTextArea.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: actionPerformed in frame problem
 
Similar Threads
What's wrong with this simple application?
I don't know what's wrong with this chess game
Help with reprinting downloaded text from FTP site onto GUI!
save text file problem help !
io Problem ..moving the files one directory to another