View Single Post
  #1 (permalink)  
Old 08-06-2007, 07:11 PM
carl carl is offline
Member
 
Join Date: Jul 2007
Posts: 35
carl is on a distinguished road
Problem with checkboxes
Hi, Here's a program I'm trying to write that uses checkboxes. But when I compile it, it doesn't work. Can anyone please point out any errors they see in the code?
Code:
import java.applet.Applet.*; import java.applet.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class test extends JApplet implements ActionListener { String companyName = new String("Event Handlers, Inc"); Font bigFont = new Font("Arial", Font.PLAIN, 24); JCheckBox cocktailBox = new JCheckBox("Cocktails"); JCheckBox dinnerBox = new JCheckBox("Dinner"); int cocktailPrice = 300, dinnerPrice = 600, totalPrice = 200; public void init() { add(cocktailBox); cocktailBox.addActionListener(this); add(dinnerBox); dinnerBox.addActionListener(this); } public void paint(Graphics gr) { gr.setFont(bigFont); gr.setColor(Color.magenta); gr.drawString(companyName, 10, 100); gr.drawString("Event Price Estimate", 10, 150); gr.setColor(Color.blue); gr.drawString(Integer.toString(totalPrice), 280, 150); } public void itemStateChanged(ActionEvent check) { totalPrice = 200; if(cocktailBox.getState()) { totalPrice += cocktailPrice; } if(dinnerBox.getState()) { totalPrice += dinnerPrice; } repaint(); } }
Thanks.
Reply With Quote
Sponsored Links