• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why cant i call the constructor from the other class  RSS feed

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys, im going crazy slowly and i cannot see what ive done wrong and im hoping someone can push me into the right direction. So i have this code we are supposed to get 2 rectangles printed out on a jpanel stating area and perimeter. I know i havent added the string to print out perimeter and area but im stuck at something at the moment and that is that i cant call my constructor from an other class to make my program work.
SO i have to classes and here they are: The error comes at row 30 and 33 on the second java file. It says that method cannot be applied by given types bla bla.



and here is the other that is trying to call for the constructos




Im seriously out of ideas. I looked through my books and nothing seems strange to me. Could someone help give me a nudge? Cheers
 
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your main method you call these two constructors, not those of your own classes:



did you try this?
 
Patricia Andersen
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hey thank you , i tried but still the same error.
I dont get why i get errors on my fill rectangle method. Im supposed to call the methods this way....
 
Ranch Hand
Posts: 178
2
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In line 39 of Paron class, you have to create an instance of the same class. Not a another JPanel.


And there are errors in Rektangel class too.
Look carefully at the getHeight() and getWidth() methods in that class.(Line 54 and 60)
Those code lines have to be changed as:


This will work..
 
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Patricia Andersen wrote:The error comes at row 30 and 33 on the second java file. It says that method cannot be applied by given types bla bla.

Copy and paste the error message here, don't paraphrase.
 
Patricia Andersen
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramesh Pramuditha Rathnayake wrote:In line 39 of Paron class, you have to create an instance of the same class. Not a another JPanel.


And there are errors in Rektangel class too.
Look carefully at the getHeight() and getWidth() methods in that class.(Line 54 and 60)
Those code lines have to be changed as:


This will work..



Hey thanks, it kind of worked, but my rectangles are now overlapping eachother, so only one shows and i guess its because they have been given the same values. Not really sure how to change this, and if i have to create new set and get methods and constructors for each rectangle?
Im sorry im so confused and lost, im a newbie and we dont even have teachers to help us, this is a distance course :P
The area and perimeter are also supposed to be calculated but i guess there are needs for more methods to gain that in the Paron c lass. Thanks for your help
 
Ramesh Pramuditha Rathnayake
Ranch Hand
Posts: 178
2
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The position of you rectangle can be changed using setX(int) and setY(int) methods. The xposition and yposition of both rectangles are same here. Therefore they are overlapping.

Finding the area and perimeter is an easy task. Try to do it your own..
 
Patricia Andersen
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramesh Pramuditha Rathnayake wrote:The position of you rectangle can be changed using setX(int) and setY(int) methods. The xposition and yposition of both rectangles are same here. Therefore they are overlapping.

Finding the area and perimeter is an easy task. Try to do it your own..


Thanks Ramesh, thats what i suspected... i have now changed a bit in my code . Entered some values into the rektangel objects that calls them from the constructor of the other class. But im not sure if i shall do that same with the X and Y position. I feel like the setX() methods can only take 1 value at the time...is that so?
 
Patricia Andersen
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So i have fixed some things but i feel like im far from results and no where on the internet do i find any similar tutorial om how to fix my methods. Im so dizzy and lost that probably its some shitty mistake that i just cant see cus im over my head.

Ill show you what i fixed, but now really nothing works, i just get a blank JFrame. If anyone could tell me how do i create a seperate height, width, x and y value for each rectangle? im trying to do that in this renewed code but when i go down to the methods to implement each value i get confused and stuck.
If i could find something like this on the net to help me understand ill be grateful. I just dont get it, ive searched all day again today and i find nothing.

so here it is the renewed code :






next class



you have been so helpful so far, i do not want anyone to do my homework, i just wanna understand and i believe if no one can explain or give you a nudge then you cant learn



 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!