levo

Multiple Forms and Linking to Files

Creating, showing, hiding and closing a form

  • 3 things to know
  • AS Unit 2

Overview

Creating an instance and showing it, the difference between hiding a form and disposing of it, what happens to the values in its controls either way, and why a secondary window must not close the whole application.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

What happens to a form's contents when it is disposed of, and why must a secondary window not close the application?

Process

What two steps are needed to implement a second form on the screen in code?

Key term

The Java code FrmReport f = new FrmReport(); f.setVisible(true); runs in a handler and the button is clicked twice. How many report windows appear?

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    What two steps are needed to implement a second form on the screen in code?

    Model answer

    An instance of the second form's class is created, and the new form's visible property is then set to true.

  2. 2

    The Java code FrmReport f = new FrmReport(); f.setVisible(true); runs in a handler and the button is clicked twice. How many report windows appear?

    Model answer

    Two report windows appear, because each click creates a fresh instance and shows it, and neither instance knows about the other.

  3. 3

    How would a developer make sure only one copy of a form is ever open?

    Model answer

    The application keeps a reference to the form and only creates a new instance when that reference is empty, otherwise the existing window is brought to the front.

  4. 4

    What is the difference between hiding a form and closing it?

    Model answer

    A hidden form still exists in memory with all its values intact, while a closed form is destroyed and its controls and their contents are gone.

  5. 5

    A form's text boxes are filled in, the form is hidden with setVisible(false), and it is later shown again. What do the text boxes contain?

    Model answer

    The text boxes still contain the values the user typed, because hiding only stops the form being drawn and the object was never destroyed.

  6. 6

    A form's text boxes are filled in and the form is closed with dispose(), then a new instance is created and shown. What do the text boxes contain?

    Model answer

    The text boxes are empty, because dispose destroyed the old window and the new instance built fresh controls holding their default values.

Other ways to work this

The same content, four other ways.

What is inside Levo

Six ways to work the same material.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

Software and the Development Environment
Defining Data: Types, Variables and Classes
Program Control Structures
Objects, Classes and Data Structures

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

A null is the of one.
absencepresencetype

Blank Blitz makes facts automatic

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

AA null means no value has been recorded.
BZero and an empty string are values.
CA null is the absence of a value.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

An error is the mistake a person made.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Multiple Forms and Linking to Files, on a schedule.

Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.