levo

Multiple Forms and Linking to Files

Passing data between forms

  • 3 things to know
  • AS Unit 2

Overview

Shared data class, one disadvantage of holding data in public global variables and callback used for between forms.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Evaluation

What is the advantage of passing a value through the constructor of the second form?

Process

How does a modal dialog return a value to the form that opened it?

Key term

Why can the calling form not read a modeless form's fields immediately after showing it?

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    Name three ways of getting a value from one form to another.

    Model answer

    A value is passed through the second form's constructor, set through a public method on it, or held in a shared class both forms can reach.

  2. 2

    What is the advantage of passing a value through the constructor of the second form?

    Model answer

    A constructor parameter makes the value compulsory, so the second form can never be created without the data it needs to work.

  3. 3

    The Java code FrmEdit f = new FrmEdit("Ana Kelly"); f.setVisible(true); runs, and FrmEdit's constructor contains txtName.setText(n); where n is the parameter. What does the user see?

    Model answer

    The user sees the edit window open with Ana Kelly already in the name box, because the constructor copied the parameter into the text box before the window appeared.

  4. 4

    How does a modal dialog return a value to the form that opened it?

    Model answer

    The dialog stores the value in one of its own fields, and the calling form reads that field through a getter once the show call returns.

  5. 5

    Why can the calling form not read a modeless form's fields immediately after showing it?

    Model answer

    The show call returns at once for a modeless form, so the user has not yet entered anything and the fields still hold their starting values.

  6. 6

    What is a shared data class, and why is one used across forms?

    Model answer

    A shared data class is a single object holding the application's working data, and every form reads and writes it so all the screens agree.

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.