Results 1 to 6 of 6
Thread: [SOLVED] reseting a value
- 11-20-2008, 06:47 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 9
- Rep Power
- 0
[SOLVED] reseting a value
Hi everyone its a pleasure to be here again. Im a novice in Java and my instructor send us a home work on regards to Radio button. Basically, my problem with my applet was... everytime I hit reset button, the value still remain. Supposedly the whole data must reset and get back from where it should started once I hit reset, but apparently it doesn't seem to do anything... it was just hidding the value.
here's my code is there something I miss?
Thank in advance.
Java Code:/** * * @author Sean */ import java.awt.*; import java.applet.*; import java.awt.event.*; public class overdueItems extends Applet implements ActionListener,ItemListener{ int bookspenalty=5, recordspenalty=7, tapespenalty=3, cdpenalty=4, videotapespenalty=6; int books=0, records=0, tapes=0, cd=0, videotapes=0; int bookitem,recorditem,itemprice; boolean done=false; int price=0; int total_overdueitems=0; int total_overduecharge=0; Label hiddenagainLabel = new Label(""); Label companyName = new Label(" Hill Brookes Library "); Label hiddenLabel = new Label(""); Label heading = new Label(" Overdue Item Price "); Label bookstabulate = new Label("Books : "); Label recordstabulate = new Label("Records : "); Label tapestabulate = new Label("Tapes : "); Label cdtabulate = new Label("CD's : "); Label videotapetabulate = new Label("Videotapes : "); Label outputLabel = new Label("Total Overdue Charge : "); Label outputLabel2 = new Label("Total Overdue Items :"); CheckboxGroup itemGroup = new CheckboxGroup(); Checkbox bookcheckBox = new Checkbox("Books $5.00",false,itemGroup); Checkbox recordcheckBox = new Checkbox("Records $7.00",false,itemGroup); Checkbox tapescheckBox = new Checkbox (" Tapes $3.00",false, itemGroup); Checkbox cdcheckBox = new Checkbox ("CD's $4.00",false,itemGroup); Checkbox videotapescheckBox = new Checkbox (" Videotapes $6.00",false,itemGroup); Checkbox hiddencheckBox = new Checkbox ("",true); Button calcButton = new Button ("Calculate"); Button addButton = new Button ("Add"); Button clearButton = new Button ("Clear"); public void init() { setSize(170,450); setBackground (Color.yellow); add(hiddenagainLabel); add(companyName); add(hiddenLabel); add(heading); add(bookcheckBox); bookcheckBox.addItemListener(this); add(recordcheckBox); recordcheckBox.addItemListener(this); add(tapescheckBox); tapescheckBox.addItemListener(this); add(cdcheckBox); cdcheckBox.addItemListener(this); add(videotapescheckBox); videotapescheckBox.addItemListener(this); add(addButton); addButton.addActionListener(this); add(calcButton); calcButton.addActionListener(this); add(clearButton); clearButton.addActionListener(this); add(bookstabulate); add(recordstabulate); add(tapestabulate); add(cdtabulate); add(videotapetabulate); add(outputLabel2); add(outputLabel); } public void itemStateChanged(ItemEvent choice) { if (bookcheckBox.getState()) { bookstabulate.setText("Books : "+(++books)); } if(recordcheckBox.getState()) { recordstabulate.setText("Records : "+(++records)); } if (tapescheckBox.getState()) { tapestabulate.setText("Tapes : "+(++tapes)); } if (cdcheckBox.getState()) { cdtabulate.setText("CD's : "+(++cd)); } if (videotapescheckBox.getState()) { videotapetabulate.setText("Videotapes : "+(++videotapes)); } else itemprice = (books+records+tapes+cd+videotapes); outputLabel2.setText("Total Overdue Items : "+(itemprice)); } public void actionPerformed(ActionEvent n) { { try { String arg=n.getActionCommand(); while (arg == "Clear") throw new NumberFormatException(); { if (bookcheckBox.getState()) total_overduecharge+=bookspenalty*books; if (recordcheckBox.getState()) total_overduecharge+=recordspenalty*records; if (tapescheckBox.getState()) total_overduecharge+=tapespenalty*tapes; if (cdcheckBox.getState()) total_overduecharge+=cdpenalty*cd; if (videotapescheckBox.getState()) total_overduecharge+=videotapespenalty*videotapes; total_overduecharge = (books*(bookspenalty)+records*(recordspenalty) +tapes*(tapespenalty)+cd*(cdpenalty)+videotapes*(videotapespenalty)); outputLabel.setText("Your Overdue Charge $"+total_overduecharge); } } catch (NumberFormatException m ) { bookstabulate.setText("Books : "); recordstabulate.setText("Records :"); tapestabulate.setText("Tapes :"); cdtabulate.setText("CD's :"); videotapetabulate.setText("Videotapes : "); outputLabel2.setText("Total Overdue Items : "); outputLabel.setText("Your Overdue Charge : "); { bookcheckBox.setState(false); recordcheckBox.setState(false); tapescheckBox.setState(false); cdcheckBox.setState(false); videotapescheckBox.setState(false); hiddencheckBox.setState(true); } } } } }
- 11-21-2008, 03:51 AM #2
Member
- Join Date
- Nov 2008
- Posts
- 9
- Rep Power
- 0
Ok! I answer my question again. There is one thing I miss. In this part you need to declare a looping in order to reset the value I use a while loop and increment it on the actionperformed. this is know solved after few cups of coffee.
-
Be careful when comparing Strings. For instance, you don't compare strings with == but instead with equals:
Not
but insteadJava Code:if (arg == "Clear")
Java Code:if (arg.equals("Clear"))
- 11-21-2008, 04:41 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 11-21-2008, 10:09 AM #5
Member
- Join Date
- Nov 2008
- Posts
- 9
- Rep Power
- 0
Ok thanks folks. Ill keep that on my mind.
yellow line is gone now.
- 11-22-2008, 01:31 PM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks