여기 프로그래밍 총 초보자인데, 방과후에 자바를 배우려고합니다. 간단한 것들을 만들고 GUI를보고 그래픽을 사용하여 도형을 그리기 시작했습니다. 나는 주로 여기에 게시 된 답변의 자습서와 힙을 따라 왔습니다.클래스에서 애플릿으로 도형을 그리는 방법은 무엇입니까?
내 Draw 클래스의 도형을 DrawTest 애플릿에 그리는 데 문제가 있습니다.
import java.awt.*;
import java.applet.*;
import javax.swing.*;
public class DrawTest extends Applet
{
Draw circle = new Draw();
public void init()
{
Panel mainPanel = new Panel();
mainPanel.setLayout(new GridLayout(0,2)); //a left and right panel
JPanel drawPanel = new JPanel(); //left panel to draw shapes into
drawPanel.setBackground(Color.BLACK);
JLabel headerLabel = new JLabel("Draw shapes from another class");
headerLabel.setForeground(Color.GREEN);
drawPanel.add(headerLabel);
drawPanel.add(circle);
circle.drawing();
JPanel textPanel = new JPanel(); //right panel for text
TextArea output = new TextArea("Circle and oval");
textPanel.add(output);
mainPanel.add(drawPanel);
mainPanel.add(textPanel);
add(mainPanel);
}
}
아래 그리고 그리기 클래스 어떤 포인터에 미리
import java.awt.*;
import java.awt.Graphics;
import java.awt.Color;
import javax.swing.*;
public class Draw extends JPanel
{
public void drawing()
{
repaint();
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.setColor(Color.BLUE);
// a circle (int x, int y, int width, int height,int startAngle, int arcAngle);
g.fillArc(20,20,50,50,0,360);
//this will draw a oval of width 60 & height 40 at (10,30)
g.setColor(Color.RED);
g.drawOval(10,30,60,40);
}
}
감사로.
당신이 '문제 도형 그리기'는 무엇을 의미하는 확장하십시오 - 당신은 무엇을 일어날 기대하고 무슨 일입니까? –
약간 막연해서 죄송합니다. 왼쪽 패널에는 채워진 원과 채워지지 않은 타원이 있어야합니다. 현재 alex2410이 보여주는 것처럼 나는 아무것도 얻지 못합니다. – elk266
답변을 변경했습니다. – alex2410