Problema de importación de clase de ticket (java)

My program will not find the ticket class i created . Cant seem to work out what i have done wrong? Thank you

package javacw;

/*
 *
 * @Author Christopher Kempster;
 *
 */
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;


public class Main extends JFrame implements ActionListener {


    public JButton buyButton, viewSeatsButton, clearSeatsButton;
    String[] showTimes = {"1pm", "3pm", "5pm", "7pm", "9pm"};
    String[] ageCategories = {"Adult", "Child", "OAP"};
    String[] seatingSections = {"Left", "Middle", "Right"};
    public JComboBox times, categories, sections;
    public JTextField numberOfTickets;
    public Ticket ticket;
    public int price;


    public static void main(String args[]) {

        Main dashboard = new Main();

        dashboard.setVisible(true);



    }

    public void actionPerformed(ActionEvent e) {
        Object item = times.getSelectedItem();
        String stringTimes = (String)item;

        Object item1 = categories.getSelectedItem();
        String stringCategories = (String)item1;

        Object item2 = sections.getSelectedItem();
        String stringSections = (String)item2;

        String text = numberOfTickets.getText();

        int ii = Integer.parseInt(text);

        if(e.getSource() == buyButton) {
            buyTickets(stringTimes, stringSections, ii, stringCategories);
        }
        else if(e.getSource() == viewSeatsButton) {
            showSeats(stringTimes, stringSections);
        }
        else if(e.getSource() == clearSeatsButton) {
            clearSection(stringTimes, stringSections);
        }

    }

    public Main() {
        ticket = new Ticket();
        JPanel panel = new JPanel();



        FlowLayout flow = new FlowLayout();

        panel.setLayout(flow);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        setSize(300, 500);

        buyButton = new JButton("Buy tickets");
        viewSeatsButton = new JButton("View seats");
        clearSeatsButton = new JButton("Clear seats");

        times = new JComboBox(showTimes);
        categories = new JComboBox(ageCategories);
        sections = new JComboBox(seatingSections);

        JLabel label = new JLabel("Number of tickets:");

        numberOfTickets = new JTextField(5);

        buyButton.addActionListener(this);
        viewSeatsButton.addActionListener(this);
        clearSeatsButton.addActionListener(this);

        panel.add(times);
        panel.add(categories);
        panel.add(sections);

        panel.add(label);

        panel.add(numberOfTickets);

        panel.add(buyButton);
        panel.add(viewSeatsButton);
        panel.add(clearSeatsButton);



        Container cp = getContentPane();
        cp.add(panel, BorderLayout.CENTER);
        cp.setBackground(Color.red);

    }

    public void showSeats(String a, String b) {
        JOptionPane.showMessageDialog(this, "There are " + ticket.seatsLeft(a, b) + " seats left in the " + b + " at " + a + ".");
    }

    public void clearSection(String a, String b) {
        ticket.clearSeats(a, b);
        JOptionPane.showMessageDialog(this, "There are now " + ticket.seatsLeft(a, b) + " tickets left for this section.");
    }

    public void buyTickets(String a, String b, int i, String c) {
        if(c.equals("Adult")) {
            price = 5;
        }
        else if(c.equals("Child")) {
            price = 2;
        }
        else if(c.equals("OAP")) {
            price = 2;
        }

        price = price * i;

        if(ticket.buyTix(a, b, i)) {

            JOptionPane.showMessageDialog(this, "Tickets have been bought!\nThere are " + ticket.seatsLeft(a, b) + " seats left in this section.\nPrice of tickets bought: £" + price + ".");

        }
        else {

            JOptionPane.showMessageDialog(this, "Sorry, there are just " + ticket.seatsLeft(a, b) + " tickets left for this section.");

        }
    }

}


Ticket.java

package javacw;
/*
 *
 * @Author Christopher Kempster;
 *
 */

public class Ticket {

    int c, seatsLeft;
    public int[] seating = {12, 40, 12, 12, 40, 12, 12, 40, 12, 12, 40, 12, 12, 40, 12};
    public int[] seating2 = {12, 40, 12, 12, 40, 12, 12, 40, 12, 12, 40, 12, 12, 40, 12};
    public Ticket() {

    }

    public void clearSeats(String a, String b) {
        seating[convertArrayPointer(a, b)] = seating2[convertArrayPointer(a, b)];
    }

    public boolean buyTix(String a, String b, int i) {

        if(seatsLeft(a, b) >= i) {
            seating[convertArrayPointer(a, b)] -= i;
            return true;
        }
        else {
            return false;
        }

    }

    public int seatsLeft(String a, String b) {

        seatsLeft = seating[convertArrayPointer(a, b)];

        return seatsLeft;
    }

    public int convertArrayPointer(String a, String b) {

        if(a.equals("1pm") && b.equals("Left")) {
            c = 0;
        }
        else if(a.equals("1pm") && b.equals("Middle")) {
            c = 1;
        }
        else if(a.equals("1pm") && b.equals("Right")) {
            c = 2;
        }

        else if(a.equals("3pm") && b.equals("Left")) {
            c = 3;
        }
        else if(a.equals("3pm") && b.equals("Middle")) {
            c = 4;
        }
        else if(a.equals("3pm") && b.equals("Right")) {
            c = 5;
        }

        else if(a.equals("5pm") && b.equals("Left")) {
            c = 6;
        }
        else if(a.equals("5pm") && b.equals("Middle")) {
            c = 7;
        }
        else if(a.equals("5pm") && b.equals("Right")) {
            c = 8;
        }

        else if(a.equals("7pm") && b.equals("Left")) {
            c = 9;
        }
        else if(a.equals("7pm") && b.equals("Middle")) {
            c = 10;
        }
        else if(a.equals("7pm") && b.equals("Right")) {
            c = 11;
        }

        else if(a.equals("9pm") && b.equals("Left")) {
            c = 12;
        }
        else if(a.equals("9pm") && b.equals("Middle")) {
            c = 13;
        }
        else if(a.equals("9pm") && b.equals("Right")) {
            c = 14;
        }
        return c;
    }

}

preguntado el 27 de agosto de 11 a las 15:08

Don't post your code, post your error message. -

He should post esencial parts of the code to show how it's done and not the whole program. -

Or you could have tried to be helpful, rather than condescending -

1 Respuestas

This compiles properly when I try under Eclipse.

The problem doesn't come from your code. I think it comes from your environment settings. Either the source path is not correct or your Ticket.java is not located in the proper directory (which should be [src path]/javacw aquí).

Respondido 27 ago 11, 19:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.