www.webdeveloper.com
Results 1 to 2 of 2

Thread: Linking Between 2 or more Classes

  1. #1
    Join Date
    Aug 2007
    Posts
    1

    Linking Between 2 or more Classes

    I dont know if this is asked before, pardon me if it does.

    I am currently studying the basics of Object Orientation Programming, so kind of rather blur with stuff.

    I have this particular "main class" which is a GUI that serves as a "Online Movie Booking System", i have not much of a problem till when i attempt to use Vectors. Another problem which i encounter is, i have 2 separate classes, how do i link to another class using a button? Is that possible?

    Vectors
    At first, i tired using arrays, meaning, i get the input from the textfield, and initialized them into specific arrays. But when i attempted the same with Vectors, i got error like
    (Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String)
    What does it mean? Oh and in addition, the code is as below

    class BookHandler implements ActionListener
    {
    public void actionPerformed(ActionEvent evt)
    {
    refNum[x] = x;

    date[x] = (String)dateList.getSelectedItem();
    mth[x] = (String)mthList.getSelectedItem();
    topShow1[x] = tfTopShow1.getText();
    topShow2[x] = tfTopShow2.getText();
    btmShow1[x] = tfBtmShow1.getText();
    btmShow2[x] = tfBtmShow2.getText();

    topShow1V.add(topShow1[x]);
    topShow2V.add(topShow2[x]);
    btmShow1V.add(btmShow1[x]);
    btmShow2V.add(btmShow2[x]);

    int tShow1 = Integer.parseInt(topShow1[x]);
    int tShow2 = Integer.parseInt(topShow2[x]);
    int bShow1 = Integer.parseInt(btmShow1[x]);
    int bShow2 = Integer.parseInt(btmShow2[x]);

    refNumV.add(refNum[x]);
    dateV.add(date[x]);
    mthV.add(mth[x]);

    String confirmation = "Booking Reference Number : " +fmt1.format((String)refNumV.get(x))+ "\n\n";
    confirmation = confirmation + "Date of movie (DD-MM-YYYY) : " +(String)dateV.get(x)+ "-" +mth[x]+ "-2007\n\n";
    confirmation = confirmation + "Cinema : DV Plaza\n\n";
    confirmation = confirmation + "Movie title : Harry Potter 6 / PG\n";
    confirmation = confirmation + "Movie time : 1pm\n";
    confirmation = confirmation + "Price per ticket S$: 6.50\n";
    confirmation = confirmation + "No. of tickets : " +(String)topShow1V.get(x)+ "\n";
    confirmation = confirmation + "Movie title : Die Hard 5.0 / NC16\n";
    confirmation = confirmation + "Movie time : 4.30pm\n";
    confirmation = confirmation + "Price per ticket S$: 7.50\n";
    confirmation = confirmation + "No. of tickets : " +(String)topShow2V.get(x)+ "\n\n";
    confirmation = confirmation + "Cinema : DV Tampines\n\n";
    confirmation = confirmation + "Movie title : Spiderman 4 / PG\n";
    confirmation = confirmation + "Movie time : 2pm\n";
    confirmation = confirmation + "Price per ticket S$: 6.50\n";
    confirmation = confirmation + "No. of tickets : " +(String)btmShow1V.get(x)+ "\n";
    confirmation = confirmation + "Movie title : Simpson the Movie / G\n";
    confirmation = confirmation + "Movie time : 60pm\n";
    confirmation = confirmation + "Price per ticket S$: 7.50\n";
    confirmation = confirmation + "No. of tickets : " +(String)btmShow2V.get(x)+ "\n\n";

    totalPrice[x] = (6.5*tShow1) + (7.5*tShow2) + (6.5*bShow1) + (7.5*bShow2);

    totalPriceV.add(totalPrice[x]);

    confirmation = confirmation + "Total price : $" +fmt2.format((String)totalPriceV.get(x))+ "\n\n";
    confirmation = confirmation + "Please remember your Booking Reference Number when collecting your ticket.\n";
    confirmation = confirmation + "Thank You!!";

    JOptionPane.showMessageDialog(null,confirmation,"Bookin Confirmation Slip", JOptionPane.PLAIN_MESSAGE);

    x++;
    }
    }

    Classes
    I have got this booking class and a seating arrangement class, how do i, say... for eg. click this particular button in booking class and it links to the seating arrangment class, showing the seating arrangement? Is that possible?

    FYI : Everything is displayed using JFrame, not JApplet.

  2. #2
    Join Date
    Oct 2004
    Location
    The very depths of programming hell
    Posts
    828
    It's not a matter of "linking" to another class. One of your classes will be the class which is actually being run - that'll be whichever one that extends Applet or a subclass of Applet, in the case of using a java applet.

    You don't "link" to a class, you create an instance of that class, called an object. That object will then be used in the main class, in whatever way necessary. You would construct a new object pf your seating arrangement class, and show that on the screen in whatever way you have facilitated for.
    >I suck at this game, can you give me some pointers?

    >> 0x278AB4FF, 0xB5822BB4, 0xAD6E673D.

    > I hate you.


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles