Results 1 to 2 of 2
  1. #1
    NickkicN is offline Member
    Join Date
    Aug 2008
    Posts
    5
    Rep Power
    0

    Exclamation code HELP URGENT

    Dear viewer,

    I need some help with this code, which is for a soda vending machine. Hope someone can help it is urgent. The problem is I cant view the applet. I do not need to know how to view an applet but i want the corrections in the applet.

    MAny thanks


    /**
    * @(#)vendingmac.java
    *
    *
    * @author
    * @version 1.00 2008/8/12
    */


    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.applet.*;

    public class vendingmac extends Applet implements ActionListener, ItemListener
    {

    // String[] chsizeitems = {"10 oz", "16 oz"};




    Label lblinsertcoins = new Label();
    Button btntencents = new Button();
    Button btntwentycents = new Button();
    Button btnfiftycents = new Button();
    Button btnrmone = new Button();
    Button btnrmfive = new Button();
    Button btnrmten = new Button();
    Label lblavailability = new Label();
    Label lblflavor = new Label();
    Button btncola = new Button();
    Button btnorange = new Button();
    Button btnlime = new Button();
    Label lbltype = new Label();
    Label lblsize = new Label();
    Choice chsize;
    CheckboxGroup chgroup=new CheckboxGroup();
    Checkbox chkdiet = new Checkbox("Diet",chgroup, false);
    Checkbox chkregular = new Checkbox("Regular",chgroup, false);
    //Checkbox chkregular = new Checkbox();
    Label lbldeposited = new Label();
    Label lbltotal = new Label();
    Label lblchange = new Label();
    TextField txtdeposited = new TextField();
    TextField txttotal = new TextField();
    TextField txtchange = new TextField();
    Button btnreturn = new Button();
    Button btnpurchase = new Button();
    Label lblcommenttop = new Label();
    Button btncheck = new Button();
    Button btnconfirm = new Button();


    double iMoney=0;
    double dSize=0, dTotal=0, dBalance=0, dPrice=0;
    String display,strFla,strSiz,strType, strTyp, take, Qty;
    int imColaReg=3, imColaDiet = 3, ilColaReg=3, ilColaDiet = 3, imOrgReg=3, imOrgDiet = 3, ilOrgReg=3, ilOrgDiet = 3, imLimeReg=3,ilLimeReg=3;
    int iflag = 1;
    public void itemStateChanged(ItemEvent e){
    }

    public void init() {
    //chsize = new Choice(chsizeitems);
    add(chsize);
    chsize.setBounds(630, 190, 100, 20);
    chsize.add("10 oz");
    chsize.add("16 oz");

    setBackground(new Color(204, 255, 204));
    setLayout(null);

    lblinsertcoins.setFont(new Font("Dialog", 0, 14));
    lblinsertcoins.setText(" Insert coins");
    add(lblinsertcoins);
    lblinsertcoins.setBounds(10, 80, 90, 23);

    btntencents.setLabel("10 cents");
    add(btntencents);
    btntencents.setBounds(20, 110, 60, 24);

    btntwentycents.setLabel("20 cents");
    add(btntwentycents);
    btntwentycents.setBounds(20, 140, 60, 24);

    btnfiftycents.setLabel("50 cents");
    add(btnfiftycents);
    btnfiftycents.setBounds(20, 170, 60, 24);

    btnrmone.setLabel("RM 1.00");
    add(btnrmone);
    btnrmone.setBounds(20, 200, 60, 24);

    btnrmfive.setLabel("RM 5.00");
    add(btnrmfive);
    btnrmfive.setBounds(20, 230, 60, 24);

    btnrmten.setLabel("RM 10.00");
    add(btnrmten);
    btnrmten.setBounds(20, 260, 60, 24);

    lblavailability.setFont(new Font("Dialog", 0, 14));
    lblavailability.setText("Availability");
    add(lblavailability);
    lblavailability.setBounds(220, 80, 70, 23);



    lblflavor.setFont(new Font("Dialog", 0, 14));
    lblflavor.setText("Flavor");
    add(lblflavor);
    lblflavor.setBounds(440, 80, 44, 23);

    btncola.setLabel("COLA");
    add(btncola);
    btncola.setBounds(430, 140, 70, 24);

    btnorange.setLabel("ORANGE");
    add(btnorange);
    btnorange.setBounds(430, 190, 70, 24);

    btnlime.setLabel("LIME");
    add(btnlime);
    btnlime.setBounds(430, 240, 70, 24);

    lbltype.setFont(new Font("Dialog", 0, 14));
    lbltype.setText("Type");
    add(lbltype);
    lbltype.setBounds(540, 80, 36, 23);

    lblsize.setFont(new Font("Dialog", 0, 14));
    lblsize.setText("Size");
    add(lblsize);
    lblsize.setBounds(660, 80, 30, 23);


    //chkdiet.setLabel("Diet");
    add(chkdiet);
    chkdiet.setBounds(540, 220, 48, 20);

    //chkregular.setLabel("Regular");
    add(chkregular);
    chkregular.setBounds(540, 180, 70, 20);

    lbldeposited.setFont(new Font("Dialog", 0, 14));
    lbldeposited.setText("Deposited");
    add(lbldeposited);
    lbldeposited.setBounds(140, 300, 70, 23);

    lbltotal.setFont(new Font("Dialog", 0, 14));
    lbltotal.setText("Total");
    add(lbltotal);
    lbltotal.setBounds(140, 340, 36, 23);

    lblchange.setFont(new Font("Dialog", 0, 14));
    lblchange.setText("Change");
    add(lblchange);
    lblchange.setBounds(140, 380, 54, 23);

    txtdeposited.setText("textField11");
    add(txtdeposited);
    txtdeposited.setBounds(230, 300, 110, 20);

    txttotal.setText("textField12");
    add(txttotal);
    txttotal.setBounds(230, 340, 110, 20);

    txtchange.setText("textField13");
    add(txtchange);
    txtchange.setBounds(230, 380, 110, 20);

    btnreturn.setLabel("Return");
    add(btnreturn);
    btnreturn.setBounds(370, 340, 140, 24);

    btnpurchase.setLabel("Purchase");
    add(btnpurchase);
    btnpurchase.setBounds(370, 380, 140, 24);

    lblcommenttop.setFont(new Font("Berlin Sans FB Demi", 0, 24));
    lblcommenttop.setText("Vending Machine");
    add(lblcommenttop);
    lblcommenttop.setBounds(270, 20, 190, 32);

    btncheck.setLabel("Check ");
    add(btncheck);
    btncheck.setBounds(177, 164, 160, 30);

    btnconfirm.setLabel("Confirm");
    add(btnconfirm);
    btnconfirm.setBounds(370, 300, 140, 24);


    //Actionlisteners

    btntencents.addActionListener(this);
    btntwentycents.addActionListener(this);
    btnfiftycents.addActionListener(this);
    btnrmone.addActionListener(this);
    btnrmfive.addActionListener(this);
    btnrmten.addActionListener(this);
    btncola.addActionListener(this);
    btnorange.addActionListener(this);
    btnlime.addActionListener(this);
    chkdiet.addItemListener(this);
    chkregular.addItemListener(this);
    chsize.addItemListener(this);
    btnreturn.addActionListener(this);
    btnpurchase.addActionListener(this);
    btncheck .addActionListener(this);
    btnconfirm.addActionListener(this);

    }

    public void actionPerformed(ActionEvent e) {




    if (e.getSource()==btntencents){ //Displaying the summation in a TextBox
    iMoney = iMoney+.10;
    txtdeposited.setText(iMoney+"");
    }

    if (e.getSource()==btntwentycents){ //Displaying the summation in a TextBox
    iMoney = iMoney+.20;
    txtdeposited.setText(iMoney+"");
    }

    if (e.getSource()==btnfiftycents){ //Displaying the summation in a TextBox
    iMoney = iMoney+.50;
    txtdeposited.setText(iMoney+"");
    }

    if (e.getSource()==btnrmone){ //Displaying the summation in a TextBox
    iMoney = iMoney+1;
    txtdeposited.setText(iMoney+"");
    }

    if (e.getSource()==btnrmfive){ //Displaying the summation in a TextBox
    iMoney = iMoney+2;
    txtdeposited.setText(iMoney+"");
    }

    if (e.getSource()==btnrmten){ //Displaying the summation in a TextBox
    iMoney = iMoney+5;
    txtdeposited.setText(iMoney+"");
    }


    if (e.getSource()==btnpurchase){ // *** Take Soda Button ***
    take = "Thank You For Using The Automated Soda Machine. The Total Cost Is Rs " +dTotal + " And Your Balance Is Rs " + dBalance + ". We Hope You Enjoy Your Drink! Have A Nice Day!";
    JOptionPane.showMessageDialog(null,take,"Automated Soda Machine - Beta",JOptionPane.INFORMATION_MESSAGE);

    }

    if (e.getSource()==btncheck){ // *** View Quantities Button ***
    viewQuantities();
    }

    if (e.getSource()==btncola){
    //cboType.setEnabled(true);
    }

    if (e.getSource()==btnorange){
    //cboType.setEnabled(true);
    }

    if (e.getSource()==btnlime){
    chkregular.setEnabled(true);
    chkdiet.setEnabled(false);
    //my diet check box shud disappear

    }

    if (e.getSource()==btnreturn){
    resetOrder();
    }




    //very important

    if(e.getSource()==btnconfirm){

    if ((e.getSource()==btncola) && (chkregular.getState()==true) && ((String)chsize.getSelectedItem()=="10 oz")){

    if (imColaReg == 0){
    JOptionPane.showMessageDialog(null,"Sorry! The Soda Is Out Of Stock!","Automated Soda Machine V1.0",JOptionPane.INFORMATION_MESSAGE);
    iflag = 0;
    }

    else{
    iflag = 1;
    imColaReg = imColaReg - 1;
    strFla = "COLA";
    dSize = 1.20;
    strSiz = "10 oz";
    strTyp = "Regular";
    }

    }

    if ((e.getSource()==btncola) && ((String)chsize.getSelectedItem()=="10 oz") && (chkdiet.getState()==true)){

    if (imColaDiet == 0){
    JOptionPane.showMessageDialog(null,"Sorry! The Soda Is Out Of Stock!","Automated Soda Machine V1.0",JOptionPane.INFORMATION_MESSAGE);
    iflag = 0;
    }

    else{
    iflag = 1;
    imColaDiet = imColaDiet - 1;
    strFla = "COLA";
    dSize = 1.20;
    strSiz = "10 oz";
    strTyp = "Diet";
    }

    }

    if ((e.getSource()==btncola) && ((String)chsize.getSelectedItem()=="16 oz") && (chkregular.getState()==true)){

    if (ilColaReg == 0){
    JOptionPane.showMessageDialog(null,"Sorry! The Soda Is Out Of Stock!","Automated Soda Machine V1.0",JOptionPane.INFORMATION_MESSAGE);
    iflag = 0;
    }

    else{
    iflag = 1;
    ilColaReg = ilColaReg - 1;
    strFla = "COLA";
    dSize = 1.80;
    strSiz = "16 oz";
    strTyp = "Regular";
    }

    }

    if ((e.getSource()==btncola) && ((String)chsize.getSelectedItem()=="16 oz") && (chkdiet.getState()==true)){

    if (ilColaDiet == 0){
    JOptionPane.showMessageDialog(null,"Sorry! The Soda Is Out Of Stock!","Automated Soda Machine V1.0",JOptionPane.INFORMATION_MESSAGE);
    iflag = 0;
    }

    else{
    iflag = 1;
    ilColaDiet = ilColaDiet - 1;
    strFla = "COLA";
    dSize = 1.80;
    strSiz = "16 oz";
    strTyp = "Diet";
    }

    }

    if ((e.getSource()==btnorange) && ((String)chsize.getSelectedItem()=="10 oz") && (chkregular.getState()==true)){

    if (imOrgReg == 0){
    JOptionPane.showMessageDialog(null,"Sorry! The Soda Is Out Of Stock!","Automated Soda Machine V1.0",JOptionPane.INFORMATION_MESSAGE);
    iflag = 0;
    }

    else{
    iflag = 1;
    imOrgReg = imOrgReg - 1;
    strFla = "ORANGE";
    dSize = 1.20;
    strSiz = "10 0z";
    strTyp = "Regular";
    }

    }

    if ((e.getSource()==btnorange) && ((String)chsize.getSelectedItem()=="10 oz") && (chkdiet.getState()==true)){

    if (imOrgDiet == 0){
    JOptionPane.showMessageDialog(null,"Sorry! The Soda Is Out Of Stock!","Automated Soda Machine V1.0",JOptionPane.INFORMATION_MESSAGE);
    iflag = 0;
    }

    else{
    iflag = 1;
    imOrgDiet = imOrgDiet - 1;
    strFla = "ORANGE";
    dSize = 1.20;
    strSiz = "10 oz";
    strTyp = "Diet";
    }

    }

    if ((e.getSource()==btnorange) && ((String)chsize.getSelectedItem()=="16 oz") && (chkregular.getState()==true)){

    if (ilOrgReg == 0){
    JOptionPane.showMessageDialog(null,"Sorry! The Soda Is Out Of Stock!","Automated Soda Machine V1.0",JOptionPane.INFORMATION_MESSAGE);
    iflag = 0;
    }

    else{
    iflag = 1;
    ilOrgReg = ilOrgReg - 1;
    strFla = "ORANGE";
    dSize = 1.80;
    strSiz = "16 0z";
    strTyp = "Regular";
    }

    }

    if ((e.getSource()==btnorange) && ((String)chsize.getSelectedItem()=="16 oz") && (chkdiet.getState()==true)){

    if (ilOrgDiet == 0){
    JOptionPane.showMessageDialog(null,"Sorry! The Soda Is Out Of Stock!","Automated Soda Machine V1.0",JOptionPane.INFORMATION_MESSAGE);
    iflag = 0;
    }

    else{
    iflag = 1;
    ilOrgDiet = ilOrgDiet - 1;
    strFla = "ORANGE";
    dSize = 1.80;
    strSiz = "16 oz";
    strTyp = "Diet";
    }

    }

    if ((e.getSource()==btnlime) && ((String)chsize.getSelectedItem()=="10 oz") && (chkregular.getState()==true)){

    if (imLimeReg == 0){
    JOptionPane.showMessageDialog(null,"Sorry! The Soda Is Out Of Stock!","Automated Soda Machine V1.0",JOptionPane.INFORMATION_MESSAGE);
    iflag = 0;
    }

    else{
    iflag = 1;
    imLimeReg = imLimeReg - 1;
    strFla = "LIME";
    dSize = 1.20;
    strSiz = "10 oz";
    strTyp = "Regular";
    }

    }

    if ((e.getSource()==btnlime) && ((String)chsize.getSelectedItem()=="16 oz") && (chkregular.getState()==true)){

    if (ilLimeReg == 0){
    JOptionPane.showMessageDialog(null,"Sorry! The Soda Is Out Of Stock!","Automated Soda Machine V1.0",JOptionPane.INFORMATION_MESSAGE);
    iflag = 0;
    }

    else{
    iflag = 1;
    ilLimeReg = ilLimeReg - 1;
    strFla = "LIME";
    dSize = 1.80;
    strSiz = "16 oz";
    strTyp = "Regular";
    }

    }

    if (iflag == 1){

    dPrice = new Double(txtdeposited.getText()).doubleValue();

    if (dPrice < dSize){
    JOptionPane.showMessageDialog(null,"Sorry, Your Cash Deposists Are Insufficient!","Automated Soda Machine V1.0",JOptionPane.INFORMATION_MESSAGE);
    //resetQuantities(e);
    System.exit(0);
    }

    else{
    dTotal = dTotal+dSize;
    }

    if (dPrice <= dTotal){
    JOptionPane.showMessageDialog(null,"Sorry, Your Cash Deposists Are Insufficient!","Automated Soda Machine V1.0",JOptionPane.INFORMATION_MESSAGE);
    dTotal = dTotal - dSize;
    //resetQuantities(e);
    System.exit(0);
    }
    else{
    sodaDetails();
    }
    }
    }

    }




    //part 3

    public void viewQuantities(){
    Qty = " Total Quantity\n\n";
    Qty = Qty + "Cola 10 oz Regular : " + imColaReg + "\n";
    Qty = Qty + "Cola 10 oz Diet : " + imColaDiet + "\n";
    Qty = Qty + "Cola 16 oz Regular : " + ilColaReg + "\n";
    Qty = Qty + "Cola 16 oz Diet : " + ilColaDiet + "\n";
    Qty = Qty + "Orange 10 oz Regular : " + imOrgReg + "\n";
    Qty = Qty + "Orange 10 oz Diet : " + imOrgDiet + "\n";
    Qty = Qty + "Orange 10 oz Regular : " + ilOrgReg + "\n";
    Qty = Qty + "Orange 10 oz Diet : " + ilOrgDiet + "\n";
    Qty = Qty + "Lime 10 oz Regular : " + imLimeReg + "\n";
    Qty = Qty + "Lime 16 oz Regular : " + ilLimeReg + "\n";
    JOptionPane.showMessageDialog(null,Qty,"Automated Soda Machine V1.0",JOptionPane.INFORMATION_MESSAGE);
    }

    public void resetOrder(){
    dSize=0;
    dTotal=0;
    imColaReg=3;
    imColaDiet = 3;
    ilColaReg=3;
    ilColaDiet = 3;
    imOrgReg=3;
    imOrgDiet = 3;
    ilOrgReg=3;
    ilOrgDiet = 3;
    imLimeReg=3;
    ilLimeReg=3;
    dBalance = dPrice;
    txttotal.setText(Double.toString(dTotal));
    txtchange.setText(dPrice+"");
    JOptionPane.showMessageDialog(null,"Your Order Has Just Been Cancelled!","Automated Soda Machine V1.0",JOptionPane.INFORMATION_MESSAGE);
    }

    public void sodaDetails(){
    dBalance = dPrice - dTotal;
    txttotal.setText(dTotal+"");
    txtchange.setText(dBalance+"");
    display = "Thank You For Selecting Our Drink. Your Drink Details Are As Follows : \n\n";
    display = display + "Soda Flavour : " + strFla + "\n";
    display = display + "Soda Size : " + strSiz + "\n";
    display = display + "Soda Type : " + strTyp + "\n";
    JOptionPane.showMessageDialog(null,display,"Automa ted Soda Machine V1.0",JOptionPane.INFORMATION_MESSAGE);
    }



    //part 4

    public void resetQuantities(ActionEvent e){

    if ((e.getSource()==btncola) && (chkregular.getState()==true) && ((String)chsize.getSelectedItem()=="10 oz")){
    imColaReg = imColaReg + 1;
    }

    if ((e.getSource()==btncola) && ((String)chsize.getSelectedItem()=="10 oz") && (chkdiet.getState()==true)){
    imColaDiet = imColaDiet + 1;
    }

    if ((e.getSource()==btncola) && ((String)chsize.getSelectedItem()=="16 oz") && (chkregular.getState()==true)){
    ilColaReg = ilColaReg + 1;
    }

    if ((e.getSource()==btncola) && ((String)chsize.getSelectedItem()=="16 oz") && (chkdiet.getState()==true)){
    ilColaDiet = ilColaDiet + 1;
    }

    if ((e.getSource()==btnorange) && ((String)chsize.getSelectedItem()=="10 oz") && (chkregular.getState()==true)){
    imOrgReg = imOrgReg + 1;
    }

    if ((e.getSource()==btnorange) && ((String)chsize.getSelectedItem()=="10 oz") && (chkdiet.getState()==true)){
    imOrgDiet = imOrgDiet + 1;
    }

    if ((e.getSource()==btnorange) && ((String)chsize.getSelectedItem()=="16 oz") && (chkregular.getState()==true)){
    ilOrgReg = ilOrgReg + 1;
    }

    if ((e.getSource()==btnorange) && ((String)chsize.getSelectedItem()=="16 oz") && (chkdiet.getState()==true)){
    ilOrgDiet = ilOrgDiet + 1;
    }

    if ((e.getSource()==btnlime) && ((String)chsize.getSelectedItem()=="10 oz") && (chkregular.getState()==true)){
    imLimeReg = imLimeReg + 1;
    }

    if ((e.getSource()==btnlime) && ((String)chsize.getSelectedItem()=="16 oz") && (chkregular.getState()==true)){
    ilLimeReg = ilLimeReg + 1;
    }
    }
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    i want the corrections in the applet.
    What is the problem that needs correction?
    If there are errors, copy and paste them here.
    There is too much code here to look at. Can you make a smaller program to demonstrate the problem.

Similar Threads

  1. Urgent small code
    By karingulanagaraj in forum New To Java
    Replies: 7
    Last Post: 08-11-2008, 04:11 AM
  2. Hi, need some urgent help!
    By jdark in forum New To Java
    Replies: 2
    Last Post: 04-18-2008, 06:50 AM
  3. please help urgent
    By ananas7777 in forum AWT / Swing
    Replies: 2
    Last Post: 12-25-2007, 08:30 AM
  4. Very Urgent
    By Swamipsn in forum New To Java
    Replies: 2
    Last Post: 08-01-2007, 01:56 PM
  5. Replies: 1
    Last Post: 04-26-2007, 03:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •