Drawing


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Drawing

  1. #1
    Join Date
    Mar 2004
    Posts
    1

    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!

  2. #2
    Join Date
    Feb 2004
    Posts
    34
    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.....

  3. #3
    Join Date
    Feb 2004
    Posts
    808
    also, setting the panel that you are drawing on, to setDoubleBuffered(true) will remove on-draw flickering of the graphics
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center