Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not drawing the Button?

 
Jing Liang
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My codes able to draw the ellipse but not the button("Start"). I added the button to the JComponent. Could someone tell me what I did wrong and help me out? Thanks in advance

 
Eric Daly
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm still a noob when it comes to swing, but I noticed you're trying to add your button to the PaintSurface. I would think you should make the button on top of the pane but not inside PaintSurface. So you could add the button during init(). Or else maybe you're just drawing your entire ellipse over the button, so you never see it. And you don't have any actionlisteners yet, so you can't test to see if the button works anyhow.
 
Jing Liang
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works. Thanks Eric
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you add super.paint(g) as the first line of the paint method, does it work?
 
Eric Daly
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keith, I tried your suggestion, but the button still did not show up. I wonder what you could do to actually get the button to appear...
 
Jing Liang
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The button shows up when I add the button at the init() BorderLayout.NORTH
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic