solutions to self help exercise writing your own subclass of JFrame

Solutions to self help exercise writing your own subclass of JFrame

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import javax.swing.*; /** Answers to self-help exercises on writing your own subclass of JFrame. */ public class JFrameFun extends JFrame { /** Swap the width and height of this window. */ public void SwapHtAndWidth() { setSize(getHeight(), getWidth()); } /** Double the width of this window. */ public void doubleWidth() { setSize(2*getWidth(), getHeight()); } /** Halve the width of this window. */ public void halveWidth() { setSize(getWidth() / 2, getHeight()); } /** Set the title of the window to the Date and time. */
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: public void setTitleToDate() { setTitle((new java.util.Date()).toString()); } /** Put the position in the title. */ public void putPositionInTitle() { setTitle("window is at (" + getX() + ", " + getY() + ")"); } /** Switch the position and size of the window */ public void swap() { int w= getWidth(); int h= getHeight(); int x= getX(); int y= getY(); setSize(x, y); setLocation(w, h); } }...
View Full Document

This note was uploaded on 07/07/2008 for the course CS 101 taught by Professor Gries during the Spring '08 term at Cornell University (Engineering School).

Ask a homework question - tutors are online