By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,467 Members | 1,308 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,467 IT Pros & Developers. It's quick & easy.

possible FileInput/output problem

P: 8
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?


Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax .swing.*;
  4. import java.io.*;
  5.  
  6.  
  7. public class Routes extends JFrame implements ActionListener
  8. {
  9.  
  10.     private String from[] = {"From","Cork","Limerick","Belfast","Dublin"};
  11.     private String to[] = {"To","Cork","Limerick","Belfast","Dublin"};
  12.     private String tickets[] = {"Tickets","1","2","3","4","5","6"};
  13.     private String back[] = {"Return", "Yes","No"};
  14.     private JLabel label1, label2, label3,label4;
  15.     private JComboBox fromCmb,toCmb, ticketsCmb, backCmb;
  16.     private JButton next;
  17.     private JLabel Tickets,Price, Total;
  18.     private JTextField ticket,price,total;
  19.     private JButton Procced;
  20.  
  21.  
  22.     public static void main(String args[])
  23.     {
  24.         Routes app = new Routes();
  25.     }
  26.  
  27.     public Routes() //constructor
  28.     {
  29.         super("Selec Destinations");
  30.  
  31.         Container c = getContentPane();
  32.         c.setLayout(new FlowLayout());
  33.  
  34.         label1 = new JLabel("From:          ");
  35.         c.add(label1);
  36.  
  37.         fromCmb = new JComboBox(from);
  38.         c.add(fromCmb);
  39.  
  40.         label2 = new JLabel("To             ");
  41.         c.add(label2);
  42.  
  43.         toCmb = new JComboBox(to);
  44.         c.add(toCmb);
  45.  
  46.         label3 = new JLabel("Number Of Tickets");
  47.         c.add(label3);
  48.  
  49.         ticketsCmb = new JComboBox(tickets);
  50.         c.add(ticketsCmb);
  51.  
  52.         label4 = new JLabel("Return      ");
  53.         c.add(label4);
  54.  
  55.         backCmb = new JComboBox(back);
  56.         c.add(backCmb);
  57.  
  58.         next = new JButton("Next");
  59.         next.addActionListener(this);
  60.         c.add(next);
  61.  
  62.         Tickets = new JLabel("Number Of Tickets ");
  63.         c.add(Tickets);
  64.  
  65.         ticket = new JTextField(20);
  66.         c.add(ticket);
  67.  
  68.         Price = new JLabel("Price Per Ticket     ");
  69.         c.add(Price);
  70.  
  71.         price = new JTextField(20);
  72.         c.add(price);
  73.  
  74.         Total = new JLabel("Total                          ");
  75.         c.add(Total);
  76.  
  77.        total = new JTextField(20);
  78.         c.add(total);
  79.  
  80.         Procced = new JButton("Procced");
  81.         Procced.addActionListener(this);
  82.         c.add(Procced);
  83.  
  84.  
  85.  
  86.         setSize(400, 300);
  87.         setVisible(true);
  88.     }
  89.  
  90.         public void actionPerformed(ActionEvent e)
  91.     {
  92.         if (e.getSource() == Procced)
  93.         {
  94.             Payment payment = new Payment();
  95.             setVisible(false);
  96.         }
  97.     }
  98.  
  99. }
Mar 12 '08 #1
Share this Question
Share on Google+
4 Replies


BigDaddyLH
Expert 100+
P: 1,216
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
Mar 12 '08 #2

BigDaddyLH
Expert 100+
P: 1,216
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
Mar 12 '08 #3

P: 8
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?
Mar 12 '08 #4

BigDaddyLH
Expert 100+
P: 1,216
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:

http://java.sun.com/docs/books/tutor...roperties.html
Mar 12 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.