wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Swing/AWT Graphics

Total questions: 27

Worksheet time: 12mins

Name
Class
Date
1.

What is the purpose of the line of code:

import java.awt.*;

a)

To allow you to make Random number generators

b)

To use an interface.

c)

To import a package

d)

To allow you to Scan from the terminal or a file.

2.

What is a method?

a)

An organized and functionally based set of related interfaces and classes

b)

Where we type our code.

c)

A set of group of code that can be called for execution.

d)

An instance of a class

3.

Which of the lines of code DOES NOT call a method?

a)

frame.setSize()

b)

frame.setVisible(true);

c)

JFrame frame;

d)

frame.setResizable(false);

4.

JFrame, JPanel, JLabel, JButton are examples of ...

a)

methods

b)

classes

c)

interfaces

d)

packages

5.

What code adds this JButton to this JPanel?

JPanel panel = new JPanel();

JButton button = new JButton();

a)

panel.add(button);

b)

button.add(panel);

c)

frame.add(panel);

d)

panel.add(JButton);

6.

Which of the options below correctly set the background color of a JPanel called panel to the color blue? (More than one option may be correct).

a)

panel.setBackground(0,0,255);

b)

panel.setBackground(BLUE);

c)

panel.setBackground(new Color(0,0,255);

d)

panel.setBackground(Color.BLUE);

e)

panel.addBackgroundColor(BLUE);

7.

How would you change the text of a label to the text contained by an integer named num;

a)

label.setText(num);

b)

label.updateText(num);

c)

label.setTest("num");

d)

label.setText(num+ "");

8.

What object type handles Java's layouts?

a)

Layout Manager

b)

Layout Scheduler

c)

Layout Operator

d)

Layout Director

9.

Which of the following layouts would be good to use for GUI that resembles a computer keyboard?

a)

Flow Layout

b)

Border Layout

c)

Grid Layout

d)

Null Layout

10.

Which of the following layouts would be good to use for GUI that resembles picture frame, with a big picture on the inside and little buttons around the outside?

a)

Flow Layout

b)

Border Layout

c)

Grid Layout

d)

Null Layout

11.

Which of the following layouts would be good to use for GUI that adjusts the position of objects when the screen is resized?

a)

Flow Layout

b)

Border Layout

c)

Grid Layout

d)

Null Layout

12.

Which of the following layouts would be good to use for manually placing objects on a GUI?

a)

Flow Layout

b)

Border Layout

c)

Grid Layout

d)

Null Layout

13.

To "nest" layouts means to...

a)

set up the panel like a bird's nest

b)

put a panel with a layout inside another panel with a layout

c)

the panel will have a hole in the middle for a bird to lay an egg

d)

(this is a made up term. You didn't teach this).

14.

Which items below are interfaces?

a)

ActionListener

b)

JPanel

c)

KeyListener

d)

IOException

15.

What method(s) must we include in order to implement ActionListener?

a)

paintComponent

b)

actionEvent

c)

actionPerformed

d)

keyPressed

16.

What method(s) must we include in order to implement KeyListener?

a)

keyTyped

b)

keyPressed

c)

keyReleased

d)

keyUsed

17.

What code must be included in order for a class to implement ActionListener and for a JButton click to be listened to? (select all that apply)

a)

public class question17 implements ActionListener{...}

b)

public void actionPerformed(ActionEvent e){ .. }

c)

JButton button = new JButton();

button.addActionListener(this);

d)

Nothing needs to be added. Your normal code implements ActionListener.

18.

How can we figure out which button was clicked inside our actionPerformed?

a)

e.getSource()

b)

e.getSource

c)

getSource()

d)

getButtonClicked()

e)

e.getButtonClicked()

19.

In order to make a class that inherits characteristics of JPanel, we need to use the key word...

a)

public

b)

class

c)

extends

d)

implements

e)

throws

20.

In Pong, when we drew shapes inside of our main JPanel, we overrode which method?

a)

paintComponent

b)

actionPerformed

c)

repaint

d)

keyPressed

21.

On a 1000 x 800 pixel JFrame, when we run the line of code below what shape appears on the screen?


g.fillRect(500,400, 30, 30);

a)

A filled in square that is 30 pixels by 30 pixels.

b)

A filled in rectangle that is 500 pixels wide by 400 pixels in height.

c)

A filled in rectangle that is 400 pixels wide by 500 pixels in height.

d)

The border of a rectangle that is 500 pixels wide by 400 pixels in height.

22.

On a 1000 x 800 pixel JFrame, when we run the line of code below where on the screen will the shape appear?


g.fillRect(500,400, 30, 30);

a)

The center of the rectangle will be at the coordinate 500,400

b)

The bottom right of the rectangle will be at the coordinate 30, 30

c)

The top left of the rectangle will be at the coordinate 500,400

d)

The top right of the rectangle will be at the coordinate 500,400

23.

On a 1000 x 800 pixel JFrame, when we run the line of code below where on the screen will the shape appear?


g.fillRect(100, 700, 50, 100);

a)

top right

b)

top left

c)

bottom right

d)

bottom left

24.

On a 1000 x 800 pixel JFrame, when we run the line of code below what does the rectangle look like?


g.fillRect(100, 700, 50, 100);

a)

twice as wide as it is tall.

b)

twice as tall as is wide.

c)

it's a square.

d)

7 times as tall as it is wide.

25.

Which method do we use to put text onto a panel?

a)

g.drawString(...)

b)

g.setText(...)

c)

g.setColor(...)

d)

g.fillRect(...)

26.

The method below takes in what three parameters?

g.drawString( ... , ... , ... )

a)

String, Location, Size

b)

Font, Color, Location

c)

String, x coordinate, y coordinate

d)

String, Size, Location

27.

When you run the code below, what color will the rectangle be?


g.setColor(Color.BLUE);

g.fillRect(LpaddleX, LpaddleY, paddleW, paddleH);

g.setColor(Color.RED);

a)

RED

b)

BLUE

c)

You'll get an error. Those colors aren't valid.