• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

actionPerformed in frame problem

 
Pepo moussa
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, please check your private messages.
 
Pepo moussa
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apparently, textArea is never initialized to any non-null value. That means you call the FileOpener constructor with a null JTextArea.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic