No student devices needed. Know more
27 questions
What is the purpose of the line of code:
import java.awt.*;
To allow you to make Random number generators
To use an interface.
To import a package
To allow you to Scan from the terminal or a file.
What is a method?
An organized and functionally based set of related interfaces and classes
Where we type our code.
A set of group of code that can be called for execution.
An instance of a class
Which of the lines of code DOES NOT call a method?
frame.setSize()
frame.setVisible(true);
JFrame frame;
frame.setResizable(false);
JFrame, JPanel, JLabel, JButton are examples of ...
methods
classes
interfaces
packages
What code adds this JButton to this JPanel?
JPanel panel = new JPanel();
JButton button = new JButton();
panel.add(button);
button.add(panel);
frame.add(panel);
panel.add(JButton);
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).
panel.setBackground(0,0,255);
panel.setBackground(BLUE);
panel.setBackground(new Color(0,0,255);
panel.setBackground(Color.BLUE);
panel.addBackgroundColor(BLUE);
How would you change the text of a label to the text contained by an integer named num;
label.setText(num);
label.updateText(num);
label.setTest("num");
label.setText(num+ "");
What object type handles Java's layouts?
Layout Manager
Layout Scheduler
Layout Operator
Layout Director
Which of the following layouts would be good to use for GUI that resembles a computer keyboard?
Flow Layout
Border Layout
Grid Layout
Null Layout
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?
Flow Layout
Border Layout
Grid Layout
Null Layout
Which of the following layouts would be good to use for GUI that adjusts the position of objects when the screen is resized?
Flow Layout
Border Layout
Grid Layout
Null Layout
Which of the following layouts would be good to use for manually placing objects on a GUI?
Flow Layout
Border Layout
Grid Layout
Null Layout
To "nest" layouts means to...
set up the panel like a bird's nest
put a panel with a layout inside another panel with a layout
the panel will have a hole in the middle for a bird to lay an egg
(this is a made up term. You didn't teach this).
Which items below are interfaces?
ActionListener
JPanel
KeyListener
IOException
What method(s) must we include in order to implement ActionListener?
paintComponent
actionEvent
actionPerformed
keyPressed
What method(s) must we include in order to implement KeyListener?
keyTyped
keyPressed
keyReleased
keyUsed
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)
public class question17 implements ActionListener{...}
public void actionPerformed(ActionEvent e){ .. }
JButton button = new JButton();
button.addActionListener(this);
Nothing needs to be added. Your normal code implements ActionListener.
How can we figure out which button was clicked inside our actionPerformed?
e.getSource()
e.getSource
getSource()
getButtonClicked()
e.getButtonClicked()
In order to make a class that inherits characteristics of JPanel, we need to use the key word...
public
class
extends
implements
throws
In Pong, when we drew shapes inside of our main JPanel, we overrode which method?
paintComponent
actionPerformed
repaint
keyPressed
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 filled in square that is 30 pixels by 30 pixels.
A filled in rectangle that is 500 pixels wide by 400 pixels in height.
A filled in rectangle that is 400 pixels wide by 500 pixels in height.
The border of a rectangle that is 500 pixels wide by 400 pixels in height.
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);
The center of the rectangle will be at the coordinate 500,400
The bottom right of the rectangle will be at the coordinate 30, 30
The top left of the rectangle will be at the coordinate 500,400
The top right of the rectangle will be at the coordinate 500,400
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);
top right
top left
bottom right
bottom left
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);
twice as wide as it is tall.
twice as tall as is wide.
it's a square.
7 times as tall as it is wide.
Which method do we use to put text onto a panel?
g.drawString(...)
g.setText(...)
g.setColor(...)
g.fillRect(...)
The method below takes in what three parameters?
g.drawString( ... , ... , ... )
String, Location, Size
Font, Color, Location
String, x coordinate, y coordinate
String, Size, Location
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);
RED
BLUE
You'll get an error. Those colors aren't valid.
Explore all questions with a free account