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 08-04-2007, 08:01 PM
Senior Member
 
Join Date: Jul 2007
Posts: 130
cruxblack will become famous soon enough
How to mouse-drag a JWindow?
Anybody could help me?
And btw, whats the difference between the mouseDragged() method and the mouseMoved()?
How do i use them?
I have read the sun tutorial, but well, still a bit dull in the practice someho
Been trying to override them for a while to make it work, but it haven't went well so far

Oh n btw, i did use JWindow intentionally, in case ur wondering why i didn't use JFrame instead

Thanks guys
CruxBlack
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-04-2007, 08:35 PM
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
Hi CruxBlack,

I did not use mouse events on a JWindow, so i dont know possible problems there but as far as i guess those events should work same in ancestors of JComponent. But you can check what is reffered with a JWindow, if a JWindow does not contain inner part of a window, then catching events in that tiny area will be difficult!

About the difference of mouseDragged and mouseMoved: mouseDragged event is fired when you move your mouse while the left mouse button is clicked! In mouseMoved, left mouse button does not need to be clicked. So even moving mouse around on top of your component will fire mouseMoved!

If you write your code and ask your specific problems, i might help better.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-05-2007, 10:52 AM
Senior Member
 
Join Date: Jul 2007
Posts: 130
cruxblack will become famous soon enough
Well, im just trying to make some images appear in a JWindow, just for practice
If i add some right-clicks inside the window then it will give an option whether to close the window (terminating the application that is) or not, so far that was solved by using a JOptionPane

I also want if i do left-click inside the window, there would be a choice just like the usual left click menu, containing properties and some other custom choices which i might insert later
Though, i havent find any way to process whether the MouseEvent input is a left or right click, anybody know how?

Bout the mouseDrag problem, i want to make it that if i mousePressed and drag the window, the window would follow according to where i dragged it, just like if u drag a frame, but in JWindow i cant seem to drag it at all
Actually, none of the MouseMotionListener implementation worked at all, the mouseMoved itself that Mr. levent said to send a MouseEvent simply by hovering above the component doesn't work even when i move my mouse inside the window

Bit troubled here, anybody experienced with JWindow could help me?
here's the code so far, just a simple one
Code:
import java.awt.event.*; import java.net.*; import javax.swing.*; public class Anima2 implements MouseListener,MouseMotionListener { JWindow w; public static void main(String[] args) throws MalformedURLException { String path = <Path where the image is located, i used a gif btw>; Anima2 a = new Anima2(path); } public Anima2(String path) throws MalformedURLException { URL url = new URL(path); Icon icon = new ImageIcon(url); JLabel label = new JLabel(icon); w = new JWindow(); w.addMouseListener(this); w.getContentPane().add(label); w.pack(); w.setLocationRelativeTo(null); w.setVisible(true); } public void mousePressed(MouseEvent e) { System.out.println("Mouse Pressed"); } public void mouseReleased(MouseEvent e) { System.out.println("Mouse Released"); } public void mouseClicked(MouseEvent e) { System.out.println("Mouse Clicked"); JOptionPane j = new JOptionPane(); int i = j.showConfirmDialog(null,"Close?"); if(i == 0) System.exit(0); } public void mouseEntered(MouseEvent e) { System.out.println("Entering Window"); } public void mouseExited(MouseEvent e) { System.out.println("Leaving Window"); } //these 2 methods below doesnt work at all public void mouseDragged(MouseEvent e) { System.out.println("Dragged"); } public void mouseMoved(MouseEvent e) { System.out.println("Moved"); } }
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 08-06-2007, 10:52 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,189
hardwired is on a distinguished road
I also want if i do left-click inside the window, there would be a choice just like the usual left click menu, containing properties and some other custom choices
You can use a JPopupMenu for this. The tutorial has a relevant section (see below). The mouse button that triggers the popup, the popupTrigger, varies by platform.
i havent find any way to process whether the MouseEvent input is a left or right click
One of the easier ways is with SwingUtilities. It has three methods, eg, SwingUtilities.isLeftMouseButton(aMouseEvent). The MouseEvent api has more info in the comments section.
Aside from the focus problem (see below) this might be difficult. You could try working with the MouseInfo and PointerInfo classes (j2se 1.5+). And the other helpful resource is again SwingUtilities which has some convenience methods such as convertPointToScreen.
none of the MouseMotionListener implementation worked at all
Focus is an issue beginning with j2se 1.4. Look in the Window class api for the method isFocusableWindow. For the window, its JRootPane or any child components to be able to send Input/MouseEvents it/they must have the focus. This method lists the requirements for this to happen.
Here are a couple of links into the tutorial that may be helpful.
How to Use Menus
esp, Bringing Up a Popup Menu
How to Use the Focus Subsystem
esp, Making a Custom Component Focusable
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
Image with JWindow -> trails ofir3dvb AWT / Swing 2 03-18-2008 06:21 PM
JWindow/JFrame with boarders Java Tip Java Tips 0 03-12-2008 12:35 PM
The mouse and the cheese Don Quixote Java 2D 4 08-15-2007 11:55 PM
Help with drag from panel fernando AWT / Swing 2 08-07-2007 11:19 PM
Mouse over JButton sandor AWT / Swing 1 05-17-2007 10:15 PM


All times are GMT +3. The time now is 12:08 PM.


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