Im new to java swing, and Ive got a little problem. So I've got a class Flight.java. In there I have a method displaySeat2D(). First I had this done with the scanner. Now I have to use swing. So basically I made text fields to take in number of rows and seats. Now Im trying to display this in my JPanel. Not realy sure how to display this. Id try to keep it simple and display it like in Eclipse console with number "0".
For example if I enter 4 rows and 4 seats in a row It would be displayed like:
0000
0000
0000
0000
This is the code.
In eclipse console the method and and display work fine.
FLIGHT class
public void displaySeat2D(){
for (int i = 0; i < arraySeatPassenger.length; i++) {line
System.out.println("");
for (int j = 0; j < arraySeatPassenger[i].length; j++) {// seat
if (arraySeatPassenger[i][j]== null) {
System.out.print("0");//
} else {
System.out.print("1");
}
}
}System.out.println("");
}
Now that Im working with swing I have to make some UI that accepts rows and seats in a row. I made this already
UserInterface class User interface example
btnConfirm.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
flight.setRowNr(Integer.parseInt(tf_SetRows.getText()));
flight.setSeatNr(Integer.parseInt(tf_SetSeats.getText()));
flight.setaArraySeatPassenger(new Passenger[flight.getRowNr()][flight.getSeatNr()]);
lblDisplay.setText("U have seats left: "+String.valueOf(flight.getRowNr()*flight.getSeatNr()));
System.out.println();
}
});
So what I dont know now is, how to display it like in Eclipse console. When I press on a button Id like this public void displaySeat2D() method to display it like I wrote it, up there.
This ofcourse displays it in eclipse console. So the question from my side is how to display it in some TextArea?
btnSeatDisplay.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
flight.displaySeat2D();
}
});
Tnx for your help in advance Im new to Swing and Java so I apologize for such a silly question.