Self Help Exercise - Writing your own subclass of JFrame

Self Help Exercise - Writing your own subclass of JFrame -...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Writing your own subclass of JFrame It is important that you practice writing Java classes, and methods within them, especially in the beginning. Below, we provide some simple exercises in creating subclasses of class JFrame, as done in the topic 2 of Module 1, part 6. Do two or three of them —or more, until they become easy to do. Page 36 of Gries/Gries contains a list of JFrame methods that you can use. Remember to write suitable specifications of the methods that you write! 1. A subclass to swap width and height In DrJava, write a subclass named JFrameFun of class JFrame. Put in it a procedure swapHtAndWdth to swap the width and height of the window. Test it in the DrJava's interactions pane by creating an instance of JFrameSwap, showing it by calling its procedure show, dragging the window to change its size, and then calling method swapHtAndWdth. 2. Add procedures to double and halve the width In class JFrameFun of exercise 1, define a procedure that doubles the width of the window and another that halves the width of the window. Test the procedures in the
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the 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).

Page1 / 2

Self Help Exercise - Writing your own subclass of JFrame -...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online