Java SWING Flashcards

(11 cards)

1
Q

What two libraries must you import at the beggining of a java GUI project?

A

import java.awt.;
import java.swing.
;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the first thing you do in a java UI application and why?

A

You crate a JFrame Object because the entire app is wrapped in a JFrame Object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What do you do imediately after creating a JFrame?

A

set the size and set the default close operation as so:

```java
frame.setSize(width, hieght);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
~~~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you create a frame in java.swing?

A

```java
JFrame frame = new JFrame(frameTitle)
~~~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

u

How do you implement a layout on a frame or pannel?

A

You use the set layout method as such:

```java
.setLayout(new Layout())
~~~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What layouts exists in java.swing and java.awt

A

FlowLayout → Arranges components in a row, left to right, and wraps when needed → Used in simple toolbars or small panels.

BorderLayout → Divides space into five regions: NORTH, SOUTH, EAST, WEST, CENTER → Used in main windows where CENTER takes most of the space.

GridLayout → Arranges components in a grid of equal-sized cells → Used in keypads, calculators, or evenly spaced forms.

BoxLayout → Aligns components vertically or horizontally → Used in vertical forms or horizontal toolbars.

GridBagLayout → Flexible grid that allows components to span rows/columns with custom size and alignment → Used in complex forms with varying component sizes.

CardLayout → Stacks components and shows one at a time → Used in wizards, tab switching, or login/signup screens.

GroupLayout → Groups components horizontally and vertically (often auto-generated) → Used in advanced UIs made with GUI builders like NetBeans.

SpringLayout → Positions components using custom distance constraints (springs) → Used in highly customized layouts, rarely used manually.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you set a grid layout in swing?

A

new GridLayout(rows, columns)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you create a JComboBox?

A

```java
JComboBox<DataType> = new JComboBox<>();
~~~</DataType>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to you add options to a JComboBox object?

A

```java
comboboxObj.addItem(item)
~~~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What must you do at the end of every Java GUI project?

A

Make the frame visible by typing:

```java
frame.setVisible(true);
~~~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you ensure and app closes when the window closes in SWING?

A

```frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE):

How well did you know this?
1
Not at all
2
3
4
5
Perfectly