okay, so I have to run a java program that generates a random tetronimo. I have the code for all seven stored inside separate methods. `public class TetrisComponent extends JComponent{
public void paintComponent(Graphics g){ Graphics2D g2 = (Graphics2D)g;
Rectangle2D.Double i = new Rectangle2D.Double(0, 100, 50, 50);
g2.setColor(Color.black);
g2.draw(i);
g2.setColor(Color.CYAN);
g2.fill(i);
Rectangle2D.Double i2 = new Rectangle2D.Double(50, 100, 50, 50);
g2.setColor(Color.black);
g2.draw(i2);
g2.setColor(Color.CYAN);
g2.fill(i2);
Rectangle2D.Double i3 = new Rectangle2D.Double(100, 100, 50, 50);
g2.setColor(Color.black);
g2.draw(i3);
g2.setColor(Color.CYAN);
g2.fill(i3);
Rectangle2D.Double i4 = new Rectangle2D.Double(150, 100, 50, 50);
g2.setColor(Color.black);
g2.draw(i4);
g2.setColor(Color.CYAN);
g2.fill(i4);
}
public void paintComponentj(Graphics g){
Graphics2D g2 = (Graphics2D)g;
Rectangle2D.Double j = new Rectangle2D.Double(200, 500, 50, 50);
g2.setColor(Color.black);
g2.draw(j);
g2.setColor(Color.blue);
g2.fill(j);
Rectangle2D.Double j2 = new Rectangle2D.Double(250, 500, 50, 50);
g2.setColor(Color.black);
g2.draw(j2);
g2.setColor(Color.blue);
g2.fill(j2);
Rectangle2D.Double j3 = new Rectangle2D.Double(300, 500, 50, 50);
g2.setColor(Color.black);
g2.draw(j3);
g2.setColor(Color.blue);
g2.fill(j3);
Rectangle2D.Double j4 = new Rectangle2D.Double(300, 550, 50, 50);
g2.setColor(Color.black);
g2.draw(j4);
g2.setColor(Color.blue);
g2.fill(j4);
}`
so how would i run this program (I have a separate TetrisViewer class) to either run only the painComponent method or painComponentj method, but at random? Is there even a way to do that?
Aucun commentaire:
Enregistrer un commentaire