• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Swing drawing

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

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

 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it is perhaps better to have (as the first line in paintComponent())
super.paintComponent(g);
 
reply
    Bookmark Topic Watch Topic
  • New Topic