Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loading and Displaying Images
#1
This is the source code for my Java tutorial discussing how to load and display images in a Java applet.

Here's the video:
<!-- m --><a class="postlink" href="http://www.youtube.com/watch?v=oXmUp4ZTW2Q">http://www.youtube.com/watch?v=oXmUp4ZTW2Q</a><!-- m -->

Source code:
[code2=java]import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.net.URL;

public class ImageLoadingTutorial extends Applet
{

private Image spiral = null;

public void paint(Graphics g)
{
this.setSize(640, 480);

if (spiral == null)
spiral = getImage("spiral.png");

Graphics2D g2 = (Graphics2D)g;
g2.drawImage(spiral, 25, 50, 25, 25, this);
}


public Image getImage(String path)
{
Image tempImage = null;
try
{
URL imageURL = ImageLoadingTutorial.class.getResource(path);
tempImage = Toolkit.getDefaultToolkit().getImage(imageURL);
}
catch (Exception e)
{
System.out.println("An error occured - " + e.getMessage());
}
return tempImage;
}

}[/code2]

Pastebin link: <!-- m --><a class="postlink" href="http://pastebin.com/sdBqqdxK">http://pastebin.com/sdBqqdxK</a><!-- m -->
My Blog | My Setup | My Videos | Have a wonderful day.


Messages In This Thread
Loading and Displaying Images - by brandonio21_phpbb3_import2 - 03-21-2013, 03:44 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)