0

I've started to create a code that will design a chose applet for a cell phone company but I need to deactivate the bottom part of the applet until all the basic info is filled in then allowing the lower, choice part of the applet to be activated and choices may be made. I have no idea how to go about deactivating and activiating it back up. I'm thinking about making two seperate panels and putting all the basic info in one and all the choice stuff in another and then trying to somehow deactivate it. Does anyone have any other ideas or tips that I could try?

Here is what I have so far:

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

//--------------------------------------------------------------------------------------------------

class IllegalQuantity extends Exception   // throws when # isn't positive
{
    public Illegal Quantity()
    {
        super();
    }

    public IllegalQuantity(string s)
    {
        super(s);
    } 
}

//---------------------------------------------------------------------------------------------------

class MissingData extends Exception      //throws when empty data fields
{
    public MissingData()
    {
        super();
    }

    public MissingData(string s)
    {
        super(s);
    }
}

//----------------------------------------------------------------------------------------------------

public class Lab6Project extends Applet implements ActionListener
{
    //two string constants 
    private final string    EMPTY = new String(),
                CRLF = new String("\n");

    //textfields and textarea
    private TextField   FirstField = new TextField(20),
                MIField = new TextField(2),
                LastField = new TextField(20),
                AddressField = new TextField(25),
                CityField = new TextField(15),
                ZipField = new TextField(7),
                CostField = new TextField(10),
                PlanField = new TextField(10),
                TaxField = new TextField(10),
                FeeField = new TextField(10),
                TotalField = new TextField(10);

    private TextArea    Order = new TextArea(6, 30);     //displays all customer choices

    //dropdown menus
    private Choice      State = new Choice(),
                Rate = new Choice(),
                Model = new Choice();

    //buttons to process information
    private Button      bReset = new Button("Reset Applet"),
                bChoices = new Button("Reset Customer Choices"),
                bSubmit = new Button("Submit");

    //labels for applet
        Label       Title = new Label("Old Dime Box, TX. Cell Phones"),
                FirstName = new Label("First Name:"),
                MI = new Label("Middle Initial:"),
                LastName = new Label("Last Name:"),
                Address = new Label("Address:"),
                City = new Label("City:"),
                ZipCode = new Label("Zip Code:"),
                Cost = new Label("Phone Cost:"),
                PlanCost = new Label("Monthly Plan Cost:"),
                Tax = new Label("Tax:"),
                Fee = new Label("Monthly Fee for Options:"),
                Total = new Label("Total Due:"),
                StateLabel = new Label("State:");

    //checkbox group
        CheckboxGroup   Extras = new CheckboxGroup();
        Checkbox    Voicemail = new Checkbox("Voicemail: $5.00 per month"),
                Text = new Checkbox("Text Messaging: $10.00 per month"),
                Internet = new Checkbox("Internet Services: $5.00 per month"),
                Rollover = new Checkbox("Rollover minutes: $5.00 per month"),
                Roadside = new Checkbox("Roadside assistance: $3.00 per month"),
                Equipment = new Checkbox("Equipment Insurance: $4.00 per month");

    public void init()
    {
        //changes Font style, color, etc. 
        Title.setFont(new Font("Helvetica", Font.BOLD, 18));
        Title.setForeground(color.BLUE);
        add(Title);

        //p1 holds basic customer info
        Panel   p1 = new Panel();
                p1.setBackground(color.red);
                p1.setLayout(new GridLayout());

                p1.add(FirstName);
                p1.add(FirstField);

                p1.add(MI);
                p1.add(MIField);

                p1.add(LastName);
                p1.add(LastField);

                p1.add(Address);
                p1.add(AddressField);

                p1.add(City);
                p1.add(CityField);

                p1.add(StateLabel);
                    State.addItem("**");
                    State.addItem("AR");        
                    State.addItem("LA");
                    State.addItem("NM");
                    State.addItem("OK");
                    State.addItem("TX");
                p1.add(State);

                p1.add(ZipCode);
                p1.add(ZipField);
                add(p1);

        //p2 is choices and extras of customer pick
        Panel   p2 = new Panel();
                p2.setBackground(color.blue);

                //adds options to rate manu
                Rate.addItem("**** Select a Rate Plan****");
                Rate.addItem("300 minutes per month - $45.00 per month");
                Rate.addItem("800 minutes per month - $65.00 per month");
                Rate.addItem("1500 minutes per month - $99.00 per month");      
                p2.add(Rate);



                //adds checkboxes and titles menu
                Extras.addItem(Voicemail); 
                Extras.addItem(Text);
                Extras.addItem(Internet);
                Extras.addItem(Rollover);
                Extras.addItem(Roadside);
                Extras.addItem(Equipment);
                p2.add(Extras);

                add(p2);

        //p3 is cost information
        Panel   p3 = new Panel();
                p3.setBackground(color.white);

                p3.add(Cost);
                p3.add(CostField);

                p3.add(PlanCost);
                p3.add(PlanField);

                p3.add(Tax);
                p3.add(TaxField);

                p3.add(Fee);
                p3.add(FeeField);

                p3.add(Total);
                p3.add(TotalField);
                add(p3);

        //p4 is buttons
        Panel   p4 = new Panel();
                p4.setBackground(color.red);
                add(p4);

                p4.add(bReset);
                bReset.setBackground(color.blue);
                bReset.setForeground(color.white);
                bReset.addActionListener(this);

                p4.add(bChoices);
                bChoices.setBackground(color.blue);
                bChoices.setForeground(color.white);
                bChoices.addActionListener(this);

                p4.add(bSubmit);
                bSubmit.setBackground(color.blue);
                bSubmit.setForeground(color.white);
                bSubmit.addActionListener(this);

        //p5 holds info about order
        Panel   p5 = new Panel();
                p5.add(Order);

                add(p5);
        }

    public void actionPerformed(ActionEvent e)  //responds to button clicks, catches missing data, and ensures data is correct
    {   
        if(e.getSource() == bReset)
        {   
            processResetButton();
        }

            else if (e.getSource() == bChoices)
            {
                processChoicesButton();
            }
                else if (e.getSource() == bSubmit)
                { 
                    try
                    {
                        processSubmitButton();
                    }

                    catch(MissingData ex)
                    {
                        Order.appendText("****" + ex.getMessage() + CRLF);
                    }
                                }
        }

    private void processResetButton()       
    {
        FirstField.setText(EMPTY);
        MIField.setText(EMPTY);
        LastField.setText(EMPTY);
        AddressField.setText(EMPTY);
        CityField.setText(EMPTY);
        State.setText("**");
        ZipField.setText(EMPTY);
        Rate.setText("*** Select a rate plan");
        Model.setText("* Select a telephone model");
        Order.setText(EMPTY);
        CostField.setText(EMPTY);
        PlanField.setText(EMPTY);
        TaxField.setText(EMPTY);
        FeeField.setText(EMPTY);
        TotalField.setText(EMPTY);
        Extras.setState(False);
    }

    private void processChoicesButton()
    {
        Rate.setText(EMPTY);
        Model.setText(EMPTY);
        Order.setText(EMPTY);
        CostField.setText(EMPTY);
        PlanField.setText(EMPTY);
        TaxField.setText(EMPTY);
        FeeField.setText(EMPTY);
        TotalField.setText(EMPTY);
        Extras.setState(False);
    }

    private void processSubmitButton() throws MissingData   
        //files completed form
        {
             if((FirstField.getText().equals (EMPTY)) 
           (LastField.getText().equals (EMPTY))
           (AddressField.getText().equals (EMPTY))
           (State.getText().equals ("**"))
           (ZipField.getText().equals (EMPTY))  ) 

                {
            throw new MissingData ("Must enter data in all fields");
        }
            try
            {
                int quantity = Integer.parseInt(ZipField.getText());
                doSubmit (quantity);
            }
            catch(NumberFormatException ex)
            {
                Order.appendText("***" + ex.getMessage() + CRLF);
                Order.appendText("*** in the quantity field" + CRLF);
                return;
            }

            catch(IllegalQuantity ex)       //not positive
            {
                Order.appendText("****" + ex.getMessage() + CRLF);
                Order.appendText("*** in the quantity field" + CRLF);
                return;
                        }

              else      //data is all there so process form
        {
            Order.appendText(CRLF + "***Form Submited");
        }  

        }  

}

Edited by pyTony: fixed formatting

2
Contributors
1
Reply
3
Views
11 Years
Discussion Span
Last Post by server_crash
0

If I understand correctly, you can set the visibility:

Component.setVisible(false);

Or even better, set the editability:

Component.setEditable(false);

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.