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 2 of 2

Thread: help with user selected section has no available seat applet

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help with user selected section has no available seat applet

    not sure where i input the... If the user selected section has no available seat, your program should ask if the user is OK with the other section seats. If the user clicked OK, you print the boarding pass of the assigned seat. If the user clicked Cancel, print "Next flight leaves in 3 hours"

    i know its but cant get the input to work..

    choice = Integer.parseInt(JOptionPane.showInputDialog("Are you OK with First Class. (click OK or Cancel"));
    	                hours.");
    {
    }

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
     
    	public class Assign7 extends JApplet implements ActionListener
    	   {
    	   JTextField outputField;
    	   JButton firstClassButton, economyButton;
    	   int section, seats[], firstclass;
    	   int economy, people, choice;
     
    	   public void init()
    	   {
     
    	      Container container = getContentPane();
    	      container.setLayout(new FlowLayout());
     
     
    	      firstClassButton = new JButton( "First Class" );
    	      firstClassButton.addActionListener( this );
    	      container.add(firstClassButton);
     
    	      economyButton = new JButton( "Economy" );
    	      economyButton.addActionListener( this );
    	      container.add(economyButton);
     
    	      outputField = new JTextField ( 17 );
    	      outputField.setEditable(false);
    	      container.add(outputField);
     
    	      seats = new int[ 11 ];   
    	      firstclass = 1;
    	      economy = 6;       
    	   } 
    	   public void actionPerformed( ActionEvent actionEvent )
    	   {
     
    	      if ( actionEvent.getSource() == firstClassButton && people <=10)
    	        {
    	             if ( firstclass <= 5 && seats[ firstclass ] == 0 )
    	              {
    	                 outputField.setText ("Boarding Pass: Seat " + firstclass+ " FirstClass");
    	                 seats[ firstclass++ ] = 1;
    	                 people++;
    	              }
    	             else if ( firstclass > 0 && economy <= 6)
    	              {
    	            outputField.setText ("FirstClass is full. Economy?");
    	              }
    	             else
    	            outputField.setText("Next flight leaves in 3 hours.");
     
    	        }    
    	      else if (actionEvent.getSource() == economyButton && people <=10)
    	      {
     
    	              if ( economy >= 5 && seats[ economy ] == 0)
    	               {
    	                  outputField.setText ("Boarding Pass: Seat " +economy+ " Economy");
                      seats[ economy++ ] = 1;
    	                  people++;
                   }
                  else if ( economy > 0 && firstclass <= 6 )
                   {
                      outputField.setText("Economy is full. FirstClass?");
                   }
     
                  else
                      outputField.setText ("Next flight leaves in 3 hours.");
     
              }
     
    	   }
     
    	}
    {
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,298
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default Re: help with user selected section has no available seat applet

    What do you mean when you say you "can't get it to work"? What does it do instead? Does it throw an Exception? Result in weird behavior? Something else?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Replies: 0
    Last Post: February 12th, 2011, 06:44 PM
  2. Problem getting selected item as string from JComboBox
    By lost in forum AWT / Java Swing
    Replies: 1
    Last Post: October 26th, 2010, 03:22 AM
  3. Change of color for selected text in AWT
    By venkyInd in forum AWT / Java Swing
    Replies: 2
    Last Post: April 9th, 2010, 03:51 AM
  4. how to delete record based on checkbox selected checkbox
    By -_- in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: December 15th, 2009, 08:26 PM
  5. User Input Loop
    By cfmonster in forum Loops & Control Statements
    Replies: 7
    Last Post: August 24th, 2009, 01:52 PM