• Post Reply Bookmark Topic Watch Topic
  • New Topic

maximising/minimising method.

Lloyd Jenkins
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
Dirk Schreckmann
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

  • 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 ]
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!