Exam 15: Advanced Gui Topics

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

import java.awt.*; import javax.swing.*; import java.awt.Color; public class JFrameWithColor extends JFrame {     private final int SIZE = 180;     private Container con = getContentPane();     private JButton button =       new JButton("Press Me");    public JFrameWithColor()    {       super("Frame");       setSize(SIZE, SIZE);       con.setLayout(new FlowLayout());       con.add(button);       -----Code here-----       -----Code here-----       -----Code here-----    }    public static void main(String[] args)    {        JFrameWithColor frame =          new JFrameWithColor();        frame.setVisible(true);    } } In the first indicated line, write the statement to set the background color of the JFrame 's content pane to gray. Using the remaining two indicated lines, write the statements to set the JButton foreground color to white and the background color to blue.

Free
(Essay)
4.9/5
(33)
Correct Answer:
Verified

con.setBackground(Color.YELLOW);
button.setBackground(Color.RED);
button.setForeground(Color.WHITE);

The wildcard in the import java.awt.* statement imports all types in the java.awt package, including java.awt.Color and java.awt.Font .

Free
(True/False)
4.9/5
(33)
Correct Answer:
Verified

False

What is the parent class of JPanel ?

Free
(Multiple Choice)
4.9/5
(42)
Correct Answer:
Verified

C

When do you need to worry about using the getContentPane() method?

(Essay)
4.9/5
(31)

Which of the following statements will correctly add a JMenuBar named myBar to a JFrame ?

(Multiple Choice)
5.0/5
(32)

import javax.swing.*; import java.awt.*; public class JDemoGridLayout extends JFrame {    private JButton b1 = new JButton("Button 1");    private JButton b2 = new JButton("Button 2");    private JButton b3 = new JButton("Button 3");    private JButton b4 = new JButton("Button 4");    private JButton b5 = new JButton("Button 5");    -----Code here-----    private Container con = getContentPane();    public JDemoGridLayout()    {      con.setLayout(layout);      con.add(b1);      con.add(b2);      con.add(b3);      con.add(b4);      con.add(b5);      setSize(200, 200);    }    public static void main(String[] args)    {      JDemoGridLayout frame = new JDemoGridLayout();      frame.setVisible(true);    } } Using the above code, write the statement in the indicated line to establish a GridLayout with three horizontal rows and two vertical columns, with horizontal and vertical gaps of five pixels each.

(Short Answer)
4.8/5
(35)

____________________ are lists of user options; they are commonly added features in GUI programs.

(Short Answer)
4.9/5
(33)

The focusGained(FocusEvent) handler is defined in the ____ interface.

(Multiple Choice)
4.8/5
(42)

A BorderLayout is arranged in north, south, east, west, and bottom positions.

(True/False)
4.7/5
(38)

A(n) _________________________ is a tree of components that has a top-level container as its root (that is, at its uppermost level).

(Short Answer)
4.7/5
(36)

import javax.swing.*; import java.awt.*; public class JDemoBorderLayout extends JFrame {     private JButton nb = new JButton("North Button");     private JButton sb = new JButton("South Button");     private JButton eb = new JButton("East Button");     private JButton wb = new JButton("West Button");     private JButton cb = new JButton("Center Button");     private Container con = getContentPane();     public JDemoBorderLayout()     {        con.setLayout(new BorderLayout());        -----Code here-----        -----Code here-----        -----Code here-----        -----Code here-----        -----Code here-----        setSize(400, 150);      }      public static void main(String[] args)      {         JDemoBorderLayout frame = new JDemoBorderLayout();         frame.setVisible(true);      } } Using the above code, write the statements in the indicated lines to add components to each of the five regions (north, south, east, west and center).

(Essay)
4.9/5
(28)

If you do not specify alignment, Component s are right-aligned in a FlowLayout Container by default.

(True/False)
5.0/5
(31)

The ____________________ manager is the default manager class for all content panes.

(Short Answer)
4.8/5
(38)

You use the ____________________ interface when you are interested in actions the user initiates from the keyboard.

(Short Answer)
4.8/5
(33)

Describe the difference between an ActionEvent and a MouseEvent .

(Essay)
4.9/5
(41)

Layout managers are interface classes that align components to prevent crowding or overlapping.

(True/False)
4.8/5
(31)

A(n) ____ implements all methods in an interface and provides an empty body for each method.

(Multiple Choice)
4.8/5
(36)

Describe the two CardLayout constructors.

(Essay)
4.8/5
(47)

Each JMenu can contain options, called JMenuItem s, or can contain submenus that are ____ .

(Multiple Choice)
4.7/5
(44)

import javax.swing.*; import java.awt.*; import java.awt.event.*; public class JMouseActionFrame extends JFrame implements MouseListener {    private int x, y;    private JLabel label = new JLabel("Do something with the mouse");    String msg = "";    public JMouseActionFrame()    {       setTitle("Mouse Actions"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       setLayout(new FlowLayout()); addMouseListener(this);       add(label);    }    public void mouseClicked(MouseEvent e)    {       int whichButton = e.getButton(); msg = "You pressed mouse ";       if(whichButton == MouseEvent.BUTTON1)          msg += "button 1.";       else          if(whichButton == MouseEvent.BUTTON2)             msg += "button 2.";          else             msg += "button 3.";       msg += " You are at position " +          e.getX() + ", " + e.getY() + ".";       if(e.getClickCount() == 2)          msg += " You double-clicked.";       else          msg += " You single-clicked.";       label.setText(msg); } @Override public void mouseEntered(MouseEvent e) {    msg = "You entered the frame.";    label.setText(msg); } @Override public void mouseExited(MouseEvent e) {    msg = "You exited the frame.";    label.setText(msg); } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } @Override public static void main(String[] args) {    JMouseActionFrame mFrame = new JMouseActionFrame();    final int WIDTH =  750; final int HEIGHT  =  300; mFrame.setSize(WIDTH, HEIGHT);                mFrame.setVisible(true); } } The above code shows a JMouseActionFrame application that demonstrates several of the mouse listener and event methods. The constructor sets a frame title by passing it to the parent of JMouseActionFrame , sets a close operation, sets the layout manager, enables the frame to listen for mouse events, and adds the JLabel to the JFrame . However, most of the action occurs in the mouseClicked() method. Describe what actions occur in this method.

(Essay)
4.8/5
(37)
Showing 1 - 20 of 66
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)