자바 프로그램 짠건데요..고수님들 좀 보고 도움좀주세요~
헛나발
클릭할때 press될때 원이 생김과 동시에 그 포인트와 released될때 포인트와 연결시켜서 선을 그리구요 그리고 released때 기억된 그 포인트에 처음같이 원이 생겨야 되는거거든요..
근데 원은 누적해서 계속 생기는데 이 직선이 그릴때 마다 누적되지 않아서요..
화면에 지금까지 그린 직선이 모두 나타나야하거든요..
코드좀 보시고 좀 알려주세요~
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class DotsLinesPanel extends JPanel
{
private final int RADIUS = 6;
private ArrayList pointList;
private ArrayList lineList;
private int count;
private Point point1 = null, point2 = null, point3 = null, point4=null;
public DotsLinesPanel()
{
pointList = new ArrayList();
lineList = new ArrayList();
count = 0;DotsLinesListener listener = new DotsLinesListener();
addMouseListener (listener);
setBackground(Color.white);
}
public void paintComponent (Graphics page)
{
super.paintComponent(page);
page.setColor (Color.orange);
Iterator pointIterator = pointList.iterator();
while ( pointIterator.hasNext())
{
Point drawPoint = (Point)pointIterator.next();
page.fillOval (drawPoint.x - RADIUS, drawPoint.y - RADIUS, RADIUS * 2, RADIUS*2);
}
page.setColor (Color.green);
if(point1 != null && point3 != null)
{
page.drawLine ( point1.x, point1.y, point3.x, point3.y);
}page.setColor (Color.orange);
while ( pointIterator.hasNext())
{
Point drawPoint = (Point)pointIterator.next();
page.fillOval (drawPoint.x - RADIUS, drawPoint.y - RADIUS, RADIUS * 2, RADIUS*2);
}
page.setColor(Color.black);
page.drawString(Count : + count,5,25);
}
private class C0110904_DotsLinesListener implements MouseListener
{
public void mousePressed ( MouseEvent event)
{
point1 = event.getPoint();
pointList.add (point1);
}
public void mouseReleased (MouseEvent event)
{
point3 = event.getPoint();
pointList.add(point3);
count++;
repaint();
}public void mouseClicked (MouseEvent event) {}
public void mouseEntered (MouseEvent event) {}
public void mouseExited (MouseEvent event) {}
}
}
========================================================================
import javax.swing.*;
public class DotsLines extends JApplet
{
private final int WIDTH = 300, HEIGHT = 200;
public void init()
{
getContentPane().add(new DotsLinesPanel());
setSize (WIDTH, HEIGHT);
}
}
직선을 ArrayList에다가 객체로 저장하라는 말을 들은것 같은데..
어떻게 해야할지를 모르겠네요..
부탁드릴께요~
결과로 나와야하는 화면 첨부할께요