• Post Reply Bookmark Topic Watch Topic
  • New Topic

A screen manager?  RSS feed

 
Rob Shan Lone
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I would like the user to choose a shape, alter the size and coordinates of the shape as well as add new shapes. I have devised this program but I am stumped passed the static and non static methods. Also confused as to how to carry out the above statements. I have separate java files for the shapes that are called apon. What would you guys recommend? I have made it into a switch statement, however I think a screen manager may work best for this, what is it and how would you do such a thing?
 
David Crossett
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post all your code? I might see a couple of things... Also, I responded to your *similar* question in another thread...I think the Beginner Forum. Check that out before you respond to this, so I can get both the code and your answer in the same post.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first thing you need to do is ask yourself why do I have all theses static methods in the first place? Remember static methods are owned by the class not instances of the class and as such they are generally used as utility methods, ie a function that does a calculation or manipulation, or in many cases they are used as factory methods to return an object of some class or interface. It should be obvious that in the static methods that you show here, since you are passing in a reference to a ShowShapes, that something isn't right. It appears that they should be parameterless instance methods instead. So instead of calling AlterPosition(Shape); you would instead call Shape.AlterPosition();, etc. What you do to fill the body of those methods is whatever behavior you want to accomplish. It appears that you are just dumping all of the static Shape[] array to the frame in your paint method. You will want to call
repaint() at the end of each of those methods so that the event thread will call your paint() method.
 
Rob Shan Lone
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey thank you for your advice. What exactly did you mean by instead of Altershape(shape); have it shape.Altershape(); what does this actually do. I can only guss that Altershape(shape) passes on the variables to the Altershape method. Whereas shape.Altershape(); invokes Altershape method in the Shape class? err is that right. Forgive the other postings, they looked like dead ends and I was unsure if people would check all forums etc. It was suggested to use the interface model, having said that I have no examples to work from.
I've been struggling with this for days. I have come up with the shape classes through help on the net. I am aware that passing in the variables will change the size of the shape, its implementing all of the tasks in the one program I am having problems with. It is invoking the correct methods, in the simplest way at the right time, with the right variables whilst trying to get it to compile! I've been doing JAVA like this for less than a year and even then we started with "Hello World"
Here are those other files


AND


AND
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!