基本上我需要爲學校做這件事,我已經通過各種關於這個的帖子,每個人都只是說「你爲什麼要這麼做?」並不回答。所以很多人需要這方面的幫助,你的答案可能會得到很多喜歡有一天如何從本身運行JApplet?
所以這裏是我的班級 - 我需要添加幾行代碼,以便使此JApplet
彈出並繪製磚塊進入JApplet
窗口?
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();
}
}
'main()'是Java **應用程序**的入口點。見http://www.oracle.com/technetwork/java/applet-137165.html –
*「每個人都只是說」你想做什麼?「而不回答。」*我通常會爲此添加評論等到提問的人提供了我的問題的答案!所以......你已經回答了「老師」這個問題,所以請按照我在評論中提出的建議去做,並且讓老師知道[爲什麼CS老師應該停止**教授Java小程序](http://程序員。 blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/)。認真。他們的教學小程序不過是疏忽而已。 –