Your program is creating two Shapes objects actually, one of which has the diameter field set correctly but is not being displayed, and the other, which retains diameter's default value of 0 and which is displayed.
Suggestions:
- Don't draw directly in a JFrame, but rather in the
paintComponent(Graphics g)
method override of a JPanel that is held by and displayed in the JFrame. There are many reasons for this, but for one, since thepaint(...)
method is not only responsible for painting a component but also its borders and children, this will prevent you from causing problems whenpaint(...)
tries to paint a GUI's children and borders. It also will help your animations (which surely you will be doing soon) to be smooth given Swing component's default use of double buffering. - Always call the
super.paintComponent(g)
method within your JPanel'spaintComponent
override. This will allow Swing to erase images that need to be erased. - Don't create two Shapes objects, but rather only one. This will simplify things greatly and will allow you to set the diameter value of the one and only object of importance.
- After changing the diameter field's value, call repaint on your GUI so that the displayed JPanel's paintComponent will be called.