Hi I want to be able to change the name of the JFrame I am working on. It is currently named SwimmingPoolVolumeCalculator. When I go the Company Tab and enter in a name, I want that name to be shown as the new Title of the JFrame. How can i do this? Here is my code:
public class SwimmingPoolVolumeCalculator<exitHandler> extends JFrame
{
/**
*
*/
private static final long serialVersionUID = 1L;
JLabel welLabel = new JLabel("Welcome");
JComponent date1;
JLabel dateLabel = new JLabel("Today's Date is:");
JFormattedTextField date = new JFormattedTextField(java.util.Calendar
.getInstance().getTime());
JButton exit = new JButton("Exit");
JLabel contractor = new JLabel("Contractor Name");
JLabel customer = new JLabel("Customer");
static JTextField conInput = new JTextField(20);
JLabel address = new JLabel("Address");
JLabel city = new JLabel("City");
JLabel state = new JLabel("State");
JLabel zip = new JLabel("Zip");
static JTextField addInput = new JTextField(20);
static JTextField cityInput = new JTextField(10);
static JTextField stateInput = new JTextField(2);
static JTextField zipInput = new JTextField(6);
JButton update = new JButton("Update");
static JTextArea conPane = new JTextArea(5,20);
static JTextArea custPane = new JTextArea(5,20);
static JTextField custInput = new JTextField(20);
JLabel cAddress = new JLabel("Address");
JLabel cCity = new JLabel("City");
JLabel cState = new JLabel("State");
JLabel cZip = new JLabel("Zip");
static JTextField cAddInput = new JTextField(20);
static JTextField cCityInput = new JTextField(10);
static JTextField cStateInput = new JTextField(2);
static JTextField cZipInput = new JTextField(6);
JButton cUpdate = new JButton("Update");
JLabel company = new JLabel("Company");
JTextField compInput = new JTextField(20);
JButton compUpdate = new JButton("Update");
JLabel compInfo = new JLabel("");
JComboBox degree = new JComboBox();
JLabel inputTemp = new JLabel("Enter Temperature");
JTextField temp = new JTextField(4);
JTextField tempAnswer = new JTextField(4);
JLabel converted = new JLabel("");
JButton tempCalc = new JButton("Convert");
JLabel meters = new JLabel("Meters");
JLabel feet = new JLabel("Feet");
JTextField meterField = new JTextField(15);
JTextField feetField = new JTextField(15);
JButton convert = new JButton("Convert");
JLabel poolLength = new JLabel("Enter Length");
JLabel poolWidth = new JLabel("Enter Width");
JLabel poolDepth = new JLabel("Enter Depth");
JTextField inPoolLength = new JTextField(15);
JTextField inPoolWidth = new JTextField(15);
JTextField inPoolDepth = new JTextField(15);
JButton poolCalc = new JButton("Calculate");
JLabel poolVol = new JLabel("Volume");
JTextField inPoolVol = new JTextField(10);
JLabel tubLength = new JLabel("Enter Length");
JLabel tubWidth = new JLabel("Enter Width");
JLabel tubDepth = new JLabel("Enter Depth");
JTextField inTubLength = new JTextField(15);
JTextField inTubWidth = new JTextField(15);
JTextField inTubDepth = new JTextField(15);
JButton tubCalc = new JButton("Calculate");
JLabel tubVol = new JLabel("Volume");
JTextField inTubVol = new JTextField(10);
public SwimmingPoolVolumeCalculator()
{
setTitle("SwimmingPoolVolumeCalculator");
JTabbedPane qTab = new JTabbedPane();
getContentPane().add(qTab);
JPanel jp1 = new JPanel();
JPanel jp2 = new JPanel();
JPanel jp3 = new JPanel();
JPanel jp4 = new JPanel();
JPanel jp5 = new JPanel();
JPanel jp6 = new JPanel();
JPanel jp7 = new JPanel();
JPanel jp8 = new JPanel();
qTab.addTab("General", jp1);
qTab.addTab("Contractor", jp2);
qTab.addTab("Customer", jp3);
qTab.addTab("Company", jp4);
qTab.addTab("Temperature",jp5);
qTab.addTab("Length", jp6);
qTab.addTab("Pool", jp7);
qTab.addTab("Hot Tubs", jp8);
String celsius = "C";
String fahrenheit = "F";
degree.addItem(celsius);
degree.addItem(fahrenheit);
//Tab 1 Field population
jp1.add(welLabel);
jp1.add(dateLabel);
jp1.add(date);
jp1.add(exit);
//Tab 2 Field population
jp2.add(contractor);
jp2.add(conInput);
jp2.add(address);
jp2.add(addInput);
jp2.add(cityInput);
jp2.add(stateInput);
jp2.add(zipInput);
jp2.add(city);
jp2.add(state);
jp2.add(zip);
jp2.add(update);
jp2.add(conPane);
//Tab 3 Field population
jp3.add(customer);
jp3.add(custInput);
jp3.add(cAddress);
jp3.add(cAddInput);
jp3.add(cCityInput);
jp3.add(cStateInput);
jp3.add(cZipInput);
jp3.add(cCity);
jp3.add(cState);
jp3.add(cZip);
jp3.add(cUpdate);
jp3.add(custPane);
//Tab 4 Field population
jp4.add(company);
jp4.add(compInput);
jp4.add(compUpdate);
jp4.add(compInfo);
//Tab 5 Field population
jp5.add(inputTemp);
jp5.add(temp);
jp5.add(degree);
jp5.add(tempAnswer);
jp5.add(converted);
jp5.add(tempCalc);
//Tab 6 Field population
jp6.add(meters);
jp6.add(meterField);
jp6.add(feet);
jp6.add(feetField);
jp6.add(convert);
feetField.setEditable(false);
//Tab 7 Field population
jp7.add(poolLength);
jp7.add(inPoolLength);
jp7.add(poolWidth);
jp7.add(inPoolWidth);
jp7.add(poolDepth);
jp7.add(inPoolDepth);
jp7.add(poolCalc);
jp7.add(poolVol);
jp7.add(inPoolVol);
inPoolVol.setEditable(false);
//Tab 8 Field population
jp8.add(tubLength);
jp8.add(inTubLength);
jp8.add(tubWidth);
jp8.add(inTubWidth);
jp8.add(tubDepth);
jp8.add(inTubDepth);
jp8.add(tubCalc);
jp8.add(tubVol);
jp8.add(inTubVol);
inTubVol.setEditable(false);
poolCalcHandler pchandler = new poolCalcHandler();
poolCalc.addActionListener(pchandler);
tubCalcHandler tchandler = new tubCalcHandler();
tubCalc.addActionListener(tchandler);
convertButtonHandler cvhandler = new convertButtonHandler();
convert.addActionListener(cvhandler);
updateButtonHandler ubhandler = new updateButtonHandler();
update.addActionListener(ubhandler);
custUpButtonHandler cubhandler = new custUpButtonHandler();
cUpdate.addActionListener(cubhandler);
compButtonHandler comphandler = new compButtonHandler();
compUpdate.addActionListener(comphandler);
}
class poolCalcHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
DecimalFormat num = new DecimalFormat("###.##");
double width;
double length;
double depth;
double volume;
String instring;
instring = inPoolLength.getText();
if (instring.equals(""))
{
instring = "0";
inPoolLength.setText("0");
}
length = Double.parseDouble(instring);
instring = inPoolWidth.getText();
if (instring.equals(""))
{
instring = "0";
inPoolWidth.setText("0");
}
width = Double.parseDouble(instring);
instring = inPoolDepth.getText();
if (instring.equals(""))
{
instring = "0";
inPoolDepth.setText("0");
}
depth = Double.parseDouble(instring);
volume = length * width * depth;
inPoolVol.setText(num.format(volume));
}
}
class tubCalcHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
DecimalFormat num = new DecimalFormat("###.##");
double width;
double length;
double depth;
double volume;
String instring;
instring = inTubLength.getText();
if (instring.equals(""))
{
instring = "0";
inTubLength.setText("0");
}
length = Double.parseDouble(instring);
instring = inTubWidth.getText();
if (instring.equals(""))
{
instring = "0";
inTubWidth.setText("0");
}
width = Double.parseDouble(instring);
instring = inTubDepth.getText();
if (instring.equals(""))
{
instring = "0";
inTubDepth.setText("0");
}
depth = Double.parseDouble(instring);
volume = length * width * depth;
inTubVol.setText(num.format(volume));
}
}
class convertButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
DecimalFormat num = new DecimalFormat("###.##");
double feetConvert;
double knownMeter;
String instring;
instring = meterField.getText();
if (instring.equals(""))
{
instring = "0";
meterField.setText("0");
}
knownMeter = Double.parseDouble(instring);
feetConvert = knownMeter * 3.281;
feetField.setText(num.format(feetConvert));
}
}
class updateButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
BufferedWriter bufferedWriter = null;
try
{
bufferedWriter = new BufferedWriter(new FileWriter("contractor.txt"));
bufferedWriter.write(conInput.getText());
bufferedWriter.newLine();
bufferedWriter.write(addInput.getText());
bufferedWriter.newLine();
bufferedWriter.write(cityInput.getText()+ ", "+stateInput.getText()+ " "+zipInput.getText());
}catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
try {
bufferedWriter.close();
} catch (IOException e1) {
e1.printStackTrace();
}
try {
if (bufferedWriter != null) {
bufferedWriter.flush();
bufferedWriter.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader("contractor.txt"));
} catch (FileNotFoundException e2) {
e2.printStackTrace();
}
String str = null;
try {
while ((str = in.readLine()) != null)
{
conPane.append(str);
}
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
class custUpButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
BufferedWriter bufferedWriter = null;
try
{
bufferedWriter = new BufferedWriter(new FileWriter("customer.txt"));
bufferedWriter.write(custInput.getText());
bufferedWriter.newLine();
bufferedWriter.write(addInput.getText());
bufferedWriter.newLine();
bufferedWriter.write(cityInput.getText()+ ", "+stateInput.getText()+ " "+zipInput.getText());
}catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
try {
bufferedWriter.close();
} catch (IOException e1) {
e1.printStackTrace();
}
try {
if (bufferedWriter != null) {
bufferedWriter.flush();
bufferedWriter.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader("customer.txt"));
} catch (FileNotFoundException e2) {
e2.printStackTrace();
}
String str = null;
try {
while ((str = in.readLine()) != null)
{
custPane.append(str);
}
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
class compButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
compInfo.setText(compInput.getText());
}
}
public static void main(String[] args)
{
SwimmingPoolVolumeCalculator instance = new SwimmingPoolVolumeCalculator();
instance.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
instance.setVisible(true);
instance.setSize(510, 400);
}
}
It should be as easy as
private void New_Name()
{
this.setTitle(newTitle.getText());
}
But that isn't working for me. Any help would truly be appreciated. Thanks!