你好後已經puzzeled一點我已經創建了下面的代碼抽象類重寫錯誤
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Tri extends RandomShape{
public void paintComponent (Graphics g){
// create random variables for collor and shape of triangle
int x;
int y;
int x2;
int y2;
x = (int) Math.random()*100;
y = (int) Math.random()*100;
x2 = (int) Math.random()*100;
y2 = (int) Math.random()*100;
int r1;
int g1;
int b1;
r1 = (int) Math.random()*255;
g1 = (int) Math.random()*255;
b1 = (int) Math.random()*255;
Color color = new Color(r1,g1,b1);
//draw triangle
g.setColor(color);
g.drawLine(x,y,y2,y);
g.setColor(color);
g.drawLine(x,y,y2,y2);
g.setColor(color);
g.drawLine(y2,y,y2,y2);
}
}
和我randomshape代碼
import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;
/**
*
* @author huub
*/
abstract class RandomShape {
/** color used for drawing this shape **/
protected Color color;
/** position of the shape (upper left corner) **/
protected int x, y;
abstract void draw(Graphics g);
}
然而,當我嘗試編譯它給了一個錯誤,三是不抽象,也不重寫抽象方法在Randomshape中的繪製我該如何解決這個問題
你知道什麼是'在方法的背景下abstract'手段,班? –
_how我可以修復this_錯誤很明顯。重寫'Tri'類中的'draw'方法。 – BackSlash
錯誤信息告訴你**完全**有什麼問題。有時間打開你的教科書並閱讀抽象類! –