[SOLVED] Checkbox new to Java
Hi there everyone Im currently a novice in Java. My problem is I would like to put an Item on my applet... Using Checkbox I would like the user to click a certian box for an Item so they can purchase and automatically add the sum and will appear the total amount at the bottom of the applet I just think that its more convient doing that. Just to clarify these is only apply on the item that was checked by the user and will display the sum right after the calculate button. can that be done using checkbox?
here is my current sample code though Im still figuring out how to deal with this for 2days. Please help me Im just new to Java. Thanks in advance.
Code:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class MidMP2 extends Applet implements ItemListener,ActionListener
{
String mouse,mousei,mr;
int m1=16,m2=30;
Label companynameLabel = new Label ("Electronics & Accessories");
Label outputLabel = new Label("We will deliver your order on time!");
Checkbox mouse2 = new Checkbox ("\n Mouse",false);
Checkbox mouse3 = new Checkbox ("\n Printer",false);
Checkbox hiddenbox = new Checkbox("",true);
Button calcButton = new Button ("Calculate");
public void init() {
setBackground(Color.orange);
add(companynameLabel);
add(mouse2);
mouse2.addItemListener(this);
add(mouse3);
mouse3.addItemListener(this);
add(calcButton);
calcButton.addActionListener(this);
add(outputLabel);
}
public void itemStateChanged(ItemEvent choice)
{
int price;
if (mouse2.getState())
price =16;
else if (mouse3.getState())
price = 14;
else
price = 0;
outputLabel.setForeground(Color.black);
outputLabel.setText("This Item Cost "+ Math.round(price)+ " Dollars");
}
public void actionPerformed(ActionEvent e)
{
try
{
String args=e.getActionCommand();
int price1=Integer.parseInt(mr);
if(args =="Calculation")
if(mouse2.getState())
z
if (price1 >= 16 )
throw new NumberFormatException();
if
(price1 == 16)
outputLabel.setText("your total"+(m2));
}
catch(NumberFormatException a)
{
outputLabel.setText("your total "+(m1));
}
}
}