Find us on Google+ Kill the code: Draw Table with required rows and cols in JAVA

Thursday, 8 March 2012

Draw Table with required rows and cols in JAVA



import java.awt.*;
import java.applet.*;
import java.awt.event.*;


/*
<applet code="mousemotion" width=400 height=400>
</applet>
*/


public class mousemotion extends Applet implements MouseMotionListener,MouseListener {
String name="NISARG";
//String dim=" ";
int mx,my,mx2,my2,mx1,my1,mx3,my3;
int reles=0,dragged=0,drg_reles=0,rls_aftr_drg=0,clr_screen=0;
int ROW=12;
int COLOUM=12;



public void init() {
addMouseMotionListener(this);
addMouseListener(this);
}
public void mouseClicked(MouseEvent me) {
showStatus("MOUSE CLICKED.");
clr_screen=1;
repaint();
}
public void mousePressed(MouseEvent me) {
mx1=me.getX();
my1=me.getY();
}
public void mouseEntered(MouseEvent me) {
showStatus("SHOW STATUS.");
}
public void mouseReleased(MouseEvent me) {
if(dragged==1) {
drg_reles=1;
}
mx2=me.getX();
my2=me.getY();
dragged=0;
reles=1;
repaint();
}
public void mouseExited(MouseEvent me) {
showStatus("MOUSE EXITED.");
}
public void mouseDragged(MouseEvent me) {
showStatus("Mouse is at "+me.getX()+" "+me.getY());
mx3=me.getX();
my3=me.getY();
rls_aftr_drg=1;
//drg_reles=1;
dragged=1;
repaint();
}
public void mouseMoved(MouseEvent me) {
showStatus("Mouse is at "+me.getX()+" "+me.getY());
}
public void paint(Graphics g) {
if(clr_screen==1) {
clr_screen=0;
}
else if(reles==1 && dragged==1) { //MOUSE RELEASED.
g.drawLine(mx1,my1,mx2,my1);
g.drawLine(mx1,my1,mx1,my2);
g.drawLine(mx1,my2,mx2,my2);
g.drawLine(mx2,my1,mx2,my2);
int ROW11=(my3-my1)/ROW;
int ROW111=ROW11;
ROW11+=my1;
int COLOUM11=(mx3-mx1)/COLOUM;
int COLOUM111=COLOUM11;
COLOUM11+=mx1;
for(int i=0;i<ROW;i++) {
g.drawLine(mx1,ROW11,mx3,ROW11);
ROW11+=ROW111;

}
//g.drawLine(mx1,ROW11,mx3,ROW11);
for(int j=0;j<COLOUM;j++) {
g.drawLine(COLOUM11,my1,COLOUM11,my3);
COLOUM11+=COLOUM111;
}
reles=0;
}
else if(rls_aftr_drg==1) { //MOUSE DRAGGED.
g.drawLine(mx1,my1,mx3,my1);
g.drawLine(mx1,my1,mx1,my3);
g.drawLine(mx1,my3,mx3,my3);
g.drawLine(mx3,my1,mx3,my3);
int ROW11=(my3-my1)/ROW;
int ROW111=ROW11;
ROW11+=my1;
int COLOUM11=(mx3-mx1)/COLOUM;
int COLOUM111=COLOUM11;
COLOUM11+=mx1;
for(int i=0;i<ROW;i++) {
g.drawLine(mx1,ROW11,mx3,ROW11);
ROW11+=ROW111;

}
for(int j=0;j<COLOUM;j++) {
g.drawLine(COLOUM11,my1,COLOUM11,my3);
COLOUM11+=COLOUM111;
}
dragged=0;
//rls_aftr_drg=0;
}
if(drg_reles==1) { //MOUSE RELEASED.
g.drawLine(mx1,my1,mx2,my1);
g.drawLine(mx1,my1,mx1,my2);
g.drawLine(mx1,my2,mx2,my2);
g.drawLine(mx2,my1,mx2,my2);
int ROW11=(my3-my1)/ROW;
int ROW111=ROW11;
ROW11+=my1;
int COLOUM11=(mx3-mx1)/COLOUM;
int COLOUM111=COLOUM11;
COLOUM11+=mx1;
for(int i=0;i<ROW;i++) {
g.drawLine(mx1,ROW11,mx3,ROW11);
ROW11+=ROW111;

}
for(int j=0;j<COLOUM;j++) {
g.drawLine(COLOUM11,my1,COLOUM11,my3);
COLOUM11+=COLOUM111;
}
drg_reles=0;
}
}
}

No comments:

Post a Comment