Question

Well I have a Calculator ready in my main class, but I want now to move it in a class but not in main, and when I do it I get some errors. I can create my JPanel with name asd but I can't use any of this:

asd.setTitle("Calculator");
asd.setSize(200, 250);
asd.setResizable(false);

I get an error "package asd does not exist"! I have to make the calculator again or am I doing something wrong?

Was it helpful?

Solution

Seems like you created the Jpanel using command

JPanel asd = new asd();

instead of

JPanel asd = new JPanel();

EDIT: based on the code in the comments, its because you're calling methods globally, you can only instantiate objects globally.

If you want to generate entire panel in the constructor, your code should look like this:

 public class kompiouteraki{
 // attributes here    

        public kompiouteraki(){
        // your code here
        }
 } 

For more information, about how to set up your class, visit class structure

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top