Win a copy of Rust Web Development this week in the Other Languages forum!

Jonathan Sternberg

Greenhorn
+ Follow
since Jun 03, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jonathan Sternberg

I'm just trying to get the basic layout to my game ready and then I'm going to work on other stuff. I'm trying to create a working world map first. First of all, I just want to get this main class working and I'm not sure why it isn't doing what I want it to.


When I press Q it should quit but it doesn't work. I looked at Java Sun and I couldn't find out why it wouldn't work.

Also how would I program a sprite to move around and go through an animation when he's walking? I know how to make it move around, just not how to have an animation. I was thinking of creating a new action like QuitAction that would move the character and change the animation but I'm not sure how I'd program that.
16 years ago
Oh sorry, I'll do that then.

And my teacher showed me today how to get rid of the afterimage too and it was really simple. I don't think I'm creating anything complicated enough to need double buffering, yet.
16 years ago
Okay I've got questions about Graphics and will probably have more coming as I learn more about graphics. Well currently I was told to do all of my graphics painting in paint(Graphics g). So I create this:



That's for keylistener and calling repaint to change the position of the image. This is for paint(Graphics g).



Now it works, but how do I get rid of the afterimage? And am I doing everything right?

And this is cool. I didn't know this site supported UBB Code otherwise I would've used the code tags in my last topic.
16 years ago
The ImageIcon was the problem??? 0_o

Well the g = getGraphics() works after you call setVisible(true) (I tested this, it doesn't work otherwise) but I'm just beginning graphics. I'll check out what this paintComponent thing is on java sun.
16 years ago
I've been trying to use graphics for this game I'm making with some friends in Java. My friend had already used graphics for a smaller game he made for a project in our computer programming class. So I asked him to send me the thing he made that worked. This is trying to draw ImageIcons on a JLabel. But I keep getting this error that my friend didn't. Note that I'm using the newest version of Eclipse to write this and he used Codewarrior JDK 1.4.

public class KeyImage extends JFrame implements ImageObserver, KeyListener {

private static Container contentPane;

private static Graphics g;
static int xLoc;
static int yLoc;
static JLabel label;

public KeyImage() {
super();

setSize(400,400);
contentPane=getContentPane();

this.setVisible(true);
xLoc=200;
yLoc=200;
g=contentPane.getGraphics();

label = new JLabel();

addKeyListener(this);
contentPane.add(label);
}
/* (non-Javadoc)
* @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
*/
public boolean imageUpdate(Image arg0, int arg1, int arg2, int arg3,
int arg4, int arg5) {
// TODO Auto-generated method stub
return false;
}

/* (non-Javadoc)
* @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
*/
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub

}

/* (non-Javadoc)
* @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
*/
public void keyPressed(KeyEvent arg0) {
// TODO Auto-generated method stub

}

/* (non-Javadoc)
* @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
*/
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub

}

public static void main(String[] args) {
KeyImage c = new KeyImage();
c.setVisible(true);
String filepath = new String("~/Documents/eclipse/");
ImageIcon icon = new ImageIcon(filepath+"eirika.gif");
g.drawImage(icon,xLoc,yLoc,c);
}
}

eirika.gif is just the image I'm using (I took one from one of the games I like) and the error always comes from the end and it says that drawImage needs an Image, int, int, and ImageObserver. But c (KeyImage) implements ImageObserver. I'm stuck and have no clue what's going on.
16 years ago