CLEAR按钮不会清除我代码中的JRadiobutton。它还影响ActionPerformed中的Receipt按钮,该按钮使Receipt的textArea仅显示JCheckBox块外的行。"清除"按钮似乎禁用了"收据"按钮。
public void actionPerformed(ActionEvent event)
{
if (event.getSource() == btnReceipt)
{
double totD = 0.0, totalS = 0.0, totalU = 0.0, totalP = 0.0;
DecimalFormat df = new DecimalFormat("0.00");
double totP = 0.0;
txtReceipt.append("n");
txtReceipt.append("ttWELCOME TO SUPER TUITION CENTER SDN BHD" + "n");
txtReceipt.append("n");
txtReceipt.append("CUSTOMER'S NAME:" + txtname.getText() + "n");
txtReceipt.append("AGEt :" + txtage.getText() + "n");
txtReceipt.append("CONTACT NO :" + txtcontact.getText() + "n");
txtReceipt.append("n");
txtReceipt.append("SUBJECTS : " + "tt PRICE" + "tHOUR" + "tTIME" + "tTOTAL" + "n");
txtReceipt.append("n");
if (rbUpsr.isSelected())
{
int countU = 0;
double totbm1 = 0.0, totbm2 = 0.0, totbi = 0.0, totmath = 0.0, totsc = 0.0;
if (cbUbm1.isSelected())
{
int hrbm1 = Integer.parseInt(txtUh1.getText());
int tmbm1 = Integer.parseInt(txtUt1.getText());
totbm1 = 20 * hrbm1 * tmbm1;
countU++;
txtReceipt.append("BAHASA MELAYU PEMAHAMAN " + "tRM 20.00" + "t" + hrbm1 + "t" + tmbm1 + "t" + df.format(totbm1) + "n"); // set to text area
}
if (cbUbm2.isSelected())
{
int hrbm2 = Integer.parseInt(txtUh2.getText());
int tmbm2 = Integer.parseInt(txtUt2.getText());
totbm2 = 20 * hrbm2 * tmbm2;
countU++;
txtReceipt.append("BAHASA MELAYU PENULISAN " + "tRM 20.00" + "t" + hrbm2 + "t" + tmbm2 + "t" + df.format(totbm2) + "n"); // set to text area
}
if (cbUbi.isSelected())
{
int hrbi = Integer.parseInt(txtUh3.getText());
int tmbi = Integer.parseInt(txtUt3.getText());
totbi = 20 * hrbi * tmbi;
countU++;
txtReceipt.append("BAHASA INGGERIS " + "ttRM 20.00" + "t" + hrbi + "t" + tmbi + "t" + df.format(totbi) + "n"); // set to text area
}
if (cbUmath.isSelected())
{
int hrmath = Integer.parseInt(txtUh4.getText());
int tmmath = Integer.parseInt(txtUt4.getText());
totmath = 20 * hrmath * tmmath;
countU++;
txtReceipt.append("MATEMATIK " + "ttRM 20.00" + "t" + hrmath + "t" + tmmath + "t" + df.format(totmath) + "n"); // set to text area
}
if (cbUsc.isSelected())
{
int hrsc = Integer.parseInt(txtUh5.getText());
int tmsc = Integer.parseInt(txtUt5.getText());
totsc = 20 * hrsc * tmsc;
txtReceipt.append("SAINS " + "ttRM 20.00" + "t" + hrsc + "t" + tmsc + "t" + df.format(totsc) + "n"); // set to text area
countU++;
}
totalU = totbm1 + totbm2 + totbi + totmath + totsc;
if (countU > 5)
{
totD = totalU * 0.1;
totP = totalU - totD;
}
else
{
totP = totalU;
}
txtReceipt.append("TOTAL FEES : " + "tt" + "RM" + totalU + "0" + "n");
}
if (rbPt3.isSelected())
{
double pbm = 0.0, pbi = 0.0, pm3 = 0.0, psc = 0.0, pag = 0.0, psj = 0.0, pkh = 0.0;
int countP = 0;
if (cbPbm.isSelected())
{
int textPhbm = Integer.parseInt(txtPhbm.getText());
int textPtbm = Integer.parseInt(txtPtbm.getText());
pbm = 35 * textPhbm * textPtbm;
countP++;
txtReceipt.append("BAHASA MELAYU " + "ttRM 35.00" + "t " + textPhbm + "t " + textPtbm + "t " + df.format(pbm) + "n"); // set to text area
}
if (cbPbi.isSelected())
{
int textPhbi = Integer.parseInt(txtPhbi.getText());
int textPtbi = Integer.parseInt(txtPtbi.getText());
pbi = 35 * textPhbi * textPtbi;
countP++;
txtReceipt.append("BAHASA INGGERIS " + "ttRM 35.00" + "t " + textPhbi + "t " + textPtbi + "t " + df.format(pbi) + "n"); // set to text area
}
if (cbPm3.isSelected())
{
int textPhm3 = Integer.parseInt(txtPhm3.getText());
int textPtm3 = Integer.parseInt(txtPtm3.getText());
pm3 = 35 * textPhm3 * textPtm3;
countP++;
txtReceipt.append("MATEMATIK " + "ttRM 35.00" + "t " + textPhm3 + "t " + textPtm3 + "t " + df.format(pm3) + "n"); // set to text area
}
if (cbPsc.isSelected())
{
int textPhsc = Integer.parseInt(txtPhsc.getText());
int textPtsc = Integer.parseInt(txtPtsc.getText());
psc = 35 * textPhsc * textPtsc;
countP++;
txtReceipt.append("SAINS " + "ttRM 35.00" + "t " + textPhsc + "t " + textPtsc + "t " + df.format(psc) + "n"); // set to text area
}
if (cbPag.isSelected())
{
int textPhag = Integer.parseInt(txtPhag.getText());
int textPtag = Integer.parseInt(txtPtag.getText());
pag = 35 * textPhag * textPtag;
countP++;
txtReceipt.append("PENDIDIKAN ISLAM " + "ttRM 35.00" + "t " + textPhag + "t " + textPtag + "t " + df.format(pag) + "n"); // set to text area
}
if (cbPsj.isSelected())
{
int textPhsj = Integer.parseInt(txtPhsj.getText());
int textPtsj = Integer.parseInt(txtPtsj.getText());
psj = 35 * textPhsj * textPtsj;
countP++;
txtReceipt.append("SEJARAH " + "ttRM 35.00" + "t " + textPhsj + "t " + textPtsj + "t " + df.format(psj) + "n"); // set to text area
}
if (cbPkh.isSelected())
{
int textPhkh = Integer.parseInt(txtPhkh.getText());
int textPtkh = Integer.parseInt(txtPtkh.getText());
pkh = 35 * textPhkh * textPtkh;
countP++;
txtReceipt.append("KEMAHIRAN HIDUP " + "ttRM 35.00" + "t " + textPhkh + "t " + textPtkh + "t " + df.format(pkh) + "n"); // set to text area
}
totalP = pbm + pbi + pm3 + psc + pag + psj + pkh;
if (countP >= 6)
{
totD = totalP * 0.1;
totP = totalP - totD;
}
else
{
totP = totalP;
}
txtReceipt.append("TOTAL FEES : " + "tt" + "RM" + totalP + "0" + "n");//set to textArea
}
if (rbSpm.isSelected())
{
double bm = 0.0, bi = 0.0, ag = 0.0, sej = 0.0, m3 = 0.0, addm3 = 0.0, sc = 0.0, cm = 0.0, bio = 0.0, fz = 0.0, ac = 0.0, pd = 0.0;
int countS = 0;
if (cbSbm.isSelected())
{
int hbm = Integer.parseInt(txtShbm.getText());
int tbm = Integer.parseInt(txtStbm.getText());
bm = 50 * hbm * tbm;
countS++;
txtReceipt.append("BAHASA MELAYU " + "ttRM 50.00" + "t " + hbm + "t " + tbm + "t " + df.format(bm) + "n"); // set to text area
}
if (cbSbi.isSelected())
{
int hbi = Integer.parseInt(txtShbi.getText());
int tbi = Integer.parseInt(txtStbi.getText());
bi = 50 * hbi * tbi;
countS++;
txtReceipt.append("BAHASA INGGERIS " + "ttRM 50.00" + "t " + hbi + "t " + tbi + "t " + df.format(bi) + "n"); // set to text area
}
if (cbSag.isSelected())
{
int hag = Integer.parseInt(txtShag.getText());
int tag = Integer.parseInt(txtStag.getText());
ag = 50 * hag * tag;
countS++;
txtReceipt.append("PENDIDIKAN ISLAM " + "ttRM 50.00" + "t " + hag + "t " + tag + "t " + df.format(ag) + "n"); // set to text area
}
if (cbSsej.isSelected())
{
int hsej = Integer.parseInt(txtShsej.getText());
int tsej = Integer.parseInt(txtStsej.getText());
sej = 50 * hsej * tsej;
countS++;
txtReceipt.append("SEJARAH " + "ttRM 50.00" + "t " + hsej + "t " + tsej + "t " + df.format(sej) + "n"); // set to text area
}
if (cbSm3.isSelected())
{
int hm3 = Integer.parseInt(txtShm3.getText());
int tm3 = Integer.parseInt(txtStm3.getText());
m3 = 50 * hm3 * tm3;
countS++;
txtReceipt.append("MATEMATIK " + "ttRM 50.00" + "t " + hm3 + "t " + tm3 + "t " + df.format(m3) + "n"); // set to text area
}
if (cbSaddm3.isSelected())
{
int haddm3 = Integer.parseInt(txtShaddm3.getText());
int taddm3 = Integer.parseInt(txtStaddm3.getText());
addm3 = 50 * haddm3 * taddm3;
countS++;
txtReceipt.append("MATEMATIK TAMBAHAN " + "ttRM 50.00" + "t " + haddm3 + "t " + taddm3 + "t " + df.format(addm3) + "n"); // set to text area
}
if (cbSsc.isSelected())
{
int hsc = Integer.parseInt(txtShsc.getText());
int tsc = Integer.parseInt(txtStsc.getText());
sc = 50 * hsc * tsc;
countS++;
txtReceipt.append("SAINS " + "tttRM 50.00" + "t " + hsc + "t " + tsc + "t " + df.format(sc) + "n"); // set to text area
}
if (cbScm.isSelected())
{
int hcm = Integer.parseInt(txtShcm.getText());
int tcm = Integer.parseInt(txtStcm.getText());
cm = 50 * hcm * tcm;
countS++;
txtReceipt.append("KIMIA " + "tttRM 50.00" + "t " + hcm + "t " + tcm + "t " + df.format(cm) + "n"); // set to text area
}
if (cbSbio.isSelected())
{
int hbio = Integer.parseInt(txtShbio.getText());
int tbio = Integer.parseInt(txtStbio.getText());
bio = 50 * hbio * tbio;
countS++;
txtReceipt.append("BIOLOGI" + "tttRM 50.00" + "t " + hbio + "t " + tbio + "t " + df.format(bio) + "n"); // set to text area
}
if (cbSfz.isSelected())
{
int hfz = Integer.parseInt(txtShfz.getText());
int tfz = Integer.parseInt(txtStfz.getText());
fz = 50 * hfz * tfz;
countS++;
txtReceipt.append("FIZIK " + "tttRM 50.00" + "t " + hfz + "t " + tfz + "t " + df.format(fz) + "n"); // set to text area
}
if (cbSac.isSelected())
{
int hac = Integer.parseInt(txtShac.getText());
int tac = Integer.parseInt(txtStac.getText());
ac = 50 * hac * tac;
countS++;
txtReceipt.append("AKAUN " + "tttRM 50.00" + "t " + hac + "t " + tac + "t " + df.format(ac) + "n"); // set to text area
}
if (cbSpd.isSelected())
{
int hpd = Integer.parseInt(txtShpd.getText());
int tpd = Integer.parseInt(txtStpd.getText());
pd = 50 * hpd * tpd;
countS++;
txtReceipt.append("PERDAGANGAN" + "ttRM 50.00" + "t " + hpd + "t " + tpd + "t " + df.format(pd) + "n"); // set to text area
}
totalS = bm + bi + ag + sej + m3 + addm3 + sc + cm + fz + ac + pd;
if (countS >= 6)
{
totD = totalS * 0.1;
totP = totalS - totD;
}
else
{
totP = totalS;
}
txtReceipt.append("TOTAL FEES : " + "tt" + "RM" + totP + "0" + "n");
}
txtReceipt.append("n");
txtReceipt.append("TOTAL DISCOUNT : " + "tt" + "RM " + totD + "0" + "n");
txtReceipt.append("TOTAL PAYMENT PER MONTH : " + "t" + "RM" + (totP * 4) + "0" + "n");
txtReceipt.append("n");
txtReceipt.append("t THANK YOU FOR CHOOSING SUPER TUITION SDN BHD" + "n");
txtReceipt.append("n"); // set to text area
}
else
if (event.getSource() == btnClear)
{
cbUbm1.setSelected(false);
cbUbm2.setSelected(false);
cbUbi.setSelected(false);
cbUmath.setSelected(false);
cbUsc.setSelected(false);
txtUh1.setText(" ");
txtUh2.setText(" ");
txtUh3.setText(" ");
txtUh4.setText(" ");
txtUh5.setText(" ");
txtUt1.setText(" ");
txtUt2.setText(" ");
txtUt3.setText(" ");
txtUt4.setText(" ");
txtUt5.setText(" ");
txtPhbm.setText(" ");
txtPhbi.setText(" ");
txtPhm3.setText(" ");
txtPhsc.setText(" ");
txtPhag.setText(" ");
txtPhsj.setText(" ");
txtPhkh.setText(" ");
txtPtbm.setText(" ");
txtPtbi.setText(" ");
txtPtm3.setText(" ");
txtPtsc.setText(" ");
txtPtag.setText(" ");
txtPtsj.setText(" ");
txtPtkh.setText(" ");
cbPbm.setSelected(false);
cbPbi.setSelected(false);
cbPm3.setSelected(false);
cbPsc.setSelected(false);
cbPag.setSelected(false);
cbPsj.setSelected(false);
cbPkh.setSelected(false);
txtShbm.setText(" ");
txtShbi.setText(" ");
txtShsc.setText(" ");
txtShag.setText(" ");
txtShm3.setText(" ");
txtShac.setText(" ");
txtShpd.setText(" ");
txtShaddm3.setText(" ");
txtShcm.setText(" ");
txtShbio.setText(" ");
txtShfz.setText(" ");
txtShsej.setText(" ");
txtStbm.setText(" ");
txtStbi.setText(" ");
txtStsc.setText(" ");
txtStag.setText(" ");
txtStm3.setText(" ");
txtStac.setText(" ");
txtStpd.setText(" ");
txtStaddm3.setText(" ");
txtStcm.setText(" ");
txtStbio.setText(" ");
txtStfz.setText(" ");
txtStsej.setText(" ");
cbSbm.setSelected(false);
cbSbi.setSelected(false);
cbSsc.setSelected(false);
cbSag.setSelected(false);
cbSm3.setSelected(false);
cbSac.setSelected(false);
cbSpd.setSelected(false);
cbSaddm3.setSelected(false);
cbScm.setSelected(false);
cbSbio.setSelected(false);
cbSfz.setSelected(false);
cbSsej.setSelected(false);
txtname.setText(" ");
txtage.setText(" ");
txtcontact.setText(" ");
rbUpsr.setSelected(false);
rbPt3.setSelected(false);
rbSpm.setSelected(false);
txtReceipt.setText("t WELCOME TO SUPER TUITION SDN BHDtt" + "n"); //clearing all data that are available
}
else if (event.getSource() == btnExit)
{
System.exit(0); //exit the program
}
}
CLEAR(清除)按钮不会清除我代码中的J收音机按钮。
必须选择单选按钮。如果你想清除所有按钮,那么你需要使用:
buttonModel.clear();
有关详细信息,请阅读ButtonModel.clear()
API。