0

I have this code below; I am trying to display the Age, Cinema Price and Price rates when user drags the "Scrollbar", please direct me on what to do to get this working.

import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
import java.text.*;
import java.awt.event.AdjustmentEvent;
import java.awt.event.*;

public class CinemaPrice extends Applet implements AdjustmentListener{
public static void main(String [ ] args){}
    // declarations

    Label enterPatronageLabel;
    Scrollbar enterPatronageScrollbar;
    int AgeOfPatron;

    Label selectedAgeLabel;
    TextField selectedAgeTextField;

    Label admissionRateLabel;
    TextField admissionRateTextField;
    char admissionRate;

    Label admissionPriceLabel;
    TextField admissionPriceTextField;
    double admissionPrice;

    // controls
    Button enterButton;
    Button clearButton;


    public void init()
    {
        setLayout(null);

        /*
            (Scrollbar.HORIZONTAL, 0, 1, 0, 100)
             starting position is 0, page size is 1, minimum is 0 and maximum is 100.
        */

        enterPatronageLabel = new Label("Enter Patronage Name:");
        enterPatronageLabel.setBounds(50, 50, 130, 20);
        add(enterPatronageLabel);

        enterPatronageScrollbar = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, 100);
        enterPatronageScrollbar.setBounds(230, 50, 100, 20);
        add(enterPatronageScrollbar);
        enterPatronageScrollbar.addAdjustmentListener(this);

        selectedAgeLabel = new Label("Selected Age:");
        selectedAgeLabel.setBounds(50, 80, 150, 20);
        add(selectedAgeLabel);

        selectedAgeTextField = new TextField(5);
        selectedAgeTextField.setBounds(230,80, 50, 20);
        add(selectedAgeTextField);

        admissionRateLabel = new Label("Admission Rate:");
        admissionRateLabel.setBounds(50, 110, 100, 20);
        add(admissionRateLabel);

        admissionRateTextField = new TextField(5);
        admissionRateTextField.setBounds(230, 110, 100, 20);
        add(admissionRateTextField);

        admissionPriceLabel = new Label("Admission Price:");
        admissionPriceLabel.setBounds(50, 140, 150, 20);
        add(admissionPriceLabel);

        admissionPriceTextField = new TextField(5);
        admissionPriceTextField.setBounds(230, 140, 50, 20);
        add(admissionPriceTextField);

        // controls
        enterButton = new Button("Enter");
        add(enterButton);
        enterButton.setBounds(50, 320, 100, 20);
        enterButton.addActionListener(this);

        clearButton = new Button("Clear");
        add(clearButton);
        clearButton.setBounds(200, 320, 100, 20);
        clearButton.addActionListener(this);

        }
        public void actionPerformed(ActionEvent event)
        {
        if (event.getSource() == enterButton)
        {
        AgeOfPatron = enterPatronageScrollbar.getValue();
        }
        if (event.getSource() == clearButton)
        {
        selectedAgeTextField.setText("");
        selectedAgeTextField.requestFocusInWindow();
        admissionRateTextField.setText("");
        admissionPriceTextField.setText("");

        }
        }

    public void adjustmentValueChanged(AdjustmentEvent e)

        {
            AgeOfPatron = enterPatronageScrollbar.getValue();
            selectedAgeTextField.setText("" + AgeOfPatron);
            System.out.println(admissionPrice);
            System.out.println(admissionRate);

     if(AgeOfPatron > 0 || AgeOfPatron < 5)
        {

            admissionPriceTextField.setText("$0.00");
            admissionRateTextField.setText("Free");
        }
    else if(AgeOfPatron > 5 || AgeOfPatron < 12)
            {
            admissionPriceTextField.setText("$4.25");
            admissionRateTextField.setText("Half Price");
            }
    else if(AgeOfPatron > 12 || AgeOfPatron < 54)
            {
            admissionPriceTextField.setText("$8.50");
            admissionRateTextField.setText("Full Price");
            }
    else if(AgeOfPatron > 55)
            {
            admissionRateTextField.setText("$0.00");
            admissionPriceTextField.setText("Free");
            }
        repaint();

        }
}
Yu Hao
  • 119,891
  • 44
  • 235
  • 294
  • *"please direct me on what to do to get this working"* Please ask a question. – Andrew Thompson Dec 01 '13 at 07:20
  • 1) Why code an applet? If it is due to spec. by teacher, please refer them to [Why CS teachers should stop teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). 2) Why AWT rather than Swing? See this answer on [Swing extras over AWT](http://stackoverflow.com/a/6255978/418556) for many good reasons to abandon using AWT components. If you need to support older AWT based APIs, see [Mixing Heavyweight and Lightweight Components](http://www.oracle.com/technetwork/articles/java/mixing-components-433992.html). – Andrew Thompson Dec 01 '13 at 07:20
  • 1) Use a consistent and logical indent for code blocks. The indentation of the code is intended to help people understand the program flow. 2) Java GUIs might have to work on a number of platforms, on different screen resolutions & using different PLAFs. As such they are not conducive to exact placement of components. To organize the components for a robust GUI, instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556), along with layout padding & borders for [white space](http://stackoverflow.com/q/17874717/418556). – Andrew Thompson Dec 01 '13 at 07:22

0 Answers0