Results 1 to 1 of 1
Thread: drow point
- 05-05-2011, 08:20 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 8
- Rep Power
- 0
drow point
Hello
You draw a set of points using JavaScript using a mouse click, but I want to
Modify the program so that if you drag a point to a new location and delete the previous draw
The new code is stored coordinates the drawing by clicking correctly and works, but I do not know change the site you can help
XML Code:import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.awt.geom.*; import java.util.ArrayList; public class TestPanelDrawing2 extends JPanel implements MouseListener ,MouseMotionListener{ static int i; static int x; static int y; static ArrayList<Ellipse2D.Double> vert = new ArrayList<Ellipse2D.Double>(); static ArrayList<Integer> xCoordinate = new ArrayList<Integer>(); static ArrayList<Integer> yCoordinate = new ArrayList<Integer>(); ///to find which node is move public static int serch_inArray(int x,int y){ for(int i=0;i<vert.size();i++){ // if(x>=) if(vert.get(i).getX()<=x+25&&vert.get(i).getX()>=x-25&&vert.get(i).getY()<=x+25&&vert.get(i).getY()>=x-25) return i; } return -1; } public void mouseDragged(MouseEvent e) { // System.out.println (x); //x=e.getX(); //y=e.getY(); //i=serch_inArray(x,y); // System.out.println (i); } public void mouseMoved (MouseEvent e) { } @Override public void mouseClicked(MouseEvent e) { x = e.getX(); y = e.getY(); drawNode(); } @Override public void mouseEntered(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { // x=e.getX(); // y=e.getY(); // i=serch_inArray(x,y); } @Override public void mouseReleased(MouseEvent e) { //x = e.getX(); // y = e.getY(); // System.out.println (i); //vert.set(i,new Ellipse2D.Double(x, y, 15, 15)); // drawNode(); } @Override public void mouseExited(MouseEvent e) { } public TestPanelDrawing2() { addMouseListener(this); } public void drawNode() { Graphics g = getGraphics(); Graphics2D g2 = (Graphics2D) g; int x1 = TestPanelDrawing2.x; int y1 = TestPanelDrawing2.y; Ellipse2D.Double a = new Ellipse2D.Double(x1 + 5, y1, 15, 15); TestPanelDrawing2.vert.add(a); for (int i = 0; i < vert.size(); i++) { Ellipse2D.Double d = vert.get(i); g2.draw(d); g.drawString((char) (65 + i) + "", (int) (d.x + 5), (int) d.y); g2.fill(new Ellipse2D.Double(d.x, d.y, 15, 15)); } } public static void main(String[] args) { TestPanelDrawing2 p = new TestPanelDrawing2(); JFrame frame = new JFrame(); frame.add(p); frame.setTitle("TestPanelDrawing"); frame.setLocationRelativeTo(null); // Center the frame frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(600, 400); frame.setVisible(true); } }
Similar Threads
-
What is the point of Interfaces?
By minime12358 in forum New To JavaReplies: 9Last Post: 09-02-2010, 03:24 PM -
looking for Point interpolater
By gib65 in forum AWT / SwingReplies: 5Last Post: 08-20-2010, 05:22 PM -
Access Point
By ja107 in forum NetworkingReplies: 0Last Post: 03-05-2010, 06:59 PM -
Can someone point me to an example?
By smhjr in forum New To JavaReplies: 2Last Post: 08-28-2009, 12:38 AM
Bookmarks