levo

Multiple Forms and Linking to Files

Creating, showing, hiding and closing a form

  • 3 things to know
  • AS Unit 2
Start revising · £5/month

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.

Everything in your subscription

Runs, plus a mode for every other kind of session.

1Flash
2Imposter
3Fade
4Brain dump

Learn every subtopic in runs of four questions

Facts flash and fade, a wrong word hides in some of them, and a brain dump decides which questions are locked in.

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

Cram the night before, weakest topic first

A quick scan finds your weakest topics. Recall each fact you missed three times in a row.

A null is the of one.
absencepresencetype

Blank Blitz consolidates the facts

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

✓What it iscovered
~Why it happenspartly there
How long it lastsnot there yet

Explain It tests your understanding

Explain a concept in your own words and see which of its points you covered.

An error is the mistake a person made.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The faults are the mistakes students make most often.

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.

Learn it in runs of four questions, each ending on a brain dump against the clock. Every question you lock in comes back the next day, then at longer gaps, each time just before you would forget it.

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