File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes maximising/minimising method. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "maximising/minimising method." Watch "maximising/minimising method." New topic
Author

maximising/minimising method.

Lloyd Jenkins
Greenhorn

Joined: Apr 17, 2002
Posts: 11
Hi,
I'm trying to write a method that, when the screen size is maximised or minimised (when the max/min button on a window is clicked), will call another method that will update the frame's canvas - keeping my 2D display properly displayed.
I've written the updateCanvas() method that I need, but I'm not sure how to start writing the method that would call it when the max/min button is pressed. Is there a special class for the button for me to make an instance of it?
Thanks
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Hello,
If you are using a Frame (which you probably are), from the documentation for the class Frame we find that:

Frames are capable of generating the following types of WindowEvents:
  • WINDOW_OPENED
  • WINDOW_CLOSING
  • WINDOW_CLOSED
  • WINDOW_ICONIFIED
  • WINDOW_DEICONIFIED
  • WINDOW_ACTIVATED
  • WINDOW_DEACTIVATED
  • WINDOW_GAINED_FOCUS
  • WINDOW_LOST_FOCUS
  • WINDOW_STATE_CHANGED

  • WindowEvent.WINDOW_ICONIFIED is the event that indicates that the window has been minimized. Unfortunately, none of these include just maximizing.
    One idea for handling when the Frame is maximized would be to implement WindowStateListener (which is "since 1.4" and as such might not be available to you - in which case a slightly different design would be necessary) and every time windowStateChanged(WindowEvent) is invoked, check whether the state of the Frame is Frame.MAXIMIZED_BOTH ("since 1.4"). To get the state of the Frame use Frame::getExtendedState() (which, again, is "since 1.4").
    Otherwise, perhaps you could simply take advantage of the automatic invocation of update(Graphics) (which Frame inherits from Container) and its default behavior of invoking paint(Graphics). Perhaps you could override either one of these methods and perform your checks and subsequent invocation of your method.
    If you're using a JDK (or JRE) "pre 1.4", then perhaps an easy solution would be to use Toolkit.getDefaultToolkit().getScreenSize() which returns a Dimension object that describes the size of the user's screen and compare this against the current size of the Frame.
    Well, that's probably enough rambling. Hopefully, something has sparked an idea for you.
    Good Luck.
    [ April 17, 2002: Message edited by: Dirk Schreckmann ]

    [How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: maximising/minimising method.
     
    Similar Threads
    ExecutorService
    method question
    Generating random numbers with given properties
    Random, random
    Refresh jsf validator component on rerender