User Interface


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: User Interface

  1. #1
    Join Date
    Dec 2005
    Posts
    12

    User Interface

    Hello guys,
    I am trying to build my first GUI…but I am stuck. Need some help please? What I am trying to do is build a user interface TicketMachine with 1 (first or second class where first class is 3 times the fare of second class)
    2 (With single and return, where standard return is twice the single fare and economy return is specifies the dates of travel and cost ¾ of standard return.)
    3 (and finally print out the total money taken and all the tickets issued to the standard output).
    I would really appreciate any help!!! I have been able to build the GUI, but I am having trouble with calling the methods and actionListener, don’t know what to do anymore.

    Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    
    public class TicketMachine extends JFrame {
       private JTextField textField1, textField2, textField3; 
       private JLabel nameLabel;
       private JPanel panel1, panel2, panel3, panel4, panel5, panel6, panel7, panel8, panel9, panel10;
       private JButton singleButton, standardButton, ecoButton, summaryButton;
       private JComboBox dest, clas;
       
       private final String destination[] = {"Capetown",
            "London", "Sydney", "Windoek", "Amsterdam"};
            
       private final String Class[] = {"First Class", "Second Class",};
    
       // set up GUI
       public TicketMachine()
       {
          super( "Ticket Machine" );
     
    
          Container contentPane = getContentPane();
          contentPane.setLayout( new FlowLayout() );
          
          panel1 = new JPanel();
          contentPane.add (panel1);
          nameLabel = new JLabel( "* TRANS ATLANTIC AIRLINES *" );
          panel1.add( nameLabel, BorderLayout.CENTER );
         
          panel2 = new JPanel();
          contentPane.add (panel2, BorderLayout.CENTER);
          nameLabel = new JLabel( "Destination" );
          panel2.add ( nameLabel );
          dest = new JComboBox (destination);
          dest.setMaximumRowCount(5);
          panel2.add( dest );
          
          panel3 = new JPanel();
          contentPane.add (panel3, BorderLayout.CENTER);
          nameLabel = new JLabel( "Class" );
          panel3.add ( nameLabel );
          clas = new JComboBox (Class);
          clas.setMaximumRowCount(2);
          panel3.add( clas );
    
          panel4 = new JPanel();
          contentPane.add (panel4);
          nameLabel = new JLabel( "Number Of Passengers" );
          panel4.add ( nameLabel );
          textField1 = new JTextField(3);
          contentPane.add( textField1 );
          
          panel5 = new JPanel();
          contentPane.add (panel5);
          singleButton = new JButton( "Issue Single Ticket" );
          panel5.add( singleButton );
    
          panel6 = new JPanel();
          contentPane.add (panel6);        
          standardButton = new JButton( "Issue Standard Return" );
          panel6.add( standardButton );
          
          panel7 = new JPanel();
          contentPane.add (panel7);        
          ecoButton = new JButton( "Issue Economy Return" );
          panel7.add( ecoButton );
            
          // construct textfield with default sizing
          panel8 = new JPanel();
          contentPane.add (panel8);
          nameLabel = new JLabel( "Depature" );
          panel8.add ( nameLabel );
          textField2 = new JTextField(10);
          contentPane.add( textField2 );
    
          // construct textfield with default text
          panel9 = new JPanel();
          contentPane.add (panel9);
          nameLabel = new JLabel( "Return" );
          panel9.add ( nameLabel );
          textField3 = new JTextField(10);
          contentPane.add( textField3 );
    
          // construct textfield with default text,
          panel10 = new JPanel();
          contentPane.add (panel10);
          nameLabel = new JLabel( "Only applies to economy return" );
          panel10.add ( nameLabel );
          summaryButton = new JButton( "Issue Summary of Ticket Sales" );
          panel10.add( summaryButton );
            
          // register event handlers
          TextFieldHandler handler = new TextFieldHandler();
          textField1.addActionListener( handler );
          textField2.addActionListener( handler );
          textField3.addActionListener( handler );
       
          setSize( 420, 420 );
          setVisible( true );
    
       } // end constructor TextFieldTest
    
      
    
       // private inner class for event handling
       private class TextFieldHandler implements ActionListener {
    
          // process textfield events
          public void actionPerformed( ActionEvent event )
          {
             String string = "";
    
             // user pressed Enter in JTextField textField1
             if ( event.getSource() == textField1 )
                string = "textField1: " + event.getActionCommand();
    
             // user pressed Enter in JTextField textField2
             else if ( event.getSource() == textField2 )
                string = "textField2: " + event.getActionCommand();
    
             // user pressed Enter in JTextField textField3
             else if ( event.getSource() == textField3 )
                string = "textField3: " + event.getActionCommand();
                
             }
    
          } 
     }

  2. #2
    Join Date
    Dec 2005
    Posts
    12
    NO help here ???

  3. #3
    Join Date
    Mar 2004
    Posts
    635
    It'd help if you told us what's wrong with the GUI you've already made.

    You've created the action listener class and added it to your text fields, so whats the trouble?

  4. #4
    Join Date
    Apr 2006
    Posts
    28

    Ask your code so that program can run

    package Tickets;

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

    public class airLine extends JFrame implements ActionListener
    {
    private JLabel jlbHeader,jlbDestination;
    private JTextField jtfNoPassengers,jtfDeparture,jtfReturn;

    private JComboBox jcbCity;
    private JComboBox jcbClass;
    private JButton jbtSingleTicket,jbtStandardReturn;
    private JButton jbtEconomyReturn,jbtSummary,jbtClear;

    public airLine()
    {
    initial();

    setBounds(0,0,600,500);
    setVisible(true);
    setResizable(false);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }
    public void getClear()
    {

    }
    public static void main(String[] arg)
    {

    new airLine();
    }
    public void initial()
    {
    String [] city={null,"Sydney","Amsterdam","London","Capetown","Newyork"};
    jcbCity=new JComboBox(city);
    jcbCity.setMaximumRowCount(5);
    String [] cl={null,"Frist Class","Second Class"};
    jcbClass=new JComboBox(cl);
    JPanel p1=new JPanel();
    p1.setLayout(new FlowLayout());
    jlbHeader=new JLabel("Atlantic Airline Ticket");
    jlbHeader.setFont(new Font("Tohama",1,20));
    jlbHeader.setForeground(Color.RED);
    p1.add(jlbHeader,JLabel.CENTER);
    getContentPane().add(p1,BorderLayout.NORTH);
    JPanel p2=new JPanel();
    p2.setLayout(new GridLayout(7,2,5,5));
    p2.add(new JLabel("Destination"));
    p2.add(jcbCity);
    p2.add(new JLabel("Class"));
    p2.add(jcbClass);
    p2.add(new JLabel("Number Of passengers"));
    jtfNoPassengers=new JTextField(10);
    p2.add(jtfNoPassengers);
    jbtSingleTicket=new JButton("Issue Single Ticket");
    jbtSingleTicket.setMnemonic('T');

    p2.add(jbtSingleTicket);
    jbtStandardReturn=new JButton("Issue Standard Return");

    jbtStandardReturn.setMnemonic('I');
    p2.add(jbtStandardReturn);

    jbtEconomyReturn=new JButton("Economy Return");
    jbtEconomyReturn.setMnemonic('E');

    p2.add(jbtEconomyReturn);
    p2.add(new JLabel(""));

    p2.add(new JLabel("Departure"));
    jtfDeparture=new JTextField(10);
    p2.add(jtfDeparture);
    p2.add(new JLabel("Return"));
    jtfReturn=new JTextField(10);
    p2.add(jtfReturn);

    getContentPane().add(p2,BorderLayout.CENTER);

    JPanel p3=new JPanel();
    p3.setLayout(new FlowLayout() );
    jbtSummary=new JButton("Summary of ticket sales");
    jbtSummary.setMnemonic('S');

    p3.add(jbtSummary);

    jbtClear=new JButton("Clear");


    jbtClear.setMnemonic('C');
    p3.add(jbtClear);
    getContentPane().add(p3,BorderLayout.SOUTH);


    jtfNoPassengers.addKeyListener(new KeyAdapter()
    {

    public void keyReleased(KeyEvent ke)
    {
    String text=jtfNoPassengers.getText();

    try
    {
    double dbNoPassengers=Double.parseDouble(text);
    }

    catch(NumberFormatException ne)
    {
    JOptionPane.showMessageDialog(null,ne.getMessage());
    }

    }
    });

    jbtSingleTicket.addActionListener(this);
    jbtStandardReturn.addActionListener(this);
    jbtSummary.addActionListener(this);
    jbtClear.addActionListener(this);
    jbtEconomyReturn.addActionListener(this);


    }
    public void actionPerformed(ActionEvent e)
    {
    if (e.getSource()==jbtClear)
    getClear();
    else if(e.getSource()==jbtSingleTicket)
    getSingleTicket();
    else if(e.getSource()==jbtStandardReturn)
    getStandardReturn();
    else getSummary();

    }
    public void getSingleTicket()
    {
    JOptionPane.showMessageDialog(null,"BBB");

    }
    public void getStandardReturn()
    {
    JOptionPane.showMessageDialog(null,"BBB");
    }
    public void getSummary()
    {
    JOptionPane.showMessageDialog(null,"BBB");
    }

    }

  5. #5
    Join Date
    Apr 2006
    Posts
    28
    implement listener already in this program, you need add the code ....
    good luck

Similar Threads

  1. Re: User Interface for DB Project
    By DrJax in forum VB Classic
    Replies: 4
    Last Post: 09-11-2001, 05:13 PM
  2. Script for scrolling
    By Mark in forum Web
    Replies: 3
    Last Post: 08-30-2001, 11:45 AM
  3. Interface leaks in C#?
    By Kevin Burton in forum .NET
    Replies: 12
    Last Post: 10-09-2000, 10:29 AM

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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center