-1

I am trying to call the private Client() inside of the main method but it is saying

non static method Client can not be referenced from a static context.

public class Client extends JFrame 
{
    private Client() 
    {    
        ImageIcon icon = new ImageIcon(getClass().getResource("/appIcon.png"));

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
        setSize(900, 450); 
        setExtendedState(Frame.MAXIMIZED_BOTH);  
        setLocationRelativeTo(null);
        setIconImage(icon.getImage());
        setVisible(true); 
    }

    public static void main(String[] args) 
    {

    }   
}
Jeroen Vannevel
  • 43,651
  • 22
  • 107
  • 170

1 Answers1

3

Client is a constructor. You call it via new:

Client c = new Client();

You can do that inside main.

If it were an instance method, you'd need an instance to call it on. But because it's a constructor, you use it to create an instance (which you might then call instance methods on).

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • I tried that but I don't know what to do after that, sorry that i didn't include it in my first question. – user3120013 Feb 23 '14 at 16:11
  • @user3120013: Anything you want. The line above will create an instance and call your code in your constructor, which does things like set the size and such. When the constructor returns, `main` gets control back, and you can use `c` to do whatever else you want to do. `c` refers to an instance of your `Client` class, which is a subclass of `JFrame`. So anything you can do with a `JFrame`, you can do with `c`. – T.J. Crowder Feb 23 '14 at 16:13