Я пытаюсь проверить, существует ли введенный номер комнаты в списке массивов:
private void initAction(RoomsWindow rw, RoomAddUpdateWindow raw) {
btnConfirm.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ArrayList<Room> rooms = RoomsWindow.loadRoom();
for (Room r : rooms) {
r.getNumber();
}
if (rooms.equals(txtNumber.getText())) {
JOptionPane.showMessageDialog(null, "Room number already exists!", "Add",
JOptionPane.PLAIN_MESSAGE);
} else {
File fileRooms = new File("src/txt/rooms");
try {
FileWriter fw = new FileWriter(fileRooms, true);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter pw = new PrintWriter(bw, true);
String tv = (String) cbTV.getSelectedItem();
if (cbTV.getSelectedItem().equals("Yes")) {
tv = "true";
} else {
tv = "false";
}
String miniBar = (String) cbMiniBar.getSelectedItem();
if (cbMiniBar.getSelectedItem().equals("Yes")) {
miniBar = "true";
} else {
miniBar = "false";
}
pw.println(txtNumber.getText() + "|" + txtType.getText() + "|" + txtName.getText() + "|"
+ txtBeds.getText() + "|" + tv + "|" + miniBar + "|" + "false" + "|" + "false");
pw.close();
JOptionPane.showMessageDialog(null, "Succesfully", "Done", JOptionPane.PLAIN_MESSAGE);
raw.setVisible(false);
rw.setVisible(false);
RoomsWindow newRoomWindow = new RoomsWindow();
newRoomWindow.setVisible(true);
} catch (IOException exc) {
exc.printStackTrace();
}
}
}
});
}
Если он существует, я не хочу записывать в файл, просто напечатать сообщение в
dialog: OptionPane.showMessageDialog(null, "Room number already exists!", "Add",
JOptionPane.PLAIN_MESSAGE);
РЕДАКТИРОВАТЬ Вот мой класс Room
: сущности пакета;
public class Room {
int number;
String type;
String name;
int beds;
Boolean tv;
Boolean miniBar;
Boolean ocupied;
Boolean deleted;
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getBeds() {
return beds;
}
public void setBeds(int beds) {
this.beds = beds;
}
public Boolean getTv() {
return tv;
}
public void setTv(Boolean tv) {
this.tv = tv;
}
public Boolean getMiniBar() {
return miniBar;
}
public void setMiniBar(Boolean miniBar) {
this.miniBar = miniBar;
}
public Boolean getOcupied() {
return ocupied;
}
public void setOcupied(Boolean ocupied) {
this.ocupied = ocupied;
}
public Boolean getDeleted() {
return deleted;
}
public void setDeleted(Boolean deleted) {
this.deleted = deleted;
}
public Room(int number, String type, String name, int beds, Boolean tv, Boolean miniBar, Boolean ocupied,
Boolean deleted) {
super();
this.number = number;
this.type = type;
this.name = name;
this.beds = beds;
this.tv = tv;
this.miniBar = miniBar;
this.ocupied = ocupied;
this.deleted = deleted;
}
}
Иначе, конечно, я хочу успешно записать в файл.Где я не прав?