Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] using graphics

Started by pcvsee Oct 24, 2000 at 7:58 PM 0 replies 300+ views
Original Post
pcvsee
pcvsee
i relatively new to java and i''m studying how to use the graphics class. i''ve read in many online books that using graphics in java requires you to use it in applets. is it possible to use it (for game programming) in a standalone java application? if it''s possible can you guys explain it to me or give a website that can explain it? thanks a lot
Smoo
Smoo
Ok well if the books you''ve read says that you can only use graphics in applets, well you misread

The thing with applets is that you create a size in your webpage and that is your canvas to load/manipulate images, text, etc..

A standalone application you would need a few things.

class MyCanvas extends canvas
{
Toolkit t1;
MediaTracker mt;
Image background;

public void init()
{
t1 = Toolkit.getDefaultToolkit();
mt = new MediaTracker(this);
image = t1.getImage("bkground.jpg");
mt.addImage(image, 0);

try
{
mt.waitForAll();
{
catch (InterruptedException e) {};

repaint();
}

public void paint(Graphics g)
{
g.drawImage(image, 0, 0, this);
}

}

Now you''d need another class to extend Frame and you''d have to add a main() to load up the app and add the MyCanvas in it.

The mediatracker is basically to preload the images into memory before you display them.

Well good luck with the rest,
Smoo

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.