Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-23-2008, 10:02 PM
Member
 
Join Date: Apr 2008
Posts: 12
Fleur is on a distinguished road
waiting for a file
Hi people,

I'm trying to get a picture shown in a JPanel.
The problem is that the picture gets created when the app starts. This takes a while. Apparently the picture is not yet created when the app gets to the code to show the (not yet existing) picture which obviously generates an error.

How do I handle this?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-23-2008, 10:06 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 789
Nicholas Jordan is on a distinguished road
Show the code you have so far.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-23-2008, 10:18 PM
Member
 
Join Date: Apr 2008
Posts: 12
Fleur is on a distinguished road
This is what i have so far:
Code:
try { FileOutputStream oFile = new FileOutputStream("photo.jpg"); oFile.write(Picture.getData()); oFile.close(); }catch (Exception e){}
and a bit further on:

Code:
ShowImage photo = new ShowImage(); photo.setBounds(280,20,200,350); this.getContentPane().add(photo); this.repaint();
where ShowImage extends JPanel:

Code:
public class ShowImage extends JPanel { BufferedImage image; public ShowImage() { try { File input = new File("photo.jpg"); image = ImageIO.read(input); } catch (Exception ie) {} } public void paint(Graphics g) { g.drawImage(image, 0, 0, null); }
It will do what I want the second time I run the app: the phot.jpg file is already there from the previous time and the picture will load into the ShowImage, but clearly I don't need the picture of the previous run
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] File chooser selecting file from directory...? prabhurangan AWT / Swing 12 06-18-2008 06:08 AM
How to parse the CSV(Comma separation values)file and validate the file using java padmajap13 Advanced Java 7 05-23-2008 05:46 AM
How to read a text file from a Java Archive File Java Tip Java Tips 0 02-08-2008 11:13 AM
File fp = new File(filePath);fp.exists() does not yeild proper result ganeshp Advanced Java 1 12-27-2007 01:42 AM
count character in text file as input file aNNuur New To Java 0 06-18-2007 08:46 AM


All times are GMT +3. The time now is 12:45 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org