Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Swing drawing  RSS feed

 
Timo Lumme
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i know how draw with applets but things seem differnt in swing drawing..
point me to right direction ..

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> but things seem differnt in swing drawing..

not really.

you have a JPanel with paintComponent(), but you don't add it to anything.
the panel you add to the frame is a separate panel
JPanel panel = new JPanel();
c.add(panel);

even adding the correct panel to the frame won't do anything because
you changed the frame's layout to FlowLayout, meaning the panel with
the graphics, without a component or a preferredSize(), will be sized to 0,0.
leave the frame as a default BorderLayout and the panel will take up all the size 800,600

try these couple of changes
 
Timo Lumme
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you,

i have a in my paintcomponent to draw a red ball and thread that moves the ball but how clear the screen the in between so that it doesnt draw a red line thru the screen?
 
Timo Lumme
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i figured it out!,
needed that piece of code before i draw anything on screen,(clear it)
not after.

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is perhaps better to have (as the first line in paintComponent())
super.paintComponent(g);
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!