Hi there i have an application i will attach the source code for it basically what i would like for it to do is if i close the application it should hold the the information in the text area without deleting it and starting it empty again how do i hold the information in there also how would i code a clear butrton to clear a screen that i specifically want to clear lets sat for instance i want clear text area one how will i code a button like that your help will be greatly appreciated
Source Code For reservations class
java
import javax.swing.JOptionPane;
import java.awt.*;
import java.awt.event.*;
public class Reservations extends Frame implements ActionListener
{
Color lightRed = new Color(255, 90, 90);
Color lightGreen = new Color(140, 215, 40);
Rooms room = new Rooms(5,3);
Panel roomPanel = new Panel();
TextArea roomDisplay[] = new TextArea[9];
Panel buttonPanel = new Panel();
Button bookButton = new Button("Book Room");
Panel inputPanel = new Panel();
Label custNameLabel = new Label("Name");
TextField nameField = new TextField(15);
Label custPhoneLabel = new Label("Phone Number");
TextField phoneField = new TextField(15);
Label amountLabel = new Label("Amount Outstanding");
TextField amountField = new TextField(15);
Label numLabel = new Label("Number in Party");
Choice numberOfGuests = new Choice();
CheckboxGroup options = new CheckboxGroup();
Checkbox nonSmoking = new Checkbox("Nonsmoking",false,options);
Checkbox smoking = new Checkbox("Smoking",false,options);
Checkbox hidden = new Checkbox("",true,options);
public Reservations()
{
this.setLayout(new BorderLayout());
roomPanel.setLayout(new GridLayout(2,4,10,10));
buttonPanel.setLayout(new FlowLayout());
inputPanel.setLayout(new FlowLayout());
for (int i=1; i<9; i++)
{
roomDisplay[i] = new TextArea(null,3,5,3);
if(i<6)
roomDisplay[i].setText("Room"+ i + "Nonsmoking");
else
roomDisplay[i].setText("Room"+ i + "Smoking");
roomDisplay[i].setEditable(false);
roomDisplay[i].setBackground(lightGreen);
roomPanel.add(roomDisplay[i]);
}
buttonPanel.add(bookButton);
inputPanel.add(custNameLabel);
inputPanel.add(nameField);
inputPanel.add(custPhoneLabel);
inputPanel.add(phoneField);
inputPanel.add(amountLabel);
inputPanel.add(amountField);
inputPanel.add(numLabel);
inputPanel.add(numberOfGuests);
for(int i=1; i<=4;i++)
numberOfGuests.add(String.valueOf(i));
inputPanel.add(nonSmoking);
inputPanel.add(smoking);
add(buttonPanel, BorderLayout.SOUTH);
add(inputPanel, BorderLayout.CENTER);
add(roomPanel, BorderLayout.NORTH);
bookButton.addActionListener(this);
addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
public static void main(String[] args)
{
Reservations f = new Reservations();
f.setBounds(200,200,600,300);
f.setTitle("Hotel Reservations");
f.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if (hidden.getState())
{
JOptionPane.showMessageDialog(null,"You must select Nonsmoking or smoking.","Error",JOptionPane.ERROR_MESSAGE);
}
else
{
int available = room.bookRoom(smoking.getState());
if (available > 0)
{
roomDisplay[available].setBackground(lightRed);
roomDisplay[available].setText(
roomDisplay[available].getText() +
"\n" +
nameField.getText() +
"\n" +"R"+"\n"+
amountField.getText()+
"Outstanding"+
phoneField.getText() +
"\nparty of " +
numberOfGuests.getSelectedItem()
);
clearFields();
}
else
{
if (smoking.getState())
JOptionPane.showMessageDialog(null,"Smoking is full","Error",JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(null,"Nonsmoking is full. ","Error",JOptionPane.INFORMATION_MESSAGE);
hidden.setState(true);
}
}
}
void clearFields()
{
nameField.setText("");
phoneField.setText("");
amountField.setText("");
numberOfGuests.select(0);
nameField.requestFocus();
hidden.setState(true);
}
}
Source Code For rooms class
ublic class Rooms
{
//declare class variables
int numSmoking;
int numNonSmoking;
boolean occupied[];
public Rooms(int non, int sm)
{
occupied = new boolean[sm+non];
for(int i=0; i<(sm+non); i++)
occupied[i] = false;
numSmoking = sm;
numNonSmoking = non;
}
public int bookRoom(boolean smoking)
{
int begin, end, roomNumber=0;
if(!smoking)
{
begin = 0;
end = numNonSmoking;
}
else
{
begin = numNonSmoking;
end = numSmoking+numNonSmoking;
}
for(int i=begin; i<end; i++)
{
if(!occupied[i])
{
occupied[i] = true;
roomNumber = i+1;
i = end;
}
}
return roomNumber;
}
}
Mod Edit: Please use code tags when posting your code. Code tags are used like so =>

Thanks,
PsychoCoder