-
Drawing
Hey rigth now im in the process of learning the draw functions and I would like to make it so that the screen doesnt clear itself each time I draw, Here part of my code doing the drawing and stuff.
public void keyPressed( KeyEvent e ) { }
public void keyReleased( KeyEvent e ) { }
public void keyTyped( KeyEvent e ) {
char c = e.getKeyChar();
if ( c == 127) {
//s = s - 1;
}
if ( c != KeyEvent.CHAR_UNDEFINED && c != 127 && c != 50 && c != 52 && c != 54 && c != 56) {
paintNum = 1;
s = s + c;
repaint();
e.consume();
}
if (c == 50) {
paintNum = 2;
repaint();
e.consume();
}
if (c == 52) {
paintNum = 2;
repaint();
e.consume();
}
if (c == 54) {
paintNum = 2;
repaint();
e.consume();
}
if (c == 56) {
paintNum = 2;
repaint();
e.consume();
}
}
public void paint( Graphics g ) {
if (paintNum == 1) {
g.setColor( Color.gray );
g.drawLine( x, y, x, y-10 );
g.drawLine( x, y, x+10, y );
g.setColor( Color.green );
g.drawString( s, 10, 17 );
paintNum = 0;
}
if (paintNum == 2) {
g.drawImage(logo,0,0,this);
paintNum = 0;
}
If you can help I thank you very much!
-
Leave out the repaint() methods and then the screen shouldn't refresh. also , you have a nested statement that only has a comment in it, but i dont know if that was on purpose or not.
www.saterasoft.cjb.net
Come and play the games.....
-
also, setting the panel that you are drawing on, to setDoubleBuffered(true) will remove on-draw flickering of the graphics
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|