자바초급자예요ㅠㅠ도와주세요ㅠㅠ
쇼코홀릭
Shape 클래스를 상속받아서 Triangle과 DrawableTriangle 그리고 Drawable 인터페이스를 작성해서 프로그램을 짜는건데요
DrawableTriangle 에서 에러가 나네요 도와주세요ㅠㅠ
Shape.java
public abstract class Shape {
protected int x, y;
public abstract double area();
public abstract double circumference();
public void move(int x1, int y1){
x += x1;
y += y1;
}
}
Drawable.java
import java.awt.Graphics;
interface Drawable{
void paint(Graphics g);
}
Triangle.java
public class Triangle extends Shape{
protected int width, height;
public Triangle(){
this(0,0);
}
public Triangle(int w, int h){
width = w;
height = h;
}
public double circumference(){
return 2*Math.sqrt(width/2*width/2 + height*height)*height;
}
public double area(){
return (width*height)/2;
}
public int getWidth(){
return width;
}
public int getHeight(){
return height;
}
public void setSize(int w, int h){
width = w;
height = h;
}
}
DrawableTriangle.java
import java.awt.*;
public class DrawableTriangle extends Triangle implements Drawable{
public DrawableTriangle(){
this(0,0,0,0);
}
public DrawableTriangle(int x, int y, int w, int h){
super(w, h);
this.x = x;
this.y = y;
}
public void paint(Graphics g){
g.drawTriangle(x, y, width, height);
g.drawString(Stirng.valueOf(area()), x-width/2, y+height/2); ---이부분이 에러가나요ㅠㅠ
}
}
DrawingFrame
import java.awt.*;
import javax.swing.*;
public class DrawingFrame extends JFrame {
protected Drawable drawable[];
public DrawingFrame(){
super(그림판);
drawable = new Drawable[3];
drawable[0] = new DrawableCircle(65, 75, 30);
drawable[1] = new DrawableRect(125, 125, 70, 65);
drawable[2] = new DrawableCircle(230,100,60);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(400,300);
setVisible(true);
}
public void paint(Graphics g){
int n = drawable.length;
for(int i=0; in; i++){
drawable[i].paint(g);
}
}
public static void main(String args[]){
new DrawingFrame();
}
}
-
치에미
빨간줄만 에러나는게 맞죠?
Stirng로 바꾸세요 오타입니다
다른 부분은 소스가 누락되서 모르겠네요