Results 1 to 2 of 2
Thread: MouseDragged Event
- 03-03-2008, 07:41 AM #1
Member
- Join Date
- Jan 2008
- Posts
- 83
- Rep Power
- 0
MouseDragged Event
I could able to drag the rectangle..but the initially placed postion was repainted
It remain in the same position..can u help me
Java Code:public class mousedrag extends javax.swing.JApplet { Imagepanel image; @Override public void init() { Container cont = getContentPane(); cont.setLayout(new BorderLayout()); setPreferredSize(new Dimension(300, 300)); JScrollPane scroll = new JScrollPane(); getContentPane().add(scroll, BorderLayout.CENTER); scroll.getViewport().add(new Imagepanel()); } private class Imagepanel extends JPanel implements MouseListener,MouseMotionListener{ public Imagepanel() { panel(); addMouseMotionListener(this); addMouseListener(this); } protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //MouseEvent e1 = this.e; //g2.setColor(getBackground()); //g2.fillRect(0, 0, getWidth(), getHeight()); //g2.setColor(getForeground()); g2.setColor(getBackground()); g2.fillRect(0, 0, getWidth(), getHeight()); g2.setColor(getForeground()); drawdig(g2); drawCalendar(g2); } public void drawdig(Graphics g) { Graphics2D g2 = (Graphics2D)g; g2.setPaint(new Color(0,157,250)); System.out.println(rectangles.size()+"SIZE"); for(Rectangle ret : rectangles) { g2.draw(ret); g2.fill(ret); } public void mouseDragged(MouseEvent e) { Point p = e.getPoint(); Rectangle[] r = rectangles.toArray(new Rectangle[rectangles.size()]); for(int i=0, j = rectangles.size(); i<j ; i++) { Point lastP = (Point)lastPos.get(r[i]); if(r[i].contains(p)) { r[i].translate(e.getX(), e.getY()); this.repaint(); } lastPos.put(r[i], p); } public void mouseMoved(MouseEvent e) { lastPos.clear(); } }
- 03-04-2008, 05:09 AM #2
Member
- Join Date
- Jan 2008
- Posts
- 83
- Rep Power
- 0
Similar Threads
-
Event
By nt5515 in forum New To JavaReplies: 0Last Post: 02-15-2008, 04:44 PM -
Listener for SWT event
By Java Tip in forum Java TipReplies: 0Last Post: 01-08-2008, 09:04 AM -
key pressed event
By kavithas in forum New To JavaReplies: 7Last Post: 12-10-2007, 02:01 PM -
Need help with JButton event
By adlb1300 in forum New To JavaReplies: 2Last Post: 11-19-2007, 01:15 AM -
Event Handling
By luisarca in forum Sun Java Wireless ToolkitReplies: 5Last Post: 05-07-2007, 06:05 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks