*
The moose likes Swing / AWT / SWT and the fly likes returning String from ActionPerformed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "returning String from ActionPerformed" Watch "returning String from ActionPerformed" New topic
Author

returning String from ActionPerformed

Alex Ter
Greenhorn

Joined: Sep 30, 2010
Posts: 10
Hi all,
I know this king of issue is quite common but I'm brand new in java so I found clues about my problem but didn't manage to make it works. Basically, I'm trying to build a small image processing program in which you load an image and then do simple stuff like rotating, changing colors, etc....
So far (which is very close for the moment...) I have a main frame which has a menu item saying "load image". When I click on it opens a file chooser, i select a picture. I would like to create a panel and then display it on the main frame.
So to do that, I retrieve the path of the picture from the file chooser in the ActionPerformed method but I wondering what to do then.

The thing is that I have to draw this picture on a panel then add it to the frame but after this I'll have to reuse it all the time when I'll do some modifications in the image. So I guess I shouldn't create the panel in the ActionPerformed method, should I ?
If not how can I return the string path of the picture from the ActionPerformed ? I tried to do it with setter/getter methods but probably didn't do it properly. Could you give me a bit of help regarding the right way to implement this kind of program ?
thanks
Here is my code for the main window, I'm using netBeans 6.9.

Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3056
    
  33

You can make the path to the picture an instance variable of some class. And then when you use the FileChooser to select the image- You can get the path and then set the path to the instance variable.


This can be one of the approaches.


Mohamed Sanaulla | My Blog
Kevin Workman
Ranch Hand

Joined: Sep 28, 2010
Posts: 151
This has been crossposted at http://www.javaprogrammingforums.com/awt-java-swing/6520-returning-string-actionperformed.html and http://www.java-forums.org/awt-swing/36335-returning-string-actionperformed.html

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

In Pseudo code
1) Subclass JPanel
2) Have a JLabel instance variable created and added to this panel
3) Provide a method called loadImage(File imageFile)
4) Add this panel to the frame. Initially it will show nothing
5) After user selects the image, invoke method in #3 above
5) Inside the method implementation
a)Store the File as an instance variable for later access
b)Set the image as an icon to the label instance in #2 above


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

Thanks Kevin.
I edited your post to correct the cross post link. You had posted the URL for this thread itself

Alex,
Please read http://www.coderanch.com/how-to/java/BeForthrightWhenCrossPostingToOtherSites which explains why crossposting without informing is a bad idea.
Alex Ter
Greenhorn

Joined: Sep 30, 2010
Posts: 10
thanks for the help for those who cared and for the virulent cross post hunter I really really apology. I really wasn't aware about cross posting issues as I never really got any help from forums and didn't expect that same people were on all the forums as I don't see the point to have then so many different ones.... anyways I'm really sorry
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Alex Ter wrote:thanks for the help for those who cared and for the virulent cross post hunter I really really apology. I really wasn't aware about cross posting issues as I never really got any help from forums and didn't expect that same people were on all the forums as I don't see the point to have then so many different ones.... anyways I'm really sorry


Appreciate the apology, but just for future reference, if you read the link about cross-posting provided to you above you would have understood that the problem is not that many volunteers are on other forums, it's that many are not, who risk wasting time answering a question that's already been answered elsewhere.

Luck
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Also learn the meaning of the adjective you applied to the 'cross post hunter'


luck, db
There are no new questions, but there may be new answers.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
Darryl Burke wrote:Also learn the meaning of the adjective you applied to the 'cross post hunter'
At least you apologised, but have a look at this FAQ, Alex Ter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: returning String from ActionPerformed
 
Similar Threads
Pass data back to Window 1 from Window 2
Whatz the problem
JMenubar/Jmenu/JMenuItem does not work
How can i display minimize and iconifiable button in JInternalFrame
Insert an image in JScrollPane