Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Java GUI

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Marshal
Posts: 76487
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 76487
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 76487
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way: the paintComponent method should have protected access and should start with super.paintComponent(g);
 
God is a comedian playing for an audience that is afraid to laugh - Voltair. tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic