Question

Consider the following Java program. What is the superclass of "Clicker"? import java.awt.event.*; import javax.swing.*; public...

Consider the following Java program. What is the superclass of "Clicker"?

import java.awt.event.*;
import javax.swing.*;
public class Clicker extends JFrame implements ActionListener {
    int count;
    JButton button;
    Clicker() {
        super("Click Me");
        button = new JButton(String.valueOf(count));
        add(button);
        button.addActionListener(this);
        setSize(200,100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }
    public void actionPerformed(ActionEvent e) {
        count++;
        button.setText(String.valueOf(count));
    }
    public static void main(String[] args) { new Clicker(); }
}

Select one:

a. ActionEvent

b. ActionListener

c. JButton

d. JFrame

e. this

Question 2

Question text

Consider the following Java program. What is the superclass of "MouseWhisperer"?


import java.awt.event.*;
import javax.swing.*;
public class MouseWhisperer extends JFrame implements MouseListener {
    MouseWhisperer() {
        super("COME CLOSER");
        setSize(300,100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        addMouseListener(this);
        setVisible(true);
    }
    public void mouseClicked(MouseEvent e) { setTitle("OUCH"); }
    public void mousePressed(MouseEvent e) { setTitle("LET GO"); }
    public void mouseReleased(MouseEvent e) { setTitle("WHEW"); }
    public void mouseEntered(MouseEvent e) { setTitle("I SEE YOU"); }
    public void mouseExited(MouseEvent e) { setTitle("COME CLOSER"); }
    public static void main(String[] args) { new MouseWhisperer(); }
}

Select one:

a. java.awt.event

b. JFrame

c. MouseEvent

d. MouseListener

e. this

Question 3

Question text

Consider the following Java program. Which object registers event listeners?


import java.awt.event.*;
import javax.swing.*;
public class MouseWhisperer extends JFrame implements MouseListener {
    MouseWhisperer() {
        super("COME CLOSER");
        setSize(300,100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        addMouseListener(this);
        setVisible(true);
    }
    public void mouseClicked(MouseEvent e) { setTitle("OUCH"); }
    public void mousePressed(MouseEvent e) { setTitle("LET GO"); }
    public void mouseReleased(MouseEvent e) { setTitle("WHEW"); }
    public void mouseEntered(MouseEvent e) { setTitle("I SEE YOU"); }
    public void mouseExited(MouseEvent e) { setTitle("COME CLOSER"); }
    public static void main(String[] args) { new MouseWhisperer(); }
}

Select one:

a. java.awt.event

b. JFrame

c. MouseEvent

d. MouseListener

e. this

Question 4

Question text

A class that implements a listener interface does which of the following?

Select one:

a. It generates events.

b. It handles events.

c. It maintains an object directory.

d. It records audio.

e. It runs an event loop.

Clear my choice

Question 5

Question text

Consider the following Java program. Which one of the following is an interface?


import java.awt.event.*;
import javax.swing.*;
public class MouseWhisperer extends JFrame implements MouseListener {
    MouseWhisperer() {
        super("COME CLOSER");
        setSize(300,100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        addMouseListener(this);
        setVisible(true);
    }
    public void mouseClicked(MouseEvent e) { setTitle("OUCH"); }
    public void mousePressed(MouseEvent e) { setTitle("LET GO"); }
    public void mouseReleased(MouseEvent e) { setTitle("WHEW"); }
    public void mouseEntered(MouseEvent e) { setTitle("I SEE YOU"); }
    public void mouseExited(MouseEvent e) { setTitle("COME CLOSER"); }
    public static void main(String[] args) { new MouseWhisperer(); }
}

Select one:

a. java.awt.event

b. JFrame

c. MouseEvent

d. MouseListener

e. this

Homework Answers

Answer #1

Inheritence is the object oriented concept in Java Programming.

Two concepts in inheritence is :- Subclass and Superclass.

subclass is the child class that inherits from another class.

superclass is the parent class being inherited from

In Java programming inheritence is implemented by using extends keyword.

Fromat : Class subclass name extends superclass name.

Question 1:

Answer : - Option d . JFrame

  • public class Clicker extends JFrame implements ActionListener

Subclass Clicker inherits superclass JFrame using extends keyword.

Question 2:

Answer : - Option b. JFrame

  • public class MouseWhisperer extends JFrame implements MouseListener

Subclass MouseWhisperer inherits superclass JFrame using extends keyword.

Question 3:

Answer : - Option e. this

Once a class implements MouseListener that class's  object can register as a listener for the action events.

So here class MouseWhisperer implements MouseListener and object of MouseWhisperer registers event listener.

Question 4:

Answer : - Option b. It handles events.

A class that implements a listener interface handles the events.

Question 5:

Answer : - Option d. MouseListener

Interface in Java is similar to a class but has some differences compare to class.

While using interfaces in java programming it uses implements keyword to implement the interface.

In the given program code it is given that,

public class MouseWhisperer extends JFrame implements MouseListener

uses implements MouseListener. From the usage of implements keyword we can identify that

" MouseListener " is the interface.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Consider the following Java program. Describe what it does in response to specific operations of the...
Consider the following Java program. Describe what it does in response to specific operations of the mouse, and how it does it. (You are encouraged to run the program for yourself to test its behavior. Then read through the program carefully to understand how that behavior arises.) import java.awt.event.*; import javax.swing.*; public class MouseWhisperer extends JFrame implements MouseListener {     MouseWhisperer() {         super("COME CLOSER");         setSize(300,100);         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         addMouseListener(this);         setVisible(true);     }     public void mouseClicked(MouseEvent e)...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { flavor = s; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         System.out.println(pepper.getFlavor());     } } a. a class variable b. a constructor c. a local object variable d....
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*;...
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener {     int count;     JButton button;     Clicker() {         super("Click Me");         button = new JButton(String.valueOf(count));         add(button);         button.addActionListener(this);         setSize(200,100);         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         setVisible(true);     }     public void actionPerformed(ActionEvent e) {         count++;         button.setText(String.valueOf(count));     }     public static void main(String[] args) { new Clicker(); } } a. add(button);...
What is the output of the following Java program? public class Food {     static int...
What is the output of the following Java program? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { s = flavor; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         pepper.setFlavor("spicy");         System.out.println(pepper.getFlavor());     } } Select one: a. sweet b. 1 c. The program does not compile. d. 2 e. spicy...
   import javax.swing.*; import java.awt.*; import java.awt.event.*; //Class that paints according to the user wish. public...
   import javax.swing.*; import java.awt.*; import java.awt.event.*; //Class that paints according to the user wish. public class RapidPrototyping extends JFrame implements MouseListener,ItemListener,ActionListener,MouseMotionListener {       //panel to hold color,shapes and thickness components    JPanel panel;    //shapes combobox    JComboBox shapes;    //color radio buttons    JRadioButton red, green, blue;    //thickness combobox    JComboBox thicknesses;    //clear button.    JButton clear;    JPanel center;       /*values of each selection*/    Color color;    int thickness;    String shape;...
Describe the following Java code. Give screenshots of the image it produces public class main{ public...
Describe the following Java code. Give screenshots of the image it produces public class main{ public static void main(String[] args{ new MyFrame(); } } import javax.swing.*; public class MyFrame extends JFrame{ MyPanel panel; MyFrame(){ this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.add(panel); this.pack(); this.setLocationRelativeTo(null); this.setVisible(true); } } import java.awt.*; import.javax.swing.*; public class MyPanel extends JPanel{ //Image Image; MyPanel(){ //image=new ImageIcon("sky.png").getImage(); this.setPreferredSize(new Dimension(500,500)); } public void paint(Graphics g){ Graphics2D g2D = (Graphics2D) g; //g2D.drawImage(image,0,0,null); g2D.setPaint(Color.blue); g2D.setStroke(new BasicStroke(5)); g2D.drawLine(0,0,500,500); //g2D.setPaint(Colo.pink); //g2D.drawRect(0,0,100,200); //g2D.fillRect(0,0,100,200); //g2D.setPaint(Color.orange); //g2D.drawOval(0,0,100,100); //g2D.fillOval(0,0,100,100); //g2D.setPaint(color.red); //g2D.drawArc(0,0,100,100,0,180); //g2D.fillArc(0,0,100,100,0,180);...
What is the output of the following Java program? interface Food {     public void printFlavor();...
What is the output of the following Java program? interface Food {     public void printFlavor(); } class Pepper implements Food {     public void printFlavor() { System.out.println("spicy"); } } public class Lunch {     public static void main(String[] args) {        Food pepper = new Pepper();         pepper.printFlavor();     } } Select one: a. spicy b. no output c. the program does not compile d. bland e. bland spicy
Using Java, write a program that allows the user to play the Rock-Paper-Scissors game against the...
Using Java, write a program that allows the user to play the Rock-Paper-Scissors game against the computer through a user interface. The user will choose to throw Rock, Paper or Scissors and the computer will randomly select between the two. In the game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. The program should then reveal the computer's choice and print a statement indicating if the user won, the computer won, or if it was a tie. Allow...
Hi, I'm writing a Java program that prints a grid with circles and squares that have...
Hi, I'm writing a Java program that prints a grid with circles and squares that have letters in them and it is also supposed to print the toString() function to the console window each time the application runs. This toString() function is supposed to show the tile's shape, letter, and color component (or components). Could someone please review and debug my code to help me figure out why my toString() function is not working? import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton;...
IN JAVA Speed Control Problem: The files SpeedControl.java and SpeedControlPanel.java contain a program (and its associated...
IN JAVA Speed Control Problem: The files SpeedControl.java and SpeedControlPanel.java contain a program (and its associated panel) with a circle that moves on the panel and rebounds from the edges. (NOTE: the program is derived from Listing 8.15 and 8.16 in the text. That program uses an image rather than a circle. You may have used it in an earlier lab on animation.) The Circle class is in the file Circle.java. Save the program to your directory and run it...