Question: In the FactorialButton program in Figures 17.8a and 17.8b, what component fires the event that the listener handles? Figures 17.8a: Figures 17.8b: /********************************** * FactorialButton.java
In the FactorialButton program in Figures 17.8a and 17.8b, what component fires the event that the listener handles?
Figures 17.8a:

Figures 17.8b:

/********************************** * FactorialButton.java * Dean & Dean * * When user clicks button or presses Enter with cursor in input * text box, entered number's factorial displays in output text box. ******************************************************************/ import javax.swing. *; import java.awt. *; import java.awt.event. *; public class Factorial Button extends JFrame { private static final int WIDTH = 300; private static final int HEIGHT = 100; private JTextField xBox; // holds user entry private JTextField xfBox; // holds generated factorial //************************** public Factorial Button() ( createContents(); setVisible(true); setTitle("Factorial Calculator"); setSize (WIDTH, HEIGHT); set Layout (new FlowLayout()); set DefaultCloseOperation (EXIT_ON_CLOSE) ; } // end FactorialButton constructor //************ ***************************** ******* private void createContents() ( ******* xBox= new JTextField(2); xfBox= new JTextField(10); xfBox.setEditable(false); JLabel xLabel = new JLabel("x:"); JLabel xfLabel = new JLabel("x! :"); JButton btn = new JButton("Factorial"); Listener listener = new Listener(); add (x Label); add(xBox); add(xfLabel); add (xfBox); add (btn); xBox. addActionListener(listener); btn.addActionListener(listener); } // end create Contents ********************* ************ Here, we register the same listener with two different components.
Step by Step Solution
3.46 Rating (172 Votes )
There are 3 Steps involved in it
Its ambi... View full answer
Get step-by-step solutions from verified subject matter experts
