import java.awt.Graphics;
import javax.swing.JComponent;
public class Cell extends JComponent{
/**
*
*/
private static final long serialVersionUID = 1L;
public Cell(){
}
public Cell(int x, int y){
locX = x;
locY = y;
setLocation(locX, locY);
setSize(50, 50);
}
public void setInsideObject(Object b){
inside = b;
}
public boolean getInside(){
if(inside != null){
return true;
} else{
return false;
}
}
public void paint(Graphics g){
g.drawRect(locX, locY, 50, 50);
}
private Object inside;
private int locX;
private int locY;
}
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class Test {
public Test(){
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("Testing Environment");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
int x, y;
/*for(int i=0; i<10; i++){
x = i*50;
y = 0;
cells[i] = new Cell(x, y);
}*/
Cell cell1 = new Cell(0,0);
Cell cell2 = new Cell(50,0);
Cell cell3 = new Cell(100,0);
cells[0] = cell1;
cells[1] = cell2;
cells[2] = cell3;
for(int i=0; i<3; i++){
frame.getContentPane().add(cells[i]);
}
frame.setVisible(true);
}
public static void main(String args[]){
SwingUtilities.invokeLater(new Runnable(){
public void run(){
new Test();
}
});
}
private Cell[] cells = new Cell[10];
private Grid grid = new Grid();
}

New Topic/Question
Reply




MultiQuote








|