import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.text.DecimalFormat;
public class CommissionApplet extends Applet implements ItemListener
{
//declare var
double dollars, answer;
int empCode;
Image dollarSign;
Color darkRed = new Color(100,150,50);
Label promptLabel = new Label("Enter the sales amount (do not use commas or dollar signs) : ");
TextField salesField = new TextField(20);
Label codeLabel = new Label("Select the appropriate commission code : ");
CheckboxGroup codeGroup = new CheckboxGroup();
Checkbox telephoneBox = new Checkbox("Telephone Sales",false,codeGroup);
Checkbox inStoreBox = new Checkbox("In-Store Sales",false,codeGroup);
Checkbox outsideBox = new Checkbox("Outside Sales",false,codeGroup);
Checkbox hiddenBox = new Checkbox("",true,codeGroup);
Label outputLabel = new Label("Click an option button to calculate the slaes commission.");
public void init()
{
setBackground(darkRed);
setForeground(Color.white);
add(promptLabel);
add(salesField);
salesField.requestFocus();
salesField.setForeground(Color.black);
add(codeLabel);
add(telephoneBox);
telephoneBox.addItemListener(this);
add(inStoreBox);
inStoreBox.addItemListener(this);
add(outsideBox);
outsideBox.addItemListener(this);
add(outputLabel);
}
public void itemStateChanged(ItemEvent choice)
{
try
{
dollars = getSales();
empCode = getCode();
answer = getComm(dollars,empCode);
output(answer,dollars);
บรรทัดนี้ดักควายห้ามก๊อป
}
catch (NumberFormatException e)
{
outputLabel.setText("You must enter a dollar amount greater than zero.");
hiddenBox.setState(true);
salesField.setText("");
salesField.requestFocus();
}
}
public double getSales()
{
double sales = Double.parseDouble(salesField.getText());
if(sales <= 0)throw new NumberFormatException();
return sales;
}
public int getCode()
{
int code = 0;
if(telephoneBox.getState()) code = 1;
else
if(inStoreBox.getState()) code = 2;
else
if(outsideBox.getState())code = 3;
return code;
บรรทัดนี้ดักควายห้ามก๊อป
}
public double getComm(double sales, int code)
{
double commission = 0.0;
switch (code)
{
case 1:
commission = .10 * sales;
break;
case 2:
commission = .14 * sales;
break;
บรรทัดนี้ดักควายห้ามก๊อป
case 3:
commission = .17 * sales;
break;
}
return commission;
}
public void output(double commission,double sales)
{
DecimalFormat twoDigits = new DecimalFormat("$#,###.00");
outputLabel.setText("Your commission on sales of" + twoDigits.format(sales) + "is" + twoDigits.format(commission));
}
public void paint(Graphics g)
{
dollarSign = getImage(getDocumentBase(),"dollarSign.gif");
g.drawImage(dollarSign,12,28,this);
}
}
import java.applet.*;
import java.awt.event.*;
import java.text.DecimalFormat;
public class CommissionApplet extends Applet implements ItemListener
{
//declare var
double dollars, answer;
int empCode;
Image dollarSign;
Color darkRed = new Color(100,150,50);
Label promptLabel = new Label("Enter the sales amount (do not use commas or dollar signs) : ");
TextField salesField = new TextField(20);
Label codeLabel = new Label("Select the appropriate commission code : ");
CheckboxGroup codeGroup = new CheckboxGroup();
Checkbox telephoneBox = new Checkbox("Telephone Sales",false,codeGroup);
Checkbox inStoreBox = new Checkbox("In-Store Sales",false,codeGroup);
Checkbox outsideBox = new Checkbox("Outside Sales",false,codeGroup);
Checkbox hiddenBox = new Checkbox("",true,codeGroup);
Label outputLabel = new Label("Click an option button to calculate the slaes commission.");
public void init()
{
setBackground(darkRed);
setForeground(Color.white);
add(promptLabel);
add(salesField);
salesField.requestFocus();
salesField.setForeground(Color.black);
add(codeLabel);
add(telephoneBox);
telephoneBox.addItemListener(this);
add(inStoreBox);
inStoreBox.addItemListener(this);
add(outsideBox);
outsideBox.addItemListener(this);
add(outputLabel);
}
public void itemStateChanged(ItemEvent choice)
{
try
{
dollars = getSales();
empCode = getCode();
answer = getComm(dollars,empCode);
output(answer,dollars);
บรรทัดนี้ดักควายห้ามก๊อป
}
catch (NumberFormatException e)
{
outputLabel.setText("You must enter a dollar amount greater than zero.");
hiddenBox.setState(true);
salesField.setText("");
salesField.requestFocus();
}
}
public double getSales()
{
double sales = Double.parseDouble(salesField.getText());
if(sales <= 0)throw new NumberFormatException();
return sales;
}
public int getCode()
{
int code = 0;
if(telephoneBox.getState()) code = 1;
else
if(inStoreBox.getState()) code = 2;
else
if(outsideBox.getState())code = 3;
return code;
บรรทัดนี้ดักควายห้ามก๊อป
}
public double getComm(double sales, int code)
{
double commission = 0.0;
switch (code)
{
case 1:
commission = .10 * sales;
break;
case 2:
commission = .14 * sales;
break;
บรรทัดนี้ดักควายห้ามก๊อป
case 3:
commission = .17 * sales;
break;
}
return commission;
}
public void output(double commission,double sales)
{
DecimalFormat twoDigits = new DecimalFormat("$#,###.00");
outputLabel.setText("Your commission on sales of" + twoDigits.format(sales) + "is" + twoDigits.format(commission));
}
public void paint(Graphics g)
{
dollarSign = getImage(getDocumentBase(),"dollarSign.gif");
g.drawImage(dollarSign,12,28,this);
}
}
Mon May 10, 2010 2:45 am by titr
» แนวคิดแบบหมวก 6 ใบ -- มาวิเคราะห์กันๆ
Fri Dec 11, 2009 12:28 am by Admin
» หาแนวร่วม ทำซัพนรก Anime จ้า *-*
Fri Oct 09, 2009 1:46 pm by สก๊อยผ่า
» ขอเรียกร้องสิทธิให้แก่ช่วงๆ กับหลินฮุ่ย!!!
Fri Oct 09, 2009 1:44 pm by สก๊อยผ่า
» มีอะไรมาให้เล่นอีกแล้ว(เกมสร้างสถานะการณ์)
Thu Sep 03, 2009 12:14 pm by Parakan
» อยากถามวิธีใช้ถุงพลาสติก
Sun Aug 09, 2009 2:34 am by Admin
» Xnac€hecklist-ใครทำชีทหายมาอ่านได้ที่นี่
Sat Aug 08, 2009 9:08 pm by Admin
» อยากไปเที่ยวทะเลอีกอ่ะ
Fri Jul 31, 2009 1:47 pm by Admin
» มีรูปให้ดู
Thu Jul 30, 2009 7:39 pm by SoHandsome