Creating a color-changing grid applet in Java -


for school project, need create applet produces 10 x 10 grid in each cell change color in accordance threads doing in background. have of rest figured out, don't have slightest clue how display grid. example code given:

import java.awt.*; import java.applet.applet;  public class array2 extends applet {   private final ststic int limit = 9;   private int[][] results;    public void init() {     int count = 1;     results = new int [limit][limit];      (int = 0; < limit; i++) {       (int j = 0; j < limit; j++) {         results[i][j] = count % 2;         count++;       }     }   }    public void paint (graphics g) {     int xloc = 25;     int yloc = 25;      (int = 0; < limit; i++) {       (int j = 0; j < limit; j++) {         g.drawstring(integer.tostring(results[i][j]), xloc. yloc);         xloc += 20;       }       xloc = 25;       yloc += 20;     }   } } 

this ends printing blank 2 x 2 grid. easy enough modify 10 x 10. however, don't know how color squares. i've searched mentions using jpanels or jframes or something, has applet. looking suggestions should coloring process, literally have go on.thanks!

the applet draws class graphics , passes instance in paint method. can use graphics many cool things on screen, check methods out! draw colored square, first set color using g.setcolor(color) , use g.fillrect(xloc, yloc, size, size) xloc , yloc being top-left coordinates of square.


Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -