Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
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 01-08-2008, 09:18 PM
Member
 
Join Date: Dec 2007
Posts: 13
Thez is on a distinguished road
Listener for JFrame size change
Is there a listener that I can use that will listen for any size changes in the window/JFrame?

If the user resizes manually or the user maximizes/restores then I need to be able to get the new size, compare it to the old one and then move objects depending on the change.

Also, is there a way to know if a JFrame is maximized or not?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-08-2008, 09:38 PM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 286
roots is on a distinguished road
Code:
public class Main { public static void main(String[] args) { JFrame j = new JFrame(); j.setVisible(true); j.getContentPane().addHierarchyBoundsListener(new HierarchyBoundsListener(){ @Override public void ancestorMoved(HierarchyEvent e) { System.out.println(e); } @Override public void ancestorResized(HierarchyEvent e) { System.out.println(e); } }); } }
Please run the code, you can continue thereafter ..
__________________
dont worry newbie, we got you covered.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-08-2008, 09:45 PM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 286
roots is on a distinguished road
Please see javadocs for Frame.getExtendedState() for Maximized thing ..
__________________
dont worry newbie, we got you covered.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-08-2008, 09:51 PM
Member
 
Join Date: Dec 2007
Posts: 13
Thez is on a distinguished road
Thanks, I'll give that a try.

Another thing, currently I'm doing a while loop to get an object to move say...100 pixels.
However (logicly) it does it instantly since I didn't tell it to wait a few milliseconds between moving a pixel.
I tried using the wait(); method but it gives the IllegalMonitorStateException.
Any ideas?
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-08-2008, 09:58 PM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 286
roots is on a distinguished road
Code:
try { Thread.sleep(100); } catch (InterruptedException e1) {}
__________________
dont worry newbie, we got you covered.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 01-08-2008, 10:23 PM
Member
 
Join Date: Dec 2007
Posts: 13
Thez is on a distinguished road
I got an odd problem with that one.
Instead of moving the image one pixel, wait & show the change, and then repeat it just seems to wait until the distance has been covered and then it shows the new position, still doing it instantly but with a delay before it (the amount of pixels * msec)

Using a println() I was able to find out that it does do the sleep part correctly but it doesnt seem to update the image itself until it reaches its end.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 01-08-2008, 10:57 PM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 286
roots is on a distinguished road
If you need precision timing with your animation .. adopt double buffering and control the display with System time ..
__________________
dont worry newbie, we got you covered.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 01-08-2008, 11:01 PM
Member
 
Join Date: Dec 2007
Posts: 13
Thez is on a distinguished road
No I dont need it to be precise, I just need to be able to move a JPanel somewhat smoothly.

The sleep loop works fine itslef but the JPanel isnt being moved while the loop is going, it only moves before and after the loop, it goes from x=0 to x=100 instead of x=1,x=2,x=3,x=4,x=5,x=6 and then moving.

I tried panel.repaint(), frame.repaint(), validate() and a bunch of other stuff but it still doesnt work.
I also tried creating a blank jFrame/class with just a JFrame and a JPanel to move but it had the same result.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 01-08-2008, 11:19 PM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 286
roots is on a distinguished road
* Painting in AWT and Swing
* Java Game Development - force the repaint of a JPanel

Hoping you can get something from there ..
__________________
dont worry newbie, we got you covered.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 01-08-2008, 11:28 PM
Member
 
Join Date: Dec 2007
Posts: 13
Thez is on a distinguished road
I tried this.paint(getGraphics()); and that seems to have done it

Last edited by Thez : 01-08-2008 at 11:56 PM.
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 02-14-2008, 05:10 PM
Member
 
Join Date: Feb 2008
Posts: 1
pulugurthashanthi is on a distinguished road
Hi
I'm new to this forum donno abt asking questions
i hav tried that coding for resizing program is getting executed but a lot of matter is being dispalyed in command prompt
please 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
add an undo listener to a Jtable christina Advanced Java 9 Yesterday 04:50 AM
Tree with Listener not working when added to ScrollPane praveen.kb AWT / Swing 2 01-09-2008 09:06 AM
Listener for SWT event Java Tip Java Tips 0 01-08-2008 11:04 AM
Listener collision on game cachi Java Applets 1 08-07-2007 09:48 AM
Adding listener to non-Java object? cruxblack Advanced Java 5 07-30-2007 04:19 AM


All times are GMT +3. The time now is 03:38 PM.


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