• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Displaying status bar in JApplet

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,
I'm an absolute beginner to Java and this question may seem trivial, but I tried to solve this problem for the past 3 days and it seems that I'm stuck... I posted it on Java Beginner board, but no one replied and I really need to solve this one, so I'm turning to inrtermedate board for help!
I'm writing a JApplet which displays a few GUI compotnents (JTextField, JLabel) and which is also supposed to display a message in the status bar.
I created all the GUI components objects and attached them to the interface in method init().
In method paint() I used showStatus method to display a message in the satus bar. I also used repaint().
The problem is that when the applet loads it shows only the status bar message - and no interface that I created in init().
Why is that?
I tried puting showStatus in intit() but it gets wiped out by the "Applet started " message.
I also noticed that the repaint() wipes out the GUI components that I created in init(). But if I don't use I can't display the status bar message (but the interface is intact!).
How do I display both the interface and the status bar? Could anyone help me understand this?
TIA...
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This will probably fine an answer for you under Applets forum. I'll move it there for you
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I think your problem is interesting. I also think you are on the right track with your approach ...
The reason your overridden paint method doesn't draw your GUI elements is because the paint routine doesn't get called until you call setVisible(true). Then, as I understand it, your paint routine just performs one thing: showStatus("Something").
I got the code to work by making one small change. The first line in the overridden paint routine was a call to super.paint(g). That allowed the GUI stuff to be drawn and the status to be shown.

Manfred.
 
Agnes Lapka
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Manfred - you are right!
I modified the code according to your instructions and it works!
Thank you so much !
I don't quite understand what exactly the super.paint() does (I only started learning java 2 weeks ago), but I'm going to read about this method as soon as I finish with the little JApplet.
Thank you!
A.
 
You can thank my dental hygienist for my untimely aliveness. So tiny:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic