Switch to full style
General Java code examples
Post a reply

Grids in java

Tue Nov 11, 2008 8:53 pm

draw Grids in java graphics
Code:
import java.awt.*;
import java.awt.event.*;

class 
Grids extends Canvas {
  
int widthheightrowscolumns;
 
  
Grids(int wint hint rint c) {
    
setSize(width wheight h);
    
rows r;
    
columns c;
  }
    public 
void paint(Graphics g) {
    
int k;
    
width getSize().width;
    
height getSize().height;

    
int htOfRow height / (rows);
    for (
0rowsk++)
      
g.drawLine(0htOfRow widthhtOfRow );

    
int wdOfRow width / (columns);
    for (
0columnsk++)
      
g.drawLine(k*wdOfRow 0k*wdOfRow height);
  }
}
public class 
DrawGrids extends Frame {
  
DrawGrids(String titleint wint hint rowsint columns) {
    
setTitle(title);
    
Grids grid = new Grids(whrowscolumns);
    
add(grid);
}
public static 
void main(String[] args) {
    new 
DrawGrids("Draw Grids"200200210).setVisible(true);
  }



Attachments
grids.gif
grids in Java
grids.gif (4.7 KiB) Viewed 9649 times

Post a reply
  Related Posts  to : Grids in java
 2d game in java-Monster-Java 2D Game Graphics and Animation     -  
 need help in java     -  
 What is Java API?!!!     -  
 Using FTP in java     -  
 java or .net     -  
 what is java     -  
 Java course     -  
 Help for jprogressbar of java     -  
 How to use Generics in java     -  
 java program     -