Jump to content

Paint in Java!


Recommended Posts

  • 3 weeks later...

Moin Moin,

i hope i'm not too late. :}

Look at this...

public class PetePanel extends JPanel implements Runnable
{
MediaTracker tracker;
Image[] petePics = new Image[6];
Image back;

public PetePanel()
{
setBackground(Color.black);
String[] peteScr = {"right1.gif", "right2.gif", "right3.gif",
"stop.gif" , "blink.gif", "wave.gif"};

Toolkit kit = Toolkit.getDefaultToolkit();

tracker = new MediaTracker(this);
for (int i = 0; i < petePics.length; i++)
{
petePics[i] = kit.getImage(peteScr[i]);
tracker.addImage(petePics[i], i+1);
}
back = kit.getImage("backdrop.gif");
tracker.addImage(back, 0);
}

public void paintComponent(Graphics comp)
{
Graphics2D comp2D = (Graphics2D) comp;
if(back != null)
comp2D.drawImage(back, 0, 0, this);
comp2D.setColor(Color.black);
comp2D.fillRect(0, 30, 450, 30);
if(petePics[current] != null)
comp2D.drawImage(petePics[current], x, y, this);
}
.
.
.
}

in the main or run function call at first
try
{
tracker.waitForAll();
}
catch (InterruptedException ign) {}

Thats it.

cu

Edited by Tim_Tayler
Link to comment
Share on other sites

  • 4 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...