This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java GUI  RSS feed

 
samarth mishra
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code moves a oval from a place to other, but when i click on the restart button it creates the new frame which should work like the same, but it's not moving

 
Campbell Ritchie
Marshal
Posts: 55687
162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I have added the code tags to your code, which you should always use, but when I did I noticed you have made the mistake of using tabs for indenting. Even so, see how much better it looks

You have some very poor design in that class. What you have done is wrap the entire GUI in a class which implements the ActionListener interface. I would prefer to make the Listener an anonymous class there, because you are only using it once, but it would work as well if you make it a private inner class (probably best inside the GUI class). Also, move the code which creates the display out of the method called by the action performed method. You only want code to move the display in side action performed.
 
samarth mishra
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay I did as you said . Made that different inner class . But now in the new frame that is being created on clicking the restart button . I want to see that Oval moving.



 
samarth mishra
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay I did as you said . Made that different inner class . But now in the new frame that is being created on clicking the restart button . I want to see that Oval moving.

 
Campbell Ritchie
Marshal
Posts: 55687
162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are still calling the go() method. All you want in the action performed method is a call which starts off the animation.
 
Campbell Ritchie
Marshal
Posts: 55687
162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way: the paintComponent method should have protected access and should start with super.paintComponent(g);
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!