(Java) The following program should display a single button that when clicked pr
ID: 3833303 • Letter: #
Question
(Java)
The following program should display a single button that when clicked prints “Submitted.” Fill in the blanks to complete the program. Everything you need to fill the blanks is either in the following list of fragments or is a variable in the incomplete program (e.g. frame, holder, clickMe, etc.). Some items in the list may be used to fill more than one blank. Every item is used at least once.
ActionEvent
ActionListener
addActionListener
actionPerformed
getContentPane
new DoIt()
import java.awt.event.*;
class DoIt implements ___________________________{
public void ___________________________ (___________________________ e) {
System.out.println("Submitted");
}
}
---------------------------------------------------------------------------------------------------------------
import javax.swing.*;
import java.awt.*;
class SimpleButton {
public static void main(String[] args) {
JFrame frame = new JFrame("Simple Button");
Container holder = ________________________._________________________ ();
JButton clickMe = new JButton("Click Me!"); ___________________________.add(___________________________);
clickMe. ___________________________ (___________________________);
___________________________.pack();
___________________________.setVisible(true);
}
}
Explanation / Answer
import java.awt.*; import java.awt.event.*; class DoIt implements ActionListener { public void actionPerformed(ActionEvent e) { System.out.println("Submitted"); } } class SimpleButton { public static void main(String[] args) { JFrame frame = new JFrame("Simple Button"); DoIt dolt = new DoIt(); Container holder = frame.getContentPane(); JButton clickMe = new JButton("Click Me!"); holder.add(clickMe); clickMe.addActionListener(dolt); frame.pack(); frame.setVisible(true); } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.