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 08-01-2007, 04:09 PM
Member
 
Join Date: Jul 2007
Posts: 33
cecily is on a distinguished road
how to import a picture into an applet
I can't really get the way to import a picture into an applet, I don't need to do anything specific with it only import it into the applet
help please
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-03-2007, 11:51 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
If you mean image loading here are four options available in applets.
Code:
// <applet code="AppletImageLoading" width="400" height="400"></applet> // prompt>appletviewer AppletImageLoading.java import java.awt.*; import java.awt.image.BufferedImage; import java.io.IOException; import java.net.URL; import javax.imageio.ImageIO; import javax.swing.*; public class AppletImageLoading extends JApplet { public void init() { Image[] images = loadImages(); JPanel panel = new JPanel(new GridLayout(0,2)); for(int j = 0; j < images.length; j++) panel.add(new JLabel(new ImageIcon(images[j]))); getContentPane().add(new JScrollPane(panel)); } private Image[] loadImages() { Image[] images = new Image[4]; String path = "images/Bird.gif"; // getResource looks for image on class path. URL url = getClass().getResource(path); // Use Applet method. images[0] = getImage(url); loadImage(images[0]); // Use Toolkit method. images[1] = getToolkit().createImage(url); loadImage(images[1]); // Use ImageIcon. ImageIcon icon = new ImageIcon(url); showLoadingStatus(icon.getImageLoadStatus()); images[2] = icon.getImage(); // Use ImageIO read method. try { images[3] = ImageIO.read(url); } catch(IOException e) { System.out.println("Read error: " + e.getMessage()); } return images; } private void loadImage(Image image) { MediaTracker tracker = new MediaTracker(this); tracker.addImage(image, 0); try { tracker.waitForID(0); } catch(InterruptedException e) { System.out.println("Loading interrupted"); } showLoadingStatus(tracker.statusAll(false)); } private void showLoadingStatus(int status) { String result = ""; if((status & MediaTracker.COMPLETE) == MediaTracker.COMPLETE) result += "COMPLETE"; if((status & MediaTracker.ABORTED) == MediaTracker.ABORTED) result += "ABORTED "; if((status & MediaTracker.ERRORED) == MediaTracker.ERRORED) result += "ERRORED"; System.out.println("Image loading = " + result); } }
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
import statement. diRisig New To Java 2 02-08-2008 02:34 AM
Picture in a JFrame problem saytri New To Java 3 01-12-2008 11:44 AM
Print a picture file oli001 New To Java 0 11-26-2007 03:40 PM
how to import jface in java swt rajaletchumy New To Java 1 08-08-2007 02:31 AM
error with import java.io.* osval New To Java 4 08-06-2007 11:12 PM


All times are GMT +3. The time now is 08:24 AM.


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