Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Add butns to the frame Create a listener object // Register listeners jbtCancel.addActionListener(btListener); Main method. public static void main(Stringl) args) f TestActionEvent frame - new

image text in transcribed
image text in transcribed
Add butns to the frame Create a listener object // Register listeners jbtCancel.addActionListener(btListener); Main method. public static void main(Stringl) args) f TestActionEvent frame - new TestActionEventO; frame.setDefaultCloseOperation(JFrame.EXIT ON CLOSE); frame.setSize(100, 80); frame.set Visible(true); class ButtonListener implements ActionListener( /*This method will be invoked when a button is clicked* public void actionPerformed(ActionEvent e) t if (e.getActionCommandO.equals("Democratie") ( System.out.println"Mitt Obama will win."); else if (e.getActionCommand0.equals("Republic")) System.out,println("Barack Romney will win."); 12. en the following Java program runs, two buttons will be displayed on s frame wh atre the captions of the two buttons? What will happen when the first buton is chiecies What will happen when the second button is clicked? Regne import javax.swing. import java.awt.* import java.awt.event. public class TestActionEvent extends JFrame t // Create two buttons private JButton jbtOk- new JButton("Democratic" private JButton jbtCancel new JButtonC"'Republic") /**Default constructor*/ public TestActionEventO // Set the window title setTitle("TestActionEvent"); // Set FlowLayout manager to arrange the components // inside the frame setLayout(new FlowLayout); // Add buttons to the frame add(jbtOk); add(jbtCancel); // Create a listener object ButtonListener btListener = new Button1 istener new ButtonListener

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions