Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Super Bowl Tickets

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Super Bowl Tickets

    So, I am in a Java Programming Intro class, and for whatever reason I am just stuck on our final project. Basically I need this to work. It looks exactly as it should so far. We are supposed to use the actionPerformed method to make it work, and make the results show up on a new window, and it's supposed to look like this;

    Event: Super Bowl 2011
    Issued to: <Name>
    Quantity: <NumberOfTickets>
    Section: <Whicheveronetheychose>
    Ticket Charge: $<Calculated Value>
    Delivery Charge: $<10 or zero>
    Total Charged: $<Calculated Value>

    Here is what I have so far;

    public class TicketApp extends JApplet
    {
        private int x;
     
        JLabel sbtLabel;
        JLabel name;
        JLabel tickets;
        JLabel section;
     
        JTextField nametext;
        JTextField tickettext;
        JComboBox sectionbox;
        JCheckBox express;
        JButton submit;
     
        public void init()
        {
            setLayout( new FlowLayout(FlowLayout.LEFT));
            sbtLabel = new JLabel("<HTML><FONT SIZE=+1>Super Bowl Tickets 2011</FONT>");
            name = new JLabel("<HTML>Enter Name");
            nametext = new JTextField(12);
            tickets = new JLabel("<HTML>Number of Tickets");
            tickettext = new JTextField(4);
            section = new JLabel("<HTML>Choose a Section");
            sectionbox = new JComboBox();
            sectionbox.addItem ("Club Box ($400)");
            sectionbox.addItem ("Lower Deck ($200)");
            sectionbox.addItem ("Upper Deck ($150)");
            express = new JCheckBox("Express Delivery? (add $10)");
            submit = new JButton("Submit Order");
     
            add (sbtLabel);
            add (name);
            add (nametext);
            add (tickets);
            add (tickettext);
            add (section);
            add (sectionbox);
            add (express);
            add (submit);
     
     
        }
    So yeah, any help is greatly appreciated.

    Thanks,
    Jonathan Oty


  2. #2
    Member
    Join Date
    Jan 2011
    Location
    Phoenix
    Posts
    49
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default Re: Super Bowl Tickets

    the way i would do it is put a series of if statements in the actionperformed method:

    public void actionPerformed(ActionEvent e)
    {
    String mystr = new String("");
     
    if(e.getsource==nametext)
    {
    mystr = nametext.getText();
    // then have another class called to open a frame with a windowListener to close it when the x is clicked
    }
     
    // do with the other textboxes via 'else if'
    }

    i hope you get the jist of what im getting at

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Super Bowl Tickets

    What exactly is the question? Just mentioning you are stuck does not give us much information to point you in the right direction. See the following tutorial for how to use ActionListeners: How to Write an Action Listener

  4. #4
    Junior Member
    Join Date
    Jan 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Super Bowl Tickets

    Well thanks both of you for the help, I didn't really have any specific questions I was just lost, but I worked through most of it. The program isn't very pretty, but I'm ok with it, now my last question is how to properly format the message windows with each piece of info on a separate line. If i could figure that out I would be greatly appreciative.

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

    public class TicketApp extends JApplet
    implements ActionListener
    {
    JLabel sbtLabel, name, tickets, section;
    JTextField nametext;
    JTextField tickettext;
    JComboBox sectionbox;
    JCheckBox express;
    JButton submit;
    int a;

    public void init()
    {
    setLayout( new FlowLayout(FlowLayout.LEFT));
    sbtLabel = new JLabel("<HTML><FONT SIZE=+1>Super Bowl Tickets 2011</FONT>");
    name = new JLabel("<HTML>Enter Name");
    nametext = new JTextField(12);
    tickets = new JLabel("<HTML>Number of Tickets");
    tickettext = new JTextField(4);
    section = new JLabel("<HTML>Choose a Section");
    sectionbox = new JComboBox();
    sectionbox.addItem ("Club Box ($400)");
    sectionbox.addItem ("Lower Deck ($200)");
    sectionbox.addItem ("Upper Deck ($150)");
    express = new JCheckBox("Express Delivery? (add $10)");
    submit = new JButton("Submit Order");
    submit.addActionListener( this );

    add (sbtLabel);
    add (name);
    add (nametext);
    add (tickets);
    add (tickettext);
    add (section);
    add (sectionbox);
    add (express);
    add (submit);



    }
    public void actionPerformed( ActionEvent ae )
    {
    Object obj = ae.getSource( );
    String name = nametext.getText();
    String ticket = tickettext.getText();
    int n = Integer.parseInt(ticket);
    int selectedOutput = sectionbox.getSelectedIndex();
    boolean checked = express.isSelected();
    int a, b, c, d, e, f;

    a = 400 * n;
    b = 400 * n + 10;
    c = 200 * n;
    d = 200 * n + 10;
    e = 150 * n;
    f = 150 * n + 10;

    String message;
    if ( selectedOutput == 0)
    if ( checked == false )
    message = ("Event: Super Bowl 2011" + "Issued to: " + name +
    "Quantity: " + ticket + "Section: Club Box ($400)" + "Ticket Charge: $" + a +
    "Delivery Charge: $0" + "Total Charged: $" + a);
    else
    message = ("Event: Super Bowl 2011" + "Issued to: " + name +
    "Quantity: " + ticket + "Section: Club Box ($400)" + "Ticket Charge: $" + a +
    "Delivery Charge: $10" + "Total Charged: $" + b);
    else if ( selectedOutput == 1)
    if ( checked == false )
    message = ("Event: Super Bowl 2011" + "Issued to: " + name +
    "Quantity: " + ticket + "Section: Lower Deck ($200)" + "Ticket Charge: $" + c +
    "Delivery Charge: $0" + "Total Charged: $" + c);
    else
    message = ("Event: Super Bowl 2011" + "Issued to: " + name +
    "Quantity: " + ticket + "Section: Lower Deck ($200)" + "Ticket Charge: $" + c +
    "Delivery Charge: $10" + "Total Charged: $" + d);
    else
    if ( checked == false )
    message = ("Event: Super Bowl 2011" + "Issued to: " + name +
    "Quantity: " + ticket + "Section: Upper Deck ($150)" + "Ticket Charge: $" + e +
    "Delivery Charge: $0" + "Total Charged: $" + e);
    else
    message = ("Event: Super Bowl 2011" + "Issued to: " + name +
    "Quantity: " + ticket + "Section: Upper Deck ($150)" + "Ticket Charge: $" + e +
    "Delivery Charge: $10" + "Total Charged: $" + f);

    JOptionPane.showMessageDialog( null, message, "Message Window",
    JOptionPane.PLAIN_MESSAGE);



    }
    }

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Super Bowl Tickets

    how to properly format the message windows with each piece of info on a separate line
    Separate each line with a new line char
    String val = "FirstLine \n Second Line \n ThirdLine\netc..."

Similar Threads

  1. Junit3 error: Implicit super constructor TestCase() is not visible
    By albertkao in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 21st, 2011, 12:53 PM
  2. Replies: 2
    Last Post: January 7th, 2011, 09:10 PM
  3. SUPER SIMPLE QUESTION!!!
    By Options in forum What's Wrong With My Code?
    Replies: 7
    Last Post: September 2nd, 2010, 09:21 PM
  4. Super Mario Frustration
    By Bryan in forum The Cafe
    Replies: 2
    Last Post: June 11th, 2010, 02:46 PM

Tags for this Thread