how to use try and catcth to my program? please help...
i have this program and it needs to input a quantity but if you didn't input quantity it must warned you using joptionpane. i need to use try and catch and put it on my code but it doesn't work at all... i mean i don't know where i must put it plz help with my code...
================================================== =======
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JOptionPane;
public class bookpractice extends Applet implements ActionListener,ItemListener
{Label bklbl = new Label("BOOK");
Choice bkchc = new Choice();
Label edlbl = new Label("EDITION");
CheckboxGroup edcbg = new CheckboxGroup();
Checkbox fichk = new Checkbox("1st",edcbg,true);
Checkbox sechk = new Checkbox("2nd",edcbg,false);
Checkbox thchk = new Checkbox("3rd",edcbg,false);
Checkbox fochk = new Checkbox("4th",edcbg,false);
Checkbox wdchk = new Checkbox("with discount");
Label qlbl = new Label("QUANTITY");
TextField qtf = new TextField("",20);
Label plbl = new Label("PRICE");
TextField ptf = new TextField("",20);
Label slbl = new Label("SALES");
TextField stf = new TextField("",20);
Button cbtn = new Button("COMPUTE");
Button rbtn = new Button("RESET");
double sales;
double q;
public void init()
{add(bklbl);
bkchc.add("JAVA");
bkchc.add("PHP");
bkchc.add("C#");
add(bkchc);
add(edlbl);
add(fichk);
add(sechk);
add(thchk);
add(fochk);
add(wdchk);
add(qlbl);
add(qtf);
add(plbl);
add(ptf);
add(slbl);
add(stf);
add(cbtn);
add(rbtn);
fichk.addItemListener(this);
sechk.addItemListener(this);
thchk.addItemListener(this);
fochk.addItemListener(this);
wdchk.addItemListener(this);
cbtn.addActionListener(this);
rbtn.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{String qstr = qtf.getText();
try
{if(qstr != "")
{
}
}
catch(Exception x)
{JOptionPane.showMessageDialog(null,"An error occurred!","Warning",JOptionPane.ERROR_MESSAGE);
}
double amt = Double.parseDouble(ptf.getText());
double q = Double.parseDouble(qstr);
{if(e.getSource() == cbtn)
{if(wdchk.getState())
{sales = amt*q;
sales = sales - (sales*0.10);
stf.setText(String.valueOf(sales));
}
else
{sales = amt*q;
stf.setText(String.valueOf(sales));
}
}
if(e.getSource() == rbtn)
{bkchc.select(0);
fichk.setState(true);
sechk.setState(false);
thchk.setState(false);
fochk.setState(false);
wdchk.setState(false);
qtf.setText("");
ptf.setText("");
stf.setText("");
}
}
}
public void itemStateChanged(ItemEvent ex)
{if(fichk.getState())
{ptf.setText("200.00");
}
if(sechk.getState())
{ptf.setText("250.00");
}
if(thchk.getState())
{ptf.setText("300.00");
}
if(fochk.getState())
{ptf.setText("350.00");
}
}
}
================================================== =======