Java graphics


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Java graphics

  1. #1
    Join Date
    Aug 2004
    Posts
    2

    Question Java graphics

    I have created a chess board and menus on top. When I click on one of the menu items it erases part of the board, and when I minimize the window the board disappears. I thought that repaint() function would work but it doesn't. Anyone knows how to solve this problem?

    Thank you.

  2. #2
    Join Date
    Aug 2004
    Posts
    2

    Question Java Graphics

    This is the code:

    public void paint(Graphics g)
    {
    super.paint(g);

    int l = 1;
    l++;
    System.out.println("This is a test " + l);
    l++;

    //Draw 64 squares with filled brown and white colors
    for(int i=1; i<=64; i++)
    {
    if((i>=1 && i<=8)||(i>=17 && i<=24) || (i>=33 && i<=40)||(i>=49 && i<=56))
    {
    //Ranks 2,4,6,8.
    if(i%2 ==0)
    g.setColor(new Color(150,0,0));
    else
    g.setColor(Color.white);
    }
    else
    //Ranks 1,3,5,7.
    if(i%2==0)
    g.setColor(Color.white);
    else
    g.setColor(new Color(150,0,0));

    if(i%8!=0)
    {
    g.fillRect(x,y,SQRSWIDTH,SQRSHEIGHT);
    x = x+50;
    }
    else
    {
    g.fillRect(x,y,SQRSWIDTH,SQRSHEIGHT);
    x = 50;
    y = y+50;
    }
    }
    //draw the letters and numbers
    g.setFont(new Font("Arial",Font.PLAIN,16));
    g.setColor(Color.blue);
    //Create for loop to draw the letters and numbers
    for(int i=8; i>=1; i--)
    {
    g.drawString(Integer.toString(i),30,yloc);
    yloc+= 50;
    g.drawString(""+((char)ascii),xloc,490);
    xloc+=50;
    ascii++;
    int k=1;
    System.out.println("draw numbers " + ++k);

    }//end of for loop
    System.out.println("end of paint method ");

    }//end of paint method

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