Results 1 to 2 of 2
- 01-26-2011, 12:25 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 2
- Rep Power
- 0
problem with drawline using arrow key
well, it works fine when i go up and down but when i using left or right arrow key. the all line shift to left or right. can anyone could help me with this?
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class KeyEvents extends JPanel implements MouseMotionListener {
Point p;
int y=100, x=100;
int a = x, b = y;
Graphics g;
public KeyEvents () {
addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_UP: b-=10;
break;
case KeyEvent.VK_DOWN: b+=10;
break;
case KeyEvent.VK_LEFT: a-=10;
break;
case KeyEvent.VK_RIGHT: a+=10;
}
repaint();
}
});
this.addMouseMotionListener(this);
}
public void mouseMoved(MouseEvent e) {
}
public void mouseDragged(MouseEvent e){
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawLine(x, y, a, b);
}
}
Thank You
- 01-26-2011, 01:12 AM #2
Member
- Join Date
- Jan 2011
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Help in bow and arrow game
By sahildave1991 in forum AWT / SwingReplies: 6Last Post: 10-18-2010, 02:34 PM -
hove i create arrow?
By sunolinu in forum Java 2DReplies: 8Last Post: 02-20-2010, 01:20 AM -
drawing ellipse by drawline method?
By hopey in forum Java 2DReplies: 8Last Post: 04-18-2009, 11:52 PM -
Arrow Button Example
By Java Tip in forum SWTReplies: 0Last Post: 07-11-2008, 04:44 PM -
Draw an arrow
By Albert in forum SWT / JFaceReplies: 3Last Post: 02-01-2008, 08:11 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks