tags:

views:

30

answers:

3

This method shows a new window in my application:

public void ShowNewCustomerView() {
    if (NewCustomer == null) NewCustomer = new NewCustomerView(this);
    NewCustomer.setVisible(true);
}

The class NewCustomerView has this method:

public void ClearFields() {
    txtAddress.setText("");
    txtCity.setText("");
    txtCompanyName.setText("");
    txtCustomerNumber.setText("");
    txtOrganisationNumber.setText("");
    txtPhoneNumber1.setText("");
    txtPhoneNumber2.setText("");
    txtPostalCode.setText("");
    txtReferenceName.setText("");
}

How can I run that method before the line:

NewCustomer.setVisible(true);

Adding this:

NewCustomer.ClearFields();

...does not work... why is that?

This is what error I get: Cannot find symbol (method ClearFields()) Class: javax.Swing.JFrame

But I created a new instance of NewCustomerView which extends JFrame?? Right?

+2  A: 

It sounds like your defining your new Frame as:

JFrame frame = new NewCustomerView();

Instead you should be doing:

NewCustomerView frame = NewCustomerView();
Jason Nichols
+1  A: 

From your comments I think you declare NewCustomer like this:

JFrame NewCustomer; 

If so try declaring:

NewCustomerView NewCustomer;

or

public void ShowNewCustomerView() {
    if (NewCustomer == null) NewCustomer = new NewCustomerView(this);
    ((NewCustomerView)NewCustomer).ClearFields();
    NewCustomer.setVisible(true);
}
bruno conde
That worked, I had declared it as a JFrame, thank you!
Johan
+1  A: 

The following error message is a hint as to what is going on:

Cannot find symbol (method ClearFields()) Class: javax.Swing.JFrame

What the message is saying is that there is a call to the ClearFields method on a JFrame object. This makes sense, as there is no ClearFields method on the JFrame object.

What this seems to indicate is that the NewCustomerView object is being declared as a JFrame rather than a NewCustomerView.

I'm going to guess the line which declares the NewCustomer object is written like this:

JFrame NewCustomer = new NewCustomerView();

What that is doing is to handle the new NewCustomerView object as a JFrame -- therefore, when trying to call the ClearFields method, one is trying to call the JFrame.ClearFields method, which doesn't exist.

Try the following instead, so the object that is being declared is handled as a NewCustomerView object:

NewCustomerView NewCustomer = new NewCustomerView();

Also as a note, in Java, variable names are written with a lower-case letter, followed by uppercase letter for each word boundary, for example, in the above example, NewCustomer would be written newCustomer.

coobird