// Program : xyz.java
// Version : 1.0
// Author : Chris H
// Date : 16-06-2003
// Purpose : to create an internet sales website applet
// : for XYZ Computers.
import java.applet.*;
import java.awt.*;
public class xyz extends Applet
{
// Set Variables and Objects
Dimension appletSize;
double P100=285.00, P166=315.50, P200=376.90, P400=512.00;
double CDRom=60.95, Modem=45.00, Speakers=34.60, ZipDrive=194.00;
Label ProcessorLabel = new Label("Processor");
Label PeripheralLabel = new Label("Peripheral");
Label MemoLabel = new Label("Memo");
Label ClientNameLabel = new Label("Name");
Label ClientAddressLabel = new Label("Mailing Address");
Label ClientEmailLabel = new Label("E-Mail Address");
Label SystemNumberLabel = new Label("# of Systems");
Label BeforeTaxLabel = new Label("Before Tax");
Label AfterTaxLabel = new Label("After Tax");
Label TaxPayableLabel = new Label("Tax Payable");
Choice Processor = new Choice();
Choice SystemNumber = new Choice();
List Peripheral = new List(4,true);
Checkbox Cash = new Checkbox("Cash");
Checkbox Credit = new Checkbox("Credit",true);
Checkbox Check = new Checkbox("Check");
CheckboxGroup PayMethod = new CheckboxGroup();
TextArea Memo = new TextArea("Notes...",6,30);
Button Calculate = new Button("Calculate");
Button SendOrder = new Button("Send Order");
TextField ClientName = new TextField("",30);
TextField ClientAddress = new TextField("",60);
TextField ClientEmail = new TextField("",30);
Label BeforeTax = new Label("");
Label AfterTax = new Label("");
Label TaxPayable = new Label("");
public void init()
{
// Set Contents of Objects and set Size and Position of all Objects
setLayout(null);
appletSize=getSize();
Cash.setCheckboxGroup(PayMethod);
Check.setCheckboxGroup(PayMethod);
Credit.setCheckboxGroup(PayMethod);
Processor.insert("----",0);
Processor.insert("P100",1);
Processor.insert("P166",2);
Processor.insert("P200",3);
Processor.insert("P400",4);
SystemNumber.insert("--",0);
SystemNumber.insert("01",1);
SystemNumber.insert("02",2);
SystemNumber.insert("03",3);
SystemNumber.insert("04",4);
SystemNumber.insert("05",5);
SystemNumber.insert("06",6);
SystemNumber.insert("07",7);
SystemNumber.insert("08",8);
SystemNumber.insert("09",9);
SystemNumber.insert("10",10);
Peripheral.addItem("CD-Rom (16x)");
Peripheral.addItem("Modem");
Peripheral.addItem("Speakers");
Peripheral.addItem("Zip Drive");
ProcessorLabel.setLocation(40,50);
ProcessorLabel.setSize(70,20);
Processor.setLocation(120,50);
PeripheralLabel.setLocation(40,80);
PeripheralLabel.setSize(70,20);
Peripheral.setLocation(120,80);
Peripheral.setSize(120,40);
MemoLabel.setLocation(250,50);
MemoLabel.setSize(60,20);
Memo.setLocation(330,50);
Memo.setSize(200,100);
SystemNumberLabel.setLocation(40,130);
SystemNumberLabel.setSize(70,20);
SystemNumber.setLocation(120,130);
Cash.setLocation(40,260);
Cash.setSize(60,20);
Check.setLocation(105,260);
Check.setSize(60,20);
Credit.setLocation(170,260);
Credit.setSize(60,20);
Calculate.setLocation(235,260);
Calculate.setSize(80,20);
SendOrder.setLocation(320,260);
SendOrder.setSize(80,20);
BeforeTaxLabel.setLocation(40,160);
BeforeTaxLabel.setSize(70,20);
BeforeTax.setLocation(120,160);
BeforeTax.setSize(60,20);
ClientNameLabel.setLocation(200,160);
ClientNameLabel.setSize(100,20);
ClientName.setLocation(310,160);
ClientName.setSize(150,20);
AfterTaxLabel.setLocation(40,190);
AfterTaxLabel.setSize(70,20);
AfterTax.setLocation(120,190);
AfterTax.setSize(60,20);
ClientAddressLabel.setLocation(200,190);
ClientAddressLabel.setSize(100,20);
ClientAddress.setLocation(310,190);
ClientAddress.setSize(150,20);
TaxPayableLabel.setLocation(40,220);
TaxPayableLabel.setSize(70,20);
TaxPayable.setLocation(120,220);
TaxPayable.setSize(60,20);
ClientEmailLabel.setLocation(200,220);
ClientEmailLabel.setSize(100,20);
ClientEmail.setLocation(310,220);
ClientEmail.setSize(150,20);
// Display all objects to the screen
add(ClientNameLabel);
add(ClientName);
add(ClientAddressLabel);
add(ClientAddress);
add(ClientEmailLabel);
add(ClientEmail);
add(ProcessorLabel);
add(Processor);
add(PeripheralLabel);
add(Peripheral);
add(MemoLabel);
add(Memo);
add(SystemNumberLabel);
add(SystemNumber);
add(Cash);
add(Check);
add(Credit);
add(Calculate);
add(SendOrder);
add(BeforeTaxLabel);
add(BeforeTax);
add(TaxPayableLabel);
add(TaxPayable);
add(AfterTaxLabel);
add(AfterTax);
}
// Graphics Subsystem
public void paint(Graphics g)
{
g.setColor(Color.black);
g.fillRect(0,0,appletSize.width,40);
g.fillRect(0,0,30,appletSize.height);
g.drawRect(0,0,appletSize.width-1,appletSize.height-1);
g.setColor(Color.yellow);
g.fillRect(32,42,appletSize.width-35,appletSize.height-45);
g.setFont(new Font("TimesRoman", Font.BOLD, 40));
g.drawString("XYZ",5,35);
g.setColor(Color.white);
g.setFont(new Font("SansSerif", Font.BOLD, 20));
g.drawString("Computers",95,23);
}
// Events
public boolean action(Event evt, Object arg)
{
// Initilise variables for the Calculations
double TaxRate=0.10, TotalBTax=0, TotalATax=0, TaxPaid=0;
if (evt.target == Calculate)
{
int Proc=0, Multi=0;
// Determine the index values for the choice boxes
Proc=Processor.getSelectedIndex();
Multi=SystemNumber.getSelectedIndex();
// Calculations
if(Proc==1)
TotalBTax=TotalBTax+P100;
if(Proc==2)
TotalBTax=TotalBTax+P166;
if(Proc==3)
TotalBTax=TotalBTax+P200;
if(Proc==4)
TotalBTax=TotalBTax+P400;
if(Peripheral.isIndexSelected(0)==true)
TotalBTax=TotalBTax+CDRom;
if(Peripheral.isIndexSelected(1)==true)
TotalBTax=TotalBTax+Modem;
if(Peripheral.isIndexSelected(2)==true)
TotalBTax=TotalBTax+Speakers;
if(Peripheral.isIndexSelected(3)==true)
TotalBTax=TotalBTax+ZipDrive;
TotalBTax=TotalBTax*Multi;
// Final Calculations
TaxPaid=TotalBTax*TaxRate;
TotalATax=TotalBTax+TaxPaid;
// Display results
BeforeTax.setText("$"+TotalBTax);
AfterTax.setText("$"+TotalATax);
TaxPayable.setText("$"+TaxPaid);
}
return(true);
}
}