Basically I need to do this for school, Ive been through all kinds of posts about this and everyone just says "why'd you wanna do that?" and don't answer. So a lot of people need help on this and your answer could get a lot of likes someday
So here's my class - what couple lines of code do i need to add to main to make this JApplet
pop up and draw the bricks into a JApplet
window?
public class Wall extends JApplet {
ArrayList<Brick> bricks = new ArrayList<Brick>();
Color[] colors = {Color.decode("#1abc9c"), Color.decode("#f1c40f"), Color.decode("#d35400"), Color.decode("#e74c3c"), Color.decode("#2ecc71"), Color.decode("#3498db"), Color.decode("#9b59b6"), Color.decode("#34495e")};
ArrayList<Integer> usedInts = new ArrayList<Integer>();
public void makeBricks(){
int xPos = 20;
int yPos = 50;
int height = 50;
int width = 60;
for(int i=0; i<8;i++){
Brick b = new Brick();
b.setxPosition(xPos);
xPos =+60;
b.setyPosition(yPos);
if (xPos == 200){
yPos+=50;
}
b.setColor(randomColor());
b.setHeight(height);
b.setWidth(width);
bricks.add(b);
}
}
public Color randomColor(){
Random r = new Random(System.currentTimeMillis());
boolean allAssigned = false;
while(!allAssigned){
int newInt = r.nextInt(8);
if(!usedInts.contains(newInt)){
usedInts.add(newInt);
return colors[newInt];
}
if(usedInts.size()>7){
usedInts.clear();
}
}
return Color.BLACK;
}
public void draw(Graphics g) {
for(Brick b: bricks){
b.draw(g);
}
}
@Override
public void paint(Graphics g){
draw(g);
}
public static void main(String[] args) {
//these lines do not work
Wall wall = new Wall();
wall.makeBricks();
wall.draw();
}
}