그래서 응용 프로그램을 만들고 화면에 추가 된 모양을 추적하고 싶습니다. 지금까지 다음 코드를 가지고 있지만 원이 추가되면 이동/변경할 수 없습니다. 이상적으로는 Shift-click과 같은 것을 사용하여 주위를 이동하거나 강조 표시 할 수 있습니다.자바 그래픽 - 모양 추적
나는 한 원에서 다른 원으로 선을 끌 수 있도록 어떻게 만들 수 있는지 궁금합니다. 나는 여기에 일을 위해 잘못된 도구를 사용하고 있는지 모르지만 어떤 도움을 주시면 감사하겠습니다.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MappingApp extends JFrame implements MouseListener {
private int x=50; // leftmost pixel in circle has this x-coordinate
private int y=50; // topmost pixel in circle has this y-coordinate
public MappingApp() {
setSize(800,800);
setLocation(100,100);
addMouseListener(this);
setVisible(true);
}
// paint is called automatically when program begins, when window is
// refreshed and when repaint() is invoked
public void paint(Graphics g) {
g.setColor(Color.yellow);
g.fillOval(x,y,100,100);
}
// The next 4 methods must be defined, but you won't use them.
public void mouseReleased(MouseEvent e) { }
public void mouseEntered(MouseEvent e) { }
public void mouseExited(MouseEvent e) { }
public void mousePressed(MouseEvent e) { }
public void mouseClicked(MouseEvent e) {
x = e.getX(); // x-coordinate of the mouse click
y = e.getY(); // y-coordinate of the mouse click
repaint(); //calls paint()
}
public static void main(String argv[]) {
DrawCircle c = new DrawCircle();
}
}
graphics.draw (타원); 나에게 오류를 준다 ... – Tim
그래픽은 pseudo이다. 나는 당신이 사용하고있는 그래픽 객체를 언급하고있다. 가지고있는 예제는 'g'를 참조로 사용합니다. 셰이프로 페인팅하려면 g.draw() – Nikki
+1을 사용해보세요. 그러나 Graphics 클래스는 도형을 그리는 방법을 알지 못합니다. 'Graphics2D' 클래스를 사용할 필요가 있습니다. 또한'fill()'메소드를 사용해야한다. draw() 메서드는 Shape의 외곽선을 그립니다. 자세한 내용은 [모양으로 재생] (http://tips4java.wordpress.com/2013/05/13/playing-with-shapes/)을 참조하십시오. – camickr