java - Abstract class override error -
hello after having puzzeled bit have created following code
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class tri extends randomshape{ public void paintcomponent (graphics g){ // create random variables collor , 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); } } and randomshape code
import java.awt.color; import java.awt.graphics; import java.util.random; /** * * @author huub */ abstract class randomshape { /** color used drawing shape **/ protected color color; /** position of shape (upper left corner) **/ protected int x, y; abstract void draw(graphics g); } however when try , compile gives error tri not abstract , not override abstract method draw in randomshape how fix this
in abstract class have abstract method called draw. class extends abstract class should override method. in case should have implementation draw(graphics g) method inside tri class. otherwise have declare tri class abstract.
hope helps.
Comments
Post a Comment