• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Displaying status bar in JApplet

Posts: 23
  • Mark post as helpful
  • send pies
  • 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?
Posts: 3341
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
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.

Agnes Lapka
Posts: 23
  • Mark post as helpful
  • send pies
  • 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!
You ridiculous clown, did you think you could get away with it? This is my favorite tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic