guys please help me with this. my problem is that on PaymentNewGUI class i am finding it hard to extract the entrance time from the file to be displayed on the gui if correct ticket number is added, reference to enterListener method in paymentnewGUI class thank you
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.Date;
import java.lang.*;
public class PaymentNewGUI extends JFrame{
private JButton tenP, twentyP, fiftyP, onePound, twoPound;
JTextField ticketID;
double amountDue = 0.00;
double amountInserted;
Label lEntranceTime;
Label lPaymentTime;
Label lDue;
Label lInserted;
Label lMessage = new Label();
Container content;
JPanel ticketPanel;
/***Key Variable***/
long entranceTime;
long paymentTime;
String ticketStatus;
double balance;
public PaymentNewGUI() {
lEntranceTime = new Label("Entrance Time: " );
lPaymentTime = new Label("Payment Time: " );
lDue = new Label("Amount Due: \u00A3" + amountDue);
lInserted = new Label("Amount Instered: \u00A3" + amountInserted);
content = getContentPane();
content.setLayout(new BorderLayout());
this.setTitle("Enter Ticket Information");
Label lTicketID = new Label("Enter Ticket No:");
JButton enterButton = new JButton("Enter");
enterButton.addActionListener(new enterListener());
ticketID = new JTextField(9);
ticketPanel = new JPanel();
ticketPanel.setLayout(new GridLayout(2,0));
ticketPanel.add(lTicketID);
ticketPanel.add(ticketID);
ticketPanel.add(enterButton);
ticketPanel.setVisible(true);
content.add(ticketPanel, BorderLayout.NORTH);
/*********************Ticket Number Listener************************************/
/*********************Label Addition to Frame Content***********************/
JPanel labelPanel = new JPanel();
labelPanel.setLayout(new GridLayout(4,0));
labelPanel.setVisible(true);
labelPanel.add(lEntranceTime);
labelPanel.add(lPaymentTime);
labelPanel.add(lDue);
labelPanel.add(lInserted);
content.add(labelPanel, BorderLayout.WEST);
/*********************Label Only*************************/
}//end PaymentNewGUI constructor
public class enterListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
Ticket ticket = new Ticket();
int ticketIDNumber = Integer.parseInt(ticketID.getText());
String loadMessage = ticket.loadTicket(ticketIDNumber);
lMessage.setText(loadMessage);
ticketPanel.add(lMessage, BorderLayout.SOUTH);
entranceTime = Ticket.entranceTime;
paymentTime = Ticket.paymentTime;
ticketStatus = Ticket.ticketStatus;
balance = Ticket.balance;
if (loadMessage.equals("The Ticket has loaded successfully.")){
System.out.println("" + Ticket.entranceTime);
// lEntranceTime.setText("Entrance Time: " + entranceTime);
} else {
System.out.println("Incorrect Ticket Information Given!");
}
}}
public static void main(String args[]) {
PaymentNewGUI frame = new PaymentNewGUI();
frame.pack();
frame.setVisible(true);
frame.setSize(400,400);
}
}
import java.util.Date;
import java.lang.*;
import java.io.*;
import java.util.Calendar;
public class Ticket {
public TicketInfo x;
public int tNumber;
public static long entranceTime;
public static long paymentTime;
public static String ticketStatus;
public static double balance;
/********************************************************************************************/
public String createTicket(){
tNumber = (int)(Math.random() * 999999)+100000;
File dir = new File("Ticket");
boolean exists = dir.exists();
if (!exists){
dir.mkdir();
} // end if
TicketInfo x = new TicketInfo(entranceTime, paymentTime, ticketStatus, balance);
String fileName = "Ticket/"+tNumber+".dat";
File ticket = new File(fileName);
if(ticket.exists()){
//generateTicketNumber();
return "Try again";
}
else {
try{
FileWriter fileWriter = new FileWriter(fileName);
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write(x.toString());
bufferedWriter.close();
fileWriter.close();
return "A Ticket is Created...Please take your ticket "+ tNumber;
}
catch(IOException e){
return "Sorry, ticket generation currently unavailable. Please call for assistance?";
}
}//end else
} //end create Ticket
public String loadTicket(int tNumber){
String fileName2 = "Ticket/"+tNumber+".dat";
File ticket2 = new File(fileName2);
if(ticket2.exists()){
try{
FileReader fileReader = new FileReader(fileName2);
BufferedReader bufferedReader = new BufferedReader(fileReader);
entranceTime = Long.parseLong(bufferedReader.readLine());
paymentTime = Long.parseLong(bufferedReader.readLine());
ticketStatus = bufferedReader.readLine();
balance = Double.parseDouble(bufferedReader.readLine());
bufferedReader.close();
fileReader.close();
return "The Ticket has loaded successfully.";
}//end try
catch(IOException e){
return "The Ticket could not be read.";
} //end catch
}
else {
return "This Ticket hasn't been registered.";
}
}
}