Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Why doesn't my JApplet repaint itself automatically?

Reply
Thread Tools

Why doesn't my JApplet repaint itself automatically?

 
 
Z
Guest
Posts: n/a
 
      02-16-2007
The following simple JApplet doesn't repaint itself when the window is
occluded and then exposed or when it's minimized and then maximized.

I get the same results whether I use appletviewer or my browser.

What am I doing wrong?


JAppletTest.java :

public class JAppletTest extends javax.swing.JApplet
{
public void paint(java.awt.Graphics g)
{
super.paint(g);
g.drawString("Hello world!", 50, 50);
}
}


JAppletTest.html :

<html>
<applet code="JAppletTest" width="200" height="100">
</applet>
</html>
 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      02-16-2007
Z wrote:
> The following simple JApplet doesn't repaint itself when the window is
> occluded and then exposed or when it's minimized and then maximized.
>
> I get the same results whether I use appletviewer or my browser.
>
> What am I doing wrong?
>
>
> JAppletTest.java :
>
> public class JAppletTest extends javax.swing.JApplet
> {
> public void paint(java.awt.Graphics g)
> {
> super.paint(g);
> g.drawString("Hello world!", 50, 50);
> }
> }
>
>
> JAppletTest.html :
>
> <html>
> <applet code="JAppletTest" width="200" height="100">
> </applet>
> </html>


I'm not sure why but take out the super.paint() and it will work fine.

--

Knute Johnson
email s/nospam/knute/
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      02-16-2007
On Feb 16, 5:14 pm, Z <(E-Mail Removed)> wrote:
> The following simple JApplet doesn't repaint itself

....
>
> public class JAppletTest extends javax.swing.JApplet
> {
> public void paint(java.awt.Graphics g)


Swing components should overidr painComponent()


Andrew T.

 
Reply With Quote
 
Knute Johnson
Guest
Posts: n/a
 
      02-16-2007
Andrew Thompson wrote:
> On Feb 16, 5:14 pm, Z <(E-Mail Removed)> wrote:
>> The following simple JApplet doesn't repaint itself

> ...
>> public class JAppletTest extends javax.swing.JApplet
>> {
>> public void paint(java.awt.Graphics g)

>
> Swing components should overidr painComponent()
>
>
> Andrew T.
>


There is no paintComponent() for JApplet.

--

Knute Johnson
email s/nospam/knute/
 
Reply With Quote
 
Chris Uppal
Guest
Posts: n/a
 
      02-16-2007
Andrew Thompson wrote:

> Swing components should overidr painComponent()


That is almost as revealing as the recent "Google is my fiend", or "Java is not
a god choice"

-- chris



 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      02-16-2007
On Feb 17, 4:50 am, Knute Johnson <(E-Mail Removed)>
wrote:
> Andrew Thompson wrote:
> > On Feb 16, 5:14 pm, Z <(E-Mail Removed)> wrote:
> >> The following simple JApplet doesn't repaint itself

> > ...
> >> public class JAppletTest extends javax.swing.JApplet
> >> {
> >> public void paint(java.awt.Graphics g)

>
> > Swing components should overidr painComponent()

...
> There is no paintComponent() for JApplet.


Huh! Good point.

I am so used to putting everything
in a JPanel (even animated rendering)
before it goes into a ..
JApplet/Frame/Dialog/OptionPane/Internal..
...you get the picture, that I never
noticed that!

( I should have checked the JDocs,
before I opened my big mouth

Andrew T.

 
Reply With Quote
 
Z.
Guest
Posts: n/a
 
      02-18-2007
Knute Johnson wrote:
> I'm not sure why but take out the super.paint() and it will work fine.


Hmm. Very odd.

My text says :

"This statement [super.paint(g);] should be the first statement in every
applet's paint method. Omitting it can cause subtle drawing errors in
applets that combine drawing and GUI components."

I must be making some fundamental mistake here. The JApplet and Applet
docs at sun.com have offered no help or hints.

Does anyone have any other ideas or suggestions?

--
Real Estate in '07: "It's dead, Jim."
 
Reply With Quote
 
Knute Johnson
Guest
Posts: n/a
 
      02-18-2007
Z. wrote:
> Knute Johnson wrote:
>> I'm not sure why but take out the super.paint() and it will work fine.

>
> Hmm. Very odd.
>
> My text says :
>
> "This statement [super.paint(g);] should be the first statement in every
> applet's paint method. Omitting it can cause subtle drawing errors in
> applets that combine drawing and GUI components."
>
> I must be making some fundamental mistake here. The JApplet and Applet
> docs at sun.com have offered no help or hints.
>
> Does anyone have any other ideas or suggestions?
>


The problem is that paint() only gets called once on a JApplet. I don't
think it was ever intended that you draw on the JApplet and have
components on it at the same time. If you want to do both, use a plain
Applet. It will work just fine.

--

Knute Johnson
email s/nospam/knute/
 
Reply With Quote
 
Z.
Guest
Posts: n/a
 
      02-18-2007
Knute Johnson wrote:
> The problem is that paint() only gets called once on a JApplet. I don't
> think it was ever intended that you draw on the JApplet and have
> components on it at the same time. If you want to do both, use a plain
> Applet. It will work just fine.


Neing new to Java, I want to make sure I understand ... on repaint, the
superclass (applet's) paint() gets called, not the JApplet's paint().

Is that right?

That would explain my problem.

Do you have a URL or some other reference that explains what method gets
called to repaint a JApplet?

--
Real Estate in '07: "It's dead, Jim."
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      02-18-2007
On Feb 17, 5:22 am, "Chris Uppal" <(E-Mail Removed)-
THIS.org> wrote:
> Andrew Thompson wrote:
> > Swing components should overidr painComponent()

>
> That is almost as revealing as the recent "Google is my fiend", or "Java is not
> a god choice"


LOL! I'll upgrade my earlier
'should have checked the JDocs' to
'should have *copy/pasted* from the
JDocs'!

Andrew T.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
obtain element name, or attribute and value of the document name itself, and some elemnts and attributes from an ancestor or the node itself using xquery Jeff Kish XML 4 10-30-2008 05:47 PM
Best way to force a JComponent to repaint itself zerg Java 125 09-09-2008 01:14 AM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Why does screen repaint? Karl ASP .Net 6 08-16-2005 12:36 PM
Why does JApplet not need an instance? Jenny Java 2 09-01-2004 05:22 PM



Advertisments