• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hint on implementing methods, please  RSS feed

 
Marcus Rauchfuss
Ranch Hand
Posts: 51
1
Eclipse IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following class is part of a homework assignment:



And this is the Model Class the above class references:




I have to implement the methods for what is happening if on some panel the action selected are Remove/Move/Change/Resize (Draw is already implemented).
The Applet in question draws ovals or rectangles on the screen and you can change the fill-color and outline-color of the shape. All this works already. I have dabbled with the move-method, but am not going anywhere.

Any hints?
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you writing applets? They are obsolete.
You can see the poor design implicit in having one Listener. Those multiple ifs are a really bad idea if there is any maintenance to be done.
Have you been told you use MouseListeners? you should avoid that and use buttons with action listeners instead. Always use the highest level listener you can. Action listeners are high‑level and mouse listeners are low‑level. Use one listener per action required.
And make the actionPerformed or similar methods very short. Simply call another method which does the action.

Another thing you are doing wrong is using the same content in each of the if blocks. You seem to be doing the same whether the action is MOVE or REMOVE.
 
Marcus Rauchfuss
Ranch Hand
Posts: 51
1
Eclipse IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Campbell,

you asked me the question about applets before and I give you the same answer: It is a homework assignment, as stated in the first line.

I know I have all the same code in the blocks but this is because I stopped there, I have actually deleted code I used before because it did not work.

I have also by now tested this method in the model class:



And it does not do anything (as far as I have tested it anyway). So maybe I should start there.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start by putting some print instructions in that method, to confirm that it is being called at all.
 
Marcus Rauchfuss
Ranch Hand
Posts: 51
1
Eclipse IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that's how I found out it does not work.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marcus Rauchfuss wrote:Any hints?

Yes: Take ONE method at a time. And don't move on to the next one until you know that the previous one works. Always.

Also: You have a fabulous amount of code there; and there's no way for us to know what was supplied for you, and what you wrote yourself. So, for next time (or maybe this one):

1. Keep a copy of what you were given.

2. If it doesn't compile, add "stub" implementations until it does. And the simplest way to do that (usually) is to simply add:

throw new UnsupportedOperationException();

to every method you've been asked to complete. (It may already have been done for you)

3. Save the version that compiles.

Now you're ready to start coding. So, go back to the first line of this post...

Programming is a lot easier when you isolate your problems.

HIH

Winston
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marcus Rauchfuss wrote:Yes, that's how I found out it does not work.

Marucs,

People here want to help you. We really do. But if you want that help, your job is to make it as easy as possible for us to do so. I would strongly suggest you read our FAQ on HowToAskQuestionsOnJavaRanch, and specifically the one titled ItDoesntWorkIsUseless.

Just posting "It doesn't work" really puts the burden on us. We'd have to take your code, compile it, run it, and try and figure out what you are thinking. If, instead, you told us what EXACTLY you did, what EXACTLY you see, and what EXACTLY you expect, it saves anyone here from having to do all that work you've already done, and lets us understand what your misconceptions may be (if you in fact have any).
 
Knute Snortum
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have to refresh the screen?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!