possible FileInput/output problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pleb
    New Member
    • Dec 2007
    • 8

    possible FileInput/output problem

    Hey Guys,

    if i want to get the total price in
    total = new JTextField(20);
    c.add(total);

    would i first have to save the price per ticket in a text file and then open that file. Muliplying this then by the number of tickets purchased?.. or is there an easier way?


    [CODE=Java]
    import java.awt.*;
    import java.awt.event. *;
    import javax .swing.*;
    import java.io.*;


    public class Routes extends JFrame implements ActionListener
    {

    private String from[] = {"From","Cork", "Limerick","Bel fast","Dublin"} ;
    private String to[] = {"To","Cork","L imerick","Belfa st","Dublin"} ;
    private String tickets[] = {"Tickets","1", "2","3","4","5" ,"6"};
    private String back[] = {"Return", "Yes","No"} ;
    private JLabel label1, label2, label3,label4;
    private JComboBox fromCmb,toCmb, ticketsCmb, backCmb;
    private JButton next;
    private JLabel Tickets,Price, Total;
    private JTextField ticket,price,to tal;
    private JButton Procced;


    public static void main(String args[])
    {
    Routes app = new Routes();
    }

    public Routes() //constructor
    {
    super("Selec Destinations");

    Container c = getContentPane( );
    c.setLayout(new FlowLayout());

    label1 = new JLabel("From: ");
    c.add(label1);

    fromCmb = new JComboBox(from) ;
    c.add(fromCmb);

    label2 = new JLabel("To ");
    c.add(label2);

    toCmb = new JComboBox(to);
    c.add(toCmb);

    label3 = new JLabel("Number Of Tickets");
    c.add(label3);

    ticketsCmb = new JComboBox(ticke ts);
    c.add(ticketsCm b);

    label4 = new JLabel("Return ");
    c.add(label4);

    backCmb = new JComboBox(back) ;
    c.add(backCmb);

    next = new JButton("Next") ;
    next.addActionL istener(this);
    c.add(next);

    Tickets = new JLabel("Number Of Tickets ");
    c.add(Tickets);

    ticket = new JTextField(20);
    c.add(ticket);

    Price = new JLabel("Price Per Ticket ");
    c.add(Price);

    price = new JTextField(20);
    c.add(price);

    Total = new JLabel("Total ");
    c.add(Total);

    total = new JTextField(20);
    c.add(total);

    Procced = new JButton("Procce d");
    Procced.addActi onListener(this );
    c.add(Procced);



    setSize(400, 300);
    setVisible(true );
    }

    public void actionPerformed (ActionEvent e)
    {
    if (e.getSource() == Procced)
    {
    Payment payment = new Payment();
    setVisible(fals e);
    }
    }

    }[/CODE]
    Last edited by BigDaddyLH; Mar 12 '08, 06:24 PM. Reason: added code tags
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    Please enclose your posted code in [code] tags (See How to Ask a Question).

    This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

    Please use [code] tags in future.

    MODERATOR

    Comment

    • BigDaddyLH
      Recognized Expert Top Contributor
      • Dec 2007
      • 1216

      #3
      Unless I'm missing something here, you want the user to enter some information in the GUI, then your program should respond by doing a calculation and displaying the result.

      I don't see how file I/O is relevant. Am I missing something?

      Do you understand how to make GUI's interactive by using listeners? http://java.sun.com/docs/books/tutor...nts/index.html

      Comment

      • pleb
        New Member
        • Dec 2007
        • 8

        #4
        Originally posted by BigDaddyLH
        Unless I'm missing something here, you want the user to enter some information in the GUI, then your program should respond by doing a calculation and displaying the result.

        I don't see how file I/O is relevant. Am I missing something?

        Do you understand how to make GUI's interactive by using listeners? http://java.sun.com/docs/books/tutor...nts/index.html
        Sorry complete newb at this... Yes it will be preforming calculations but the "Admin" have to be able to set/change the ticket prices.. Thus im thinking the Price per ticket has to be read form the text file first?

        Comment

        • BigDaddyLH
          Recognized Expert Top Contributor
          • Dec 2007
          • 1216

          #5
          Originally posted by pleb
          Sorry complete newb at this... Yes it will be preforming calculations but the "Admin" have to be able to set/change the ticket prices.. Thus im thinking the Price per ticket has to be read form the text file first?
          That's certainly possible. One simple way to create configuration data like that is to use a property file:

          This Java tutorial describes exceptions, basic input/output, concurrency, regular expressions, and the platform environment

          Comment

          Working...