Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

14-2 Write the application JFrameDisableButton that instantiates a JFrame that contains a JButton. Modify the JFrameDisableButton program so that the JButton is not disabled until

14-2

Write the application JFrameDisableButtonthat instantiates a JFrame that contains a JButton. Modify the JFrameDisableButtonprogram so that the JButton is not disabled until the user has clicked at least eight times. At that point, display a JLabel that indicates Thats enough!.

import java.awt.*; import javax.swing.*; import java.awt.event.*; public class JFrameDisableButton extends JFrame implements ActionListener { final int SIZE = 180; Container con = getContentPane(); JButton button = new JButton("Press Me"); int count = 0; final int MAX = 8; JLabel label = new JLabel("That's enough!"); public JFrameDisableButton() { // Write your code here } @Override public void actionPerformed(ActionEvent e) { // Write your code here } public static void main(String[] args) { JFrameDisableButton frame = new JFrameDisableButton(); } }

-----------------------------------------------------------------------------

14-3

The application JFacts contains a JFrame, a label, and six random facts. Every time the user clicks the JButton, remove replace the label's text and add a different one. The facts should cycle in order, fact 1 to fact 6. When the JButton is pressed on face 6, the program should display fact 1 again.

import javax.swing.*; import java.awt.*; import java.awt.event.*;

public class JFacts extends JFrame implements ActionListener { FlowLayout flow = new FlowLayout(); JButton b = new JButton("Press to change fact"); JLabel stars = new JLabel("**********************************************"); JLabel fact = new JLabel(); String[] quotes = new String[]{"Only seven prisoners were in the Bastille when it was stormed. ", "A Tale of Two Cities is a novel set during the French Revolution. ", "Perhaps 40,000 people were executed at the guillotine. ", "A loaf of bread cost a weeks wages prior to the French Revolution. ", "Thomas Jefferson was the U.S. Minister to France during the Revolution. ", "Protestant and Jewish religions were illegal in France before 1879. ", }; int counter = 0; public JFacts() { // Write your code here } public static void main(String[] args) { JFacts rFrame = new JFacts(); rFrame.setSize(440, 100); rFrame.setVisible(true); } @Override public void actionPerformed(ActionEvent e) { // Write your code here }

}

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions