初心者です。 コンパイルのエラー
import java.awt.*;
import javax.swing.*;
public class R11Sample1 extends JFrame {
Rect r1 = new Rect(Color.red, 100, 100, 80, 60);
Rect r2 = new Rect(new Color (0.5f, 1f, 0f, 0.7f), 150, 120, 60, 90);
Oval = new Oval(Color.blue, 60, 50, 10, 10);
JPanel panel = new JPanel() {
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
r1.draw(g2); r2.draw(g2);
}
};
public R11Sample1() {
setSize(400, 350); setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().add(panel);
}
public static void main(String[] args) { new R11Sample1().setVisible
(true); }
}
class Rect {
Paint pat;
int xpos, ypos, width, height;
public Rect(Paint p, int x, int y, int w, int h) {
pat = p; xpos = x; ypos = y; width = w; height = h;
}
public void draw(Graphics2D g) {
g.setPaint(pat);
g.fillRect(xpos-width/2, ypos-height/2, width, height);
}
}
class Oval {
Paint pat;
int xpos, ypos, radius;
public Oval(Paint p, int x, int y, int width, int height) {
pat = p; xpos = x; ypos = y; width = w; height = h;
}
public void draw(Graphics2D g) {
g.setPaint(pat);
g.fillOval(xpos-width/2, ypos-height/2, width, height);
}
}
これでコンパイルすると、
Identifierがありません
といわれました。
どこを直せばいいのでしょうか。
また、全体的に間違ったところがあったら教えてください。
お礼
sussakun様、早々のご返事ありがとうございます! 「中央の座標を求める部分」はこういうふうになるのですね。 できるだけASの意味を考えながら一字一字入力してみました。 ちゃんと動作しました! 素晴らしいです!!! どうしてこれだけの長いASをスラスラ書けるのか、感激の一言です。 ASは本当に難しいですね・・・。 もしよろしければ、初心者がすんなり入れるASの本をご紹介いただけませんか? 思ったとおりに動作してとても嬉しいです!本当にありがとうございました!
補足
思ったとおりに動作できたので実質上回答は締め切らせていただきます。 sassakun様がASの本をご紹介くださるかもしれないので、入力ができるように2~3日はこのままの状態にしておき、その後、ポイント入力と締め切りをさせていただきます。