




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Lab; Class: Computer Science 1; Subject: Computer Science; University: Columbus State University; Term: Unknown 1989;
Typology: Lab Reports
1 / 8
This page cannot be seen from the preview
Don't miss anything!
Determining Event Sources Vote Counter, Revisited Dialog Boxes Modifying EvenOdd.java A Pay Check Program Checkboxes & Radio Buttons Adding Buttons to StyleOptions.java
Chapter 4 had a lab exercise that created a GUI with two buttons representing two candidates (Joe and Sam) in an election or popularity contest. The program computed the number of times each button was pressed. In that exercise two different listeners were used, one for each button. This exercise is a slight modification. Only one listener will be used and its ActionPerformed method will determine which button was pressed. The files VoteCounter.java and VoteCounterPanel.java contain slight revisions to the skeleton programs used in the Chapter 4 exercise. Save them to your directory and do the following:
File EvenOdd.java contains the dialog box example in Listing 5.21 the text.
Write a class PayCheck that uses dialog boxes to compute the total gross pay of an hourly wage worker. The program should use input dialog boxes to get the number of hours worked and the hourly pay rate from the user. The program should use a message dialog to display the total gross pay. The pay calculation should assume the worker earns time and a half for overtime (for hours over 40).
// StyleOptionsPanel.java Author: Lewis/Loftus // // Demonstrates the use of check boxes. //******************************************************************** import javax.swing.; import java.awt.; import java.awt.event.*; public class StyleOptionsPanel extends JPanel { private int fontSize = 36; private int style = Font.PLAIN; private JLabel saying; private JCheckBox bold, italic; //----------------------------------------------------------------- // Sets up a panel with a label and some check boxes that // control the style of the label's font. //----------------------------------------------------------------- public StyleOptionsPanel() { saying = new JLabel ("Say it with style!"); saying.setFont (new Font ("Helvetica", style, fontSize)); bold = new JCheckBox ("Bold"); bold.setBackground (Color.cyan); italic = new JCheckBox ("Italic"); italic.setBackground (Color.cyan); StyleListener listener = new StyleListener(); bold.addItemListener (listener); italic.addItemListener (listener); add (saying); add (bold); add (italic); setBackground (Color.cyan); setPreferredSize (new Dimension(300, 100)); } //***************************************************************** // Represents the listener for both check boxes. //***************************************************************** private class StyleListener implements ItemListener { //-------------------------------------------------------------- // Updates the style of the label font style. //-------------------------------------------------------------- public void itemStateChanged (ItemEvent event) { style = Font.PLAIN; if (bold.isSelected()) style = Font.BOLD; if (italic.isSelected()) style += Font.ITALIC;
saying.setFont (new Font ("Helvetica", style, fontSize)); } } }