java applet program

cashier system

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 4048 Views - Last Post: 04 August 2007 - 12:47 PM Rate Topic: -----

#16 zedenaka  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 04-July 07

Re: java applet program

Posted 04 August 2007 - 10:00 AM

the program works but you see i can't do that cause according to our prof the output should be.....

we can input any number in any field... what i mean is there is an option that i can only choose one,two,three or four books(to check/choose)..... so what you are saying will not work for the program....

can u give me a better solution/code for this.

my head is turning upside down.

are you available in the evening??? cause its 1 am here in the philippines .... and i'm kinda sleepy... hehehe.. if you dont mind

This post has been edited by zedenaka: 04 August 2007 - 10:03 AM

Was This Post Helpful? 0
  • +
  • -

#17 PennyBoki  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 55
  • View blog
  • Posts: 2,345
  • Joined: 11-December 06

Re: java applet program

Posted 04 August 2007 - 10:06 AM

View Postzedenaka, on 4 Aug, 2007 - 10:00 AM, said:

the program works but you see i can't do that cause according to our prof the output should be.....

we can input any number in any field... what i mean is there is an option that i can only choose one,two,three or four books(to check/choose)..... so what you are saying will not work for the program....

can u give me a better solution/code for this.

my head is turning upside down.


Exactly my point zedenaka, therefore you should check every textfield if it has value,
if there is a value then parse it if there isn't then set the integer variable that corresponds with the field to 1.

You misunderstood me here:

Quote

this way it only works when the four fields are filled

never mind this and try as I tell you
Was This Post Helpful? 0
  • +
  • -

#18 zedenaka  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 04-July 07

Re: java applet program

Posted 04 August 2007 - 10:20 AM

i've already got it!!! :) tkanks a lot... i've done it like this
if(hpBox.getState())
		{
		qty1=Integer.parseInt(qty1Txt.getText());
		tp1=qty1*up1;
		tp1Lbl.setText("P " +tp1);
		}
		else
		{
		qty1=0;
		tp1=qty1*up1;
		tp1Lbl.setText("P " +tp1);
		}



but i still have one problem... when i click the reset button all the fields should be erased/removed and the checkbox/group should also be empty cause i set it to false... but the checkbox group isnt empty.... do you know why??
	
	if(arg=="RESET")
		
	{
		hpBox.setState(false);
		lotrBox.setState(false);
		aiwBox.setState(false);
		pBox.setState(false);
		qty1Txt.setText(" ");
		qty2Txt.setText(" ");
		qty3Txt.setText(" ");
		qty4Txt.setText(" ");
		tp1Lbl.setText("P");
		tp2Lbl.setText("P");
		tp3Lbl.setText("P");
		tp4Lbl.setText("P");
		cash.setState(false);
		twop.setState(false);
		threep.setState(false);
		tqLbl.setText("Total Quantity:");
		priceLbl.setText("Price:");
		interestLbl.setText("Interest:");
		taLbl.setText("Total Amount:");
		
	}


Was This Post Helpful? 0
  • +
  • -

#19 PennyBoki  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 55
  • View blog
  • Posts: 2,345
  • Joined: 11-December 06

Re: java applet program

Posted 04 August 2007 - 10:24 AM

yes try instead of if(arg=="RESET")
to put this
if(arg.equals("RESET"))
Was This Post Helpful? 0
  • +
  • -

#20 zedenaka  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 04-July 07

Re: java applet program

Posted 04 August 2007 - 10:28 AM

hmmmmmmmm it still wont work.... the selection i've made with the checkbox group isn't removed...
Was This Post Helpful? 0
  • +
  • -

#21 PennyBoki  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 55
  • View blog
  • Posts: 2,345
  • Joined: 11-December 06

Re: java applet program

Posted 04 August 2007 - 10:30 AM

ok here we go again post the new code all of it.
Was This Post Helpful? 0
  • +
  • -

#22 zedenaka  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 04-July 07

Re: java applet program

Posted 04 August 2007 - 10:43 AM

sorry for this.... am i getting you mad???
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class mp2f extends Applet implements ActionListener,ItemListener

{
	int a;
	
	Label booksLbl = new Label("Books Available:");	
	Checkbox hpBox = new Checkbox("Harry Potter",false);
	Checkbox lotrBox = new Checkbox("Lord of the Rings",false);
	Checkbox aiwBox = new Checkbox("Alice in Wonderland",false);
	Checkbox pBox = new Checkbox("Prince",false);

	Label qtyLbl = new Label("Quantity");
	TextField qty1Txt = new TextField(10);
	TextField qty2Txt = new TextField(10);
	TextField qty3Txt = new TextField(10);
	TextField qty4Txt = new TextField(10);

	Label upLbl = new Label("Unit Price:");
	Label up1Lbl = new Label("P 1500");
	Label up2Lbl = new Label("P 1000");
	Label up3Lbl = new Label("P 800");
	Label up4Lbl = new Label("P 1600");

	Label tpLbl = new Label("Total Price");
	Label tp1Lbl = new Label("");
	Label tp2Lbl = new Label("");
	Label tp3Lbl = new Label("");
	Label tp4Lbl = new Label("");
	
	Label mopLbl = new Label("Mode of Payment:");
	CheckboxGroup optGroup = new CheckboxGroup();
	 	Checkbox cash = new Checkbox("Cash",false,optGroup);
		Checkbox twop = new Checkbox("2 Payments(10%)",false,optGroup);
	 	Checkbox threep = new Checkbox("3 Payments(20%)",false,optGroup);

	Label tqLbl = new Label("Total Quantity:");

	Label priceLbl = new Label("Price:");

	Label interestLbl = new Label("Interest:");

	Label taLbl = new Label("Total Amount:");	

	Button okButton = new Button("OK");

	 Button resetButton = new Button("RESET");
		
	 
	 public void init()

	 {

	add(booksLbl);
	add(hpBox);
	hpBox.addItemListener(this);
	add(lotrBox);
	lotrBox.addItemListener(this);
	add(aiwBox);
	aiwBox.addItemListener(this);
	add(pBox);
	pBox.addItemListener(this);

	add(qtyLbl);
	add(qty1Txt);	
	add(qty2Txt);
	add(qty3Txt);
	add(qty4Txt);

	add(upLbl);
	add(up1Lbl);
	add(up2Lbl);
	add(up3Lbl);
	add(up4Lbl);

	add(tpLbl);
	add(tp1Lbl);
	add(tp2Lbl);
	add(tp3Lbl);
	add(tp4Lbl);
	

	add(mopLbl);	
	add(cash);
	cash.addItemListener(this);
	add(twop);
	twop.addItemListener(this);
	add(threep);
	threep.addItemListener(this);
	
	add(tqLbl);

	add(priceLbl);

	add(interestLbl);

	add(okButton);
	okButton.addActionListener(this);
	add(resetButton);
	resetButton.addActionListener(this);	
		  

	 }

	 public void itemStateChanged(ItemEvent e)

	 {
	if(cash.getState())
	a=1;

	if(twop.getState())
	a=2;

	if(threep.getState())
	a=3;
	 }

 

	 public void actionPerformed(ActionEvent e)

	 {
	String arg;
	
	int tq,price,up1=1500,up2=1000,up3=800,up4=1600,qty1,qty2,qty3,qty4,tp1=0,tp2=0,tp3=0,tp4=0;
	double interest=0,ta;
	
	arg=e.getActionCommand();	

	if(arg.equals("OK"))
	{
		if(hpBox.getState())
		{
		qty1=Integer.parseInt(qty1Txt.getText());
		tp1=qty1*up1;
		tp1Lbl.setText("P " +tp1);
		}
		else
		{
		qty1=0;
		tp1=qty1*up1;
		tp1Lbl.setText("P " +tp1);
		}
		
		if(lotrBox.getState())
		{
		qty2=Integer.parseInt(qty2Txt.getText());
		tp2=qty2*up2;	
		tp2Lbl.setText("P " +tp2);
		}
		else
		{
		qty2=0;
		tp2=qty2*up2;
		tp2Lbl.setText("P " +tp2);
		}

		if(aiwBox.getState())
		{
		qty3=Integer.parseInt(qty3Txt.getText());
		tp3=qty3*up3;
		tp3Lbl.setText("P " +tp3);
		}
		else
		{
		qty3=0;
		tp3=qty3*up3;
		tp3Lbl.setText("P " +tp3);
		}

		if(pBox.getState())
		{
		qty4=Integer.parseInt(qty4Txt.getText());
		tp4=qty4*up4;			
		tp4Lbl.setText("P " +tp4);	
		}
		else
		{
		qty4=0;
		tp4=qty4*up4;
		tp4Lbl.setText("P " +tp4);
		}
		

		if(a==1)
		{
		tq=(qty1) + (qty2) + (qty3) + (qty4);
		tqLbl.setText("Total Quantity: "+tq);

		price=(tp1) + (tp2) + (tp3) + (tp4);
		priceLbl.setText("Price: "+price);

		interestLbl.setText("Interest: 0");

		ta=price+interest;
		taLbl.setText("Total Amount: "+ta);
		}
		
	
		if(a==2)
		{
		tq=(qty1) + (qty2) + (qty3) + (qty4);
		tqLbl.setText("Total Quantity: "+tq);
		

		price=(tp1) + (tp2) + (tp3) + (tp4);
		priceLbl.setText("Price: "+price);
	
		interest=(price) * 0.1;
		interestLbl.setText("Interest: "+interest);

		ta=price+interest;
		taLbl.setText("Total Amount: "+ta);
		}

		if(a==3)
		{
		tq=(qty1) + (qty2) + (qty3) + (qty4);
		tqLbl.setText("Total Quantity: "+tq);

		price=(tp1) + (tp2) + (tp3) + (tp4);
		priceLbl.setText("Price: "+price);

		interest=(price) * 0.2;
		interestLbl.setText("Interest: "+interest);

		ta=price+interest;
		taLbl.setText("Total Amount: "+ta);
		}
	}
	
	if(arg.equals("RESET"))
		
	{
		hpBox.setState(false);
		lotrBox.setState(false);
		aiwBox.setState(false);
		pBox.setState(false);
		qty1Txt.setText(" ");
		qty2Txt.setText(" ");
		qty3Txt.setText(" ");
		qty4Txt.setText(" ");
		tp1Lbl.setText("P");
		tp2Lbl.setText("P");
		tp3Lbl.setText("P");
		tp4Lbl.setText("P");
		cash.setState(false);
		twop.setState(false);
		threep.setState(false);
		tqLbl.setText("Total Quantity:");
		priceLbl.setText("Price:");
		interestLbl.setText("Interest:");
		taLbl.setText("Total Amount:");
		
	}
	 }
}


Was This Post Helpful? 0
  • +
  • -

#23 PennyBoki  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 55
  • View blog
  • Posts: 2,345
  • Joined: 11-December 06

Re: java applet program

Posted 04 August 2007 - 12:47 PM

OK here is the code:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class mp2f extends Applet implements ActionListener,ItemListener

{
	int a;
	
	Label booksLbl = new Label("Books Available:");	
	Checkbox hpBox = new Checkbox("Harry Potter",false);
	Checkbox lotrBox = new Checkbox("Lord of the Rings",false);
	Checkbox aiwBox = new Checkbox("Alice in Wonderland",false);
	Checkbox pBox = new Checkbox("Prince",false);

	Label qtyLbl = new Label("Quantity");
	TextField qty1Txt = new TextField(10);
	TextField qty2Txt = new TextField(10);
	TextField qty3Txt = new TextField(10);
	TextField qty4Txt = new TextField(10);

	Label upLbl = new Label("Unit Price:");
	Label up1Lbl = new Label("P 1500");
	Label up2Lbl = new Label("P 1000");
	Label up3Lbl = new Label("P 800");
	Label up4Lbl = new Label("P 1600");

	Label tpLbl = new Label("Total Price");
	Label tp1Lbl = new Label("");
	Label tp2Lbl = new Label("");
	Label tp3Lbl = new Label("");
	Label tp4Lbl = new Label("");
	
	Label mopLbl = new Label("Mode of Payment:");
	CheckboxGroup optGroup = new CheckboxGroup();
		 Checkbox cash = new Checkbox("Cash",false,optGroup);
		Checkbox twop = new Checkbox("2 Payments(10%)",false,optGroup);
		 Checkbox threep = new Checkbox("3 Payments(20%)",false,optGroup);

	Label tqLbl = new Label("Total Quantity:");

	Label priceLbl = new Label("Price:");

	Label interestLbl = new Label("Interest:");

	Label taLbl = new Label("Total Amount:");	

	Button okButton = new Button("OK");

	 Button resetButton = new Button("RESET");
	   int tq,price,up1=1500,up2=1000,up3=800,up4=1600,qty1,qty2,qty3,qty4,tp1=0,tp2=0,tp3=
0,tp4=0;
	double interest=0,ta; 
	 
	 public void init()

	 {
	setLayout(new GridLayout(6,5));
	add(booksLbl);
	add(hpBox);
	hpBox.addItemListener(this);
	add(lotrBox);
	lotrBox.addItemListener(this);
	add(aiwBox);
	aiwBox.addItemListener(this);
	add(pBox);
	pBox.addItemListener(this);

	add(qtyLbl);
	add(qty1Txt);	
	add(qty2Txt);
	add(qty3Txt);
	add(qty4Txt);

	add(upLbl);
	add(up1Lbl);
	add(up2Lbl);
	add(up3Lbl);
	add(up4Lbl);

	add(tpLbl);
	add(tp1Lbl);
	add(tp2Lbl);
	add(tp3Lbl);
	add(tp4Lbl);
	

	add(mopLbl);	
	add(cash);
	cash.addItemListener(this);
	add(twop);
	twop.addItemListener(this);
	add(threep);
	threep.addItemListener(this);
	
	add(tqLbl);

	add(priceLbl);

	add(interestLbl);

	add(okButton);
	okButton.addActionListener(this);
	add(resetButton);
	resetButton.addActionListener(this);	
		  

	 }

	 public void itemStateChanged(ItemEvent e)

	 {
	if(cash.getState())
	a=1;
	else
	if(twop.getState())
	a=2;
	else
	if(threep.getState())
	a=3;
	 }



	 public void actionPerformed(ActionEvent e)

	 {
	String arg;
	
	
	
	arg=e.getActionCommand();	

	if(e.getSource()==okButton)
	{
		
		
			if(hpBox.getState())
			{
			qty1=Integer.parseInt(qty1Txt.getText());
			tp1=qty1*up1;
			tp1Lbl.setText("P " +tp1);
			}
			
			else
			{
			
			tp1=0;
			tp1Lbl.setText("P " +tp1);
			}
		
		
		
		
			if(lotrBox.getState())
			{
			qty2=Integer.parseInt(qty2Txt.getText());
			tp2=qty2*up2;	
			tp2Lbl.setText("P " +tp2);
			}
			
			else
			{
			
			tp2=0;
			tp2Lbl.setText("P " +tp2);
			}
	   	 
		

	  
			if(aiwBox.getState())
			{
			qty3=Integer.parseInt(qty3Txt.getText());
			tp3=qty3*up3;
			tp3Lbl.setText("P " +tp3);
			}
			else
			{
			
			tp3=0;
			tp3Lbl.setText("P " +tp3);
			}
		

		
			if(pBox.getState())
			{
			qty4=Integer.parseInt(qty4Txt.getText());
			tp4=qty4*up4;			
			tp4Lbl.setText("P " +tp4);	
			}
			else
			{
			
			tp4=0;
			tp4Lbl.setText("P " +tp4);
			}
		

		if(a==1)
		{
		tq=(qty1) + (qty2) + (qty3) + (qty4);
		tqLbl.setText("Total Quantity: "+tq);

		price=(tp1) + (tp2) + (tp3) + (tp4);
		priceLbl.setText("Price: "+price);

		interestLbl.setText("Interest: 0");

		ta=price+interest;
		taLbl.setText("Total Amount: "+ta);
		}
		
	
	   else if(a==2)
		{
		tq=(qty1) + (qty2) + (qty3) + (qty4);
		tqLbl.setText("Total Quantity: "+tq);
		

		price=(tp1) + (tp2) + (tp3) + (tp4);
		priceLbl.setText("Price: "+price);
	
		interest=(price) * 0.1;
		interestLbl.setText("Interest: "+interest);

		ta=price+interest;
		taLbl.setText("Total Amount: "+ta);
		}

		else if(a==3)
		{
		tq=(qty1) + (qty2) + (qty3) + (qty4);
		tqLbl.setText("Total Quantity: "+tq);

		price=(tp1) + (tp2) + (tp3) + (tp4);
		priceLbl.setText("Price: "+price);

		interest=(price) * 0.2;
		interestLbl.setText("Interest: "+interest);

		ta=price+interest;
		taLbl.setText("Total Amount: "+ta);
		}
		repaint();
	}
	
	else if(e.getSource()==resetButton)	
	{
		hpBox.setState(false);
		lotrBox.setState(false);
		aiwBox.setState(false);
		pBox.setState(false);
		qty1Txt.setText("");
		qty2Txt.setText("");
		qty3Txt.setText("");
		qty4Txt.setText("");
		tp1Lbl.setText("P");
		tp2Lbl.setText("P");
		tp3Lbl.setText("P");
		tp4Lbl.setText("P");
	   // cash.setState(false);
	  //  twop.setState(false);
	   // threep.setState(false);
		tqLbl.setText("Total Quantity:");
		priceLbl.setText("Price:");
		interestLbl.setText("Interest:");
		taLbl.setText("Total Amount: ");
		//a=1;
		tq=0;
		price=0;
		up1=1500;
		up2=1000;
		up3=800;
		up4=1600;
		qty1=0;
		qty2=0;
		qty3=0;
		qty4=0;
		tp1=0;
		tp2=0;
		tp3=0;
		tp4=0;
		repaint();
	}
   }
}

here is the applet code with the right dimensions
<html>
<applet code="mp2f.class" height=200 width=600>
</applet>
</html> 

and for the record I'm not mad, even if I was that's my problem not yours, so please tell me it works ...
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2