These are the classes i have currently:
/**
* Project One
* @author
*/
public class ProjectOne {
public static void main(String[] args) {
TicketForm jframe;
jframe = new TicketForm();
jframe.setVisible(true);
}
}
Basic main class that merely calls the JFrame and then is basically done.
/**
* Ticket Form Class
* @author
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TicketForm extends JFrame implements ActionListener {
// Private class constants
private static final int Frame_Width = 400;
private static final int Frame_Height = 500;
private static final int Frame_X = 150;
private static final int Frame_Y = 250;
private JButton btnReport;
private JButton btnReset;
private JTextField txtCountA;
private JTextField txtCountB;
private JTextField txtCountC;
private JTextField txtPriceA;
private JTextField txtPriceB;
private JTextField txtPriceC;
private JLabel lblBlank;
private JLabel lblCount;
private JLabel lblPrice;
private JLabel lblSeatA;
private JLabel lblSeatB;
private JLabel lblSeatC;
private JTextArea txtReport;
Seat countA;
Seat countB;
Seat countC;
Seat priceA;
Seat priceB;
Seat priceC;
Report report;
public TicketForm() {
// Initializing JFrame properties
this.setTitle("Concert Ticket Calculator");
this.setSize(Frame_Width, Frame_Height);
this.setLocation(Frame_X, Frame_Y);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// Gain reference to the contentPane object of this JFrame
Container contentPane = this.getContentPane();
// Set the layout manager of the contentPane
contentPane.setLayout(new BorderLayout());
// Start creating a GUI control object :)/>
btnReport = new JButton("Create Report");
btnReport.addActionListener(this);
btnReset = new JButton("Reset");
btnReset.addActionListener(this);
lblCount = new JLabel("Count");
lblPrice = new JLabel("Price ($)");
lblSeatA = new JLabel("Enter for seat A:");
lblSeatB = new JLabel("Enter for seat B:");
lblSeatC = new JLabel("Enter for seat C:");
lblBlank = new JLabel("");
txtCountA = new JTextField();
txtCountB = new JTextField();
txtCountC = new JTextField();
txtPriceA = new JTextField();
txtPriceB = new JTextField();
txtPriceC = new JTextField();
txtReport = new JTextArea();
report = new Report();
// Construct a JPanel object to hold input controls
JPanel dataPane = new JPanel();
dataPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Enter Data"), BorderFactory.createEmptyBorder(10,10,10,10)));
dataPane.setLayout(new GridLayout(4, 3, 5, 5));
dataPane.add(lblBlank);
dataPane.add(lblCount);
dataPane.add(lblPrice);
dataPane.add(lblSeatA);
dataPane.add(txtCountA);
dataPane.add(txtPriceA);
dataPane.add(lblSeatB);
dataPane.add(txtCountB);
dataPane.add(txtPriceB);
dataPane.add(lblSeatC);
dataPane.add(txtCountC);
dataPane.add(txtPriceC);
contentPane.add(dataPane, BorderLayout.NORTH);
JPanel reportPane = new JPanel();
reportPane.setBorder(BorderFactory.createTitledBorder("Report"));
reportPane.add(txtReport);
contentPane.add(reportPane, BorderLayout.CENTER);
JPanel buttonPane = new JPanel();
buttonPane.add(btnReport);
buttonPane.add(btnReset);
contentPane.add(buttonPane, BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent event) {
if (event.getSource() == btnReport) {
countA.setCountA(txtCountA.getText());
countB.setCountB(txtCountB.getText());
countC.setCountC(txtCountC.getText());
priceA.setPriceA(txtPriceA.getText());
priceB.setPriceB(txtPriceB.getText());
priceC.setPriceC(txtPriceC.getText());
txtReport.setText(report.getReport());
} else {
System.out.println("You clicked the reset");
txtCountA.setText("");
txtCountB.setText("");
txtCountC.setText("");
txtPriceA.setText("");
txtPriceB.setText("");
txtPriceC.setText("");
txtReport.setText("");
}
}
}
Thats my JFrame class that sets everything up.
/**
* Seat Class
* @author
*/
public class Seat {
private int cA;
private int cB;
private int cC;
private int pA;
private int pB;
private int pC;
private int totalA;
private int totalB;
private int totalC;
private int totalS;
// Get and Set variables
public void setCountA(String countA) {
int cA = Integer.parseInt(countA);
int totalA = (cA * pA);
}
public int getCountA() {
return cA;
}
public int getTotalA() {
return totalA;
}
public void setCountB(String countB) {
int cB = Integer.parseInt(countB);
int totalB = (cB * pB);
}
public int getCountB() {
return cB;
}
public int getTotalB() {
return totalB;
}
public void setCountC(String countC) {
int cC = Integer.parseInt(countC);
int totalC = (cC * pC);
}
public int getCountC() {
return cC;
}
public int getTotalC() {
return totalC;
}
public void setPriceA(String priceA) {
int pA = Integer.parseInt(priceA);
}
public int getPriceA() {
return pA;
}
public void setPriceB(String priceB) {
int pB = Integer.parseInt(priceB);
}
public int getPriceB() {
return pB;
}
public void setPriceC(String priceC) {
int pC = Integer.parseInt(priceC);
}
public int getPriceC() {
return pC;
}
public void setTotalS() {
totalS = (totalA + totalB + totalC);
}
public int getTotalS() {
return totalS;
}
}
This is a seat class, it's meant to do the math for the whole thing.
/**
* Report Class
* @author
*/
public class Report {
Seat countA;
Seat countB;
Seat countC;
Seat priceA;
Seat priceB;
Seat priceC;
Seat totalA;
Seat totalB;
Seat totalC;
Seat totalS;
public String getReport() {
int seatCountA = countA.getCountA();
int seatCountB = countB.getCountB();
int seatCountC = countC.getCountC();
int seatPriceA = priceA.getPriceA();
int seatPriceB = priceB.getPriceB();
int seatPriceC = priceC.getPriceC();
int seatTotalA = totalA.getTotalA();
int seatTotalB = totalB.getTotalB();
int seatTotalC = totalC.getTotalC();
int seatTotalS = totalS.getTotalS();
String report = ("Tickets Sold Price Total\n"
+ "------------ ----- -----\n"
+ "Seat A " + seatCountA + " $" + seatPriceA + " $" + seatTotalA + "\n"
+ "Seat B " + seatCountB + " $" + seatPriceB + " $" + seatTotalB + "\n"
+ "Seat C " + seatCountC + " $" + seatPriceC + " $" + seatTotalC + "\n"
+ "\n"
+ "Total Sales: $" + seatTotalS);
return report;
}
}
And finally the Report class which is just supposed to take the data and generate the output.
The whole project is a form that calculates the total sales based on the number of each type of ticket sold: A, B and C. And the value of each ticket, all of which are set by the user in 6 text fields. The seat class should take the data from the ticketform class, multiply the number of tickets by the cost for each seat type and put them into new variables. The report class is then supposed to take the variables from the seat class and generate a report based on it and return it so it can be outputted through the ticketform class.
I know it's probably a mess but i've only been learning Java for less than 2 months so far. So can anyone point out whats going on with this? Far as i can see it shouldnt give a null error for values in the Report class because they arent actually called until after the button is clicked. Or thats how it's supposed to be anyway.

New Topic/Question
Reply



MultiQuote





|