一個java的問題什麼是 else without if
作者: sagat (SAGAT) 站內: Talk
標題: 一個java的問題什麼是 else without if
時間: Thu Jan 10 19:33:01 2008
以下是自己的寫的java程式
也是明天的期末考
到目前為止就只有一個地方一直不會
他總會跟我說
else without if
而錯誤的地方已經在下面標示出來
那要如何更改呢
課本我看不懂〒△〒
我是用bluej寫的
謝謝
//*********************** ex001.java **********************
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ex001 extends JApplet implements ActionListener
{
private Timer timer;
private int n=0, d=100;
public void init()
{
setSize(300, 300);
setVisible(true);
}
public void start()
{
timer = new Timer(0, this);
timer.start();
}
public void paint(Graphics g)
{
int w = getSize().width;
int h = getSize().height;
g.setColor(Color.white);
g.fillRect(0,0, w-1,h-1);
n++;
if (n%2==1)
{
g.setColor(Color.green);
g.fillOval(w/2-d/2, h/2-d/2, d,d);
timer.stop();
timer = new Timer(5000, this);
timer.start();
}
else
{
g.setColor(Color.yellow);
g.fillOval(w/2-d/2, h/2-d/2, d,d);
timer.stop();
timer = new Timer(5000, this);
timer.start();
}
else <這個
{
g.setColor(Color.red);
g.fillOval(w/2-d/2, h/2-d/2, d,d);
timer.stop();
timer = new Timer(5000, this);
timer.start();
}
else <還有這個
{
g.setColor(Color.yellow);
g.fillOval(w/2-d/2, h/2-d/2, d,d);
timer.stop();
timer = new Timer(2000, this);
timer.start();
}
}
public void actionPerformed(ActionEvent e)
{
repaint();
}
}
--
旅行才是目的,騎車只是手段。
http://www.wretch.cc/album/csit92
http://photo.xuite.net/csit92
--
╭┼ Origin: 玩車人的天地 ˙東吳機研站 scumotor.com.tw
┼╯ Author: sagat 從 122-122-7-66.dynamic.hinet.net 發表
→ Roderick 推:......請告訴我你為什麼會這樣寫 = =" 08/01/10
→ Roderick 推:喔~對不起,眼殘…請將所有錯誤的 else 改 else if 08/01/10
→ sagat 推:謝謝 不過結果還是一樣 08/01/10
→ sagat 推:bluej是有提示說好像不能有一個以上的else 08/01/10
→ sagat 推:看不懂英文大概猜一下的 08/01/10
→ Andy 推:表示你有一個else沒有if的條件 08/01/10