Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-07-2008, 11:57 AM
Member
 
Join Date: Jan 2008
Posts: 78
Preethi is on a distinguished road
Mouse dragg not working
Quote:
i tried to drag my rectangle..But my code is not working....
can anyone help me please...
Code:
import javax.swing.*; import java.awt.*; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.event.*; import java.awt.font.FontRenderContext; public class Mousedragg extends javax.swing.JApplet { 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 { Imagepanel image; JScrollPane scroll = new JScrollPane(); boolean selected= false; boolean selected1= false; private boolean canDrag = false; int x,y,w,h; Rectangle r = new Rectangle(x,y,w,h); Imagepanel() { setPreferredSize(new Dimension(32910, 32710)); scroll = new JScrollPane(); add(scroll); addMouseListener(this); addMouseMotionListener(this); Imagepanel imagepanel ; } protected void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D)g; x= 40; y =20; w = 15; h =10; for(int i=0;i<5;i++) { g2.fillRect(x,y,w,h); g2.fill(r); x +=30; } } public void mouseClicked(MouseEvent e) { } private void imagePaneMouseClicked(MouseEvent e) { Point p = e.getPoint(); if(r.contains(p)) { if(!selected) { canDrag = true; repaint(); } } } public void mousePressed(MouseEvent e) { imagePaneMouseClicked(e); } public void mouseDragged(MouseEvent e) { Point p = e.getPoint(); if(canDrag == true) { int x = e.getX(); int y = e.getY(); int w = (int)r.getHeight(); r.setLocation(x,y); repaint(); } } public void mouseMoved(MouseEvent e) { } public void mouseReleased(MouseEvent e) { canDrag = false; } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } } }

Last edited by Preethi : 02-07-2008 at 12:21 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-08-2008, 05:51 AM
Member
 
Join Date: Jan 2008
Posts: 78
Preethi is on a distinguished road
can anyone help me?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mouse Right click option not working in solaris and linux OS dinesh kaushik AWT / Swing 2 11-21-2007 05:02 PM
The mouse and the cheese Don Quixote Java 2D 4 08-15-2007 11:55 PM
mouse over on JButton gradon Java Applets 1 08-04-2007 06:50 AM
Use the mouse position susan Java Applets 1 07-29-2007 12:10 AM
Mouse over JButton sandor AWT / Swing 1 05-17-2007 10:15 PM


All times are GMT +3. The time now is 02:15 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org