Calling repaint of an inner class does not trigger paint() actually does nothing
up vote
0
down vote
favorite
I'm not too familiar with JApplet
and paint and repaint(). Any help is appreciated.
I have an outside class "A" that extends JApplet and draws somestuff in its paint()
I also have a private class "B" that sits inside A and also extends JApplet and draws
stuff in its paint().
A's paint() evokes B's paint() so when A is ran both A an B are drawn.
I use a mouselistener to detect when a mouse is clicked and that's when
B should repaint() and draw some new stuff and remove older stuff.
When I press my mouse, however, I see that B's repaint() does nothing.
I print a couple debug messages to the console and I can tell
that when B's repaint() is called nothing happens, i.e., the program should go through
B's paint() again but it doesn't.
Here is the general structure, and again, any help is appreciated
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class A extends JApplet {
private class B extends JApplet implements MouseListener{
public B() { }
public void paint (Graphics g) {
// g.drawline ...
//System.out...
}
public void mousePressed(MouseEvent e) {
//System.out....
repaint();
}
public void mouseReleased(MouseEvent e) {
//System.out....
repaint();
}
// ... rest of mouse listener interface
}
public void init() {
// setSize() ...
}
public void paint(Graphics g) {
// g.drawRectange ...
// Draw other stuff
B b = new B();
B.paint(g)
}
}
java swing repaint japplet
add a comment |
up vote
0
down vote
favorite
I'm not too familiar with JApplet
and paint and repaint(). Any help is appreciated.
I have an outside class "A" that extends JApplet and draws somestuff in its paint()
I also have a private class "B" that sits inside A and also extends JApplet and draws
stuff in its paint().
A's paint() evokes B's paint() so when A is ran both A an B are drawn.
I use a mouselistener to detect when a mouse is clicked and that's when
B should repaint() and draw some new stuff and remove older stuff.
When I press my mouse, however, I see that B's repaint() does nothing.
I print a couple debug messages to the console and I can tell
that when B's repaint() is called nothing happens, i.e., the program should go through
B's paint() again but it doesn't.
Here is the general structure, and again, any help is appreciated
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class A extends JApplet {
private class B extends JApplet implements MouseListener{
public B() { }
public void paint (Graphics g) {
// g.drawline ...
//System.out...
}
public void mousePressed(MouseEvent e) {
//System.out....
repaint();
}
public void mouseReleased(MouseEvent e) {
//System.out....
repaint();
}
// ... rest of mouse listener interface
}
public void init() {
// setSize() ...
}
public void paint(Graphics g) {
// g.drawRectange ...
// Draw other stuff
B b = new B();
B.paint(g)
}
}
java swing repaint japplet
2
Removeprivate class B extends JApplet implements MouseListener{ public B() { }
(but addimplements MouseListener
to the outer applet) & it should work as expected (AFAIU). Which leads to the question.. Why are you trying to do this?
– Andrew Thompson
Nov 18 at 8:00
1
Please edit your question to include a MCVE which can be compiled and tested by others which shows that your debugSystem.out.println()
calls are printed, but the content is not reloaded. Also include the code which shows/loads your applet.
– Progman
Nov 18 at 19:10
1
@Progman "include a MCVE" Great idea, and a tip:[mcve]
in a comment auto-expands to Minimal, Complete, and Verifiable example.
– Andrew Thompson
Nov 19 at 3:12
1
@AndrewThompson Didn't know, thank you ;)
– Progman
Nov 19 at 18:33
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm not too familiar with JApplet
and paint and repaint(). Any help is appreciated.
I have an outside class "A" that extends JApplet and draws somestuff in its paint()
I also have a private class "B" that sits inside A and also extends JApplet and draws
stuff in its paint().
A's paint() evokes B's paint() so when A is ran both A an B are drawn.
I use a mouselistener to detect when a mouse is clicked and that's when
B should repaint() and draw some new stuff and remove older stuff.
When I press my mouse, however, I see that B's repaint() does nothing.
I print a couple debug messages to the console and I can tell
that when B's repaint() is called nothing happens, i.e., the program should go through
B's paint() again but it doesn't.
Here is the general structure, and again, any help is appreciated
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class A extends JApplet {
private class B extends JApplet implements MouseListener{
public B() { }
public void paint (Graphics g) {
// g.drawline ...
//System.out...
}
public void mousePressed(MouseEvent e) {
//System.out....
repaint();
}
public void mouseReleased(MouseEvent e) {
//System.out....
repaint();
}
// ... rest of mouse listener interface
}
public void init() {
// setSize() ...
}
public void paint(Graphics g) {
// g.drawRectange ...
// Draw other stuff
B b = new B();
B.paint(g)
}
}
java swing repaint japplet
I'm not too familiar with JApplet
and paint and repaint(). Any help is appreciated.
I have an outside class "A" that extends JApplet and draws somestuff in its paint()
I also have a private class "B" that sits inside A and also extends JApplet and draws
stuff in its paint().
A's paint() evokes B's paint() so when A is ran both A an B are drawn.
I use a mouselistener to detect when a mouse is clicked and that's when
B should repaint() and draw some new stuff and remove older stuff.
When I press my mouse, however, I see that B's repaint() does nothing.
I print a couple debug messages to the console and I can tell
that when B's repaint() is called nothing happens, i.e., the program should go through
B's paint() again but it doesn't.
Here is the general structure, and again, any help is appreciated
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class A extends JApplet {
private class B extends JApplet implements MouseListener{
public B() { }
public void paint (Graphics g) {
// g.drawline ...
//System.out...
}
public void mousePressed(MouseEvent e) {
//System.out....
repaint();
}
public void mouseReleased(MouseEvent e) {
//System.out....
repaint();
}
// ... rest of mouse listener interface
}
public void init() {
// setSize() ...
}
public void paint(Graphics g) {
// g.drawRectange ...
// Draw other stuff
B b = new B();
B.paint(g)
}
}
java swing repaint japplet
java swing repaint japplet
edited Nov 18 at 9:33
Andrew Thompson
152k27159333
152k27159333
asked Nov 18 at 5:56
sean sontag
31
31
2
Removeprivate class B extends JApplet implements MouseListener{ public B() { }
(but addimplements MouseListener
to the outer applet) & it should work as expected (AFAIU). Which leads to the question.. Why are you trying to do this?
– Andrew Thompson
Nov 18 at 8:00
1
Please edit your question to include a MCVE which can be compiled and tested by others which shows that your debugSystem.out.println()
calls are printed, but the content is not reloaded. Also include the code which shows/loads your applet.
– Progman
Nov 18 at 19:10
1
@Progman "include a MCVE" Great idea, and a tip:[mcve]
in a comment auto-expands to Minimal, Complete, and Verifiable example.
– Andrew Thompson
Nov 19 at 3:12
1
@AndrewThompson Didn't know, thank you ;)
– Progman
Nov 19 at 18:33
add a comment |
2
Removeprivate class B extends JApplet implements MouseListener{ public B() { }
(but addimplements MouseListener
to the outer applet) & it should work as expected (AFAIU). Which leads to the question.. Why are you trying to do this?
– Andrew Thompson
Nov 18 at 8:00
1
Please edit your question to include a MCVE which can be compiled and tested by others which shows that your debugSystem.out.println()
calls are printed, but the content is not reloaded. Also include the code which shows/loads your applet.
– Progman
Nov 18 at 19:10
1
@Progman "include a MCVE" Great idea, and a tip:[mcve]
in a comment auto-expands to Minimal, Complete, and Verifiable example.
– Andrew Thompson
Nov 19 at 3:12
1
@AndrewThompson Didn't know, thank you ;)
– Progman
Nov 19 at 18:33
2
2
Remove
private class B extends JApplet implements MouseListener{ public B() { }
(but add implements MouseListener
to the outer applet) & it should work as expected (AFAIU). Which leads to the question.. Why are you trying to do this?– Andrew Thompson
Nov 18 at 8:00
Remove
private class B extends JApplet implements MouseListener{ public B() { }
(but add implements MouseListener
to the outer applet) & it should work as expected (AFAIU). Which leads to the question.. Why are you trying to do this?– Andrew Thompson
Nov 18 at 8:00
1
1
Please edit your question to include a MCVE which can be compiled and tested by others which shows that your debug
System.out.println()
calls are printed, but the content is not reloaded. Also include the code which shows/loads your applet.– Progman
Nov 18 at 19:10
Please edit your question to include a MCVE which can be compiled and tested by others which shows that your debug
System.out.println()
calls are printed, but the content is not reloaded. Also include the code which shows/loads your applet.– Progman
Nov 18 at 19:10
1
1
@Progman "include a MCVE" Great idea, and a tip:
[mcve]
in a comment auto-expands to Minimal, Complete, and Verifiable example.– Andrew Thompson
Nov 19 at 3:12
@Progman "include a MCVE" Great idea, and a tip:
[mcve]
in a comment auto-expands to Minimal, Complete, and Verifiable example.– Andrew Thompson
Nov 19 at 3:12
1
1
@AndrewThompson Didn't know, thank you ;)
– Progman
Nov 19 at 18:33
@AndrewThompson Didn't know, thank you ;)
– Progman
Nov 19 at 18:33
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
The problem is that nothing is reacting to the repaint()
request in your B
class. It might trigger a repaint of the B
class but that doesn't mean that the A
class gets repainted, nobody told him. Like as you said:
A's paint() evokes B's paint() so when A is ran both A an B are drawn.
That's right, but it doesn't mean it's the same the other way around.
When you want that the A
class should repaint it's content you have to call repaint()
on the A
object, since that's the class you want to be repainted.
Hi thank you very much but that's not what I asked for. I'm saying that B's repaint should trigger B's paint but it doesn't. I'm not trying to repaint A at all.
– sean sontag
Nov 18 at 19:02
@seansontag How do you display the JAppletB
?
– Progman
Nov 18 at 19:05
I guess I should clarify, to display the JApplet, A's paint() is called once but that's it. After that B should be the one to keep repainting itself.
– sean sontag
Nov 18 at 19:15
@seansontag The problem is that you are displaying the appletA
, notB
. Maybe what you are looking for is a normal JPanel added to the layout manager of your JAppletA
. Please edit your question with the MCVE.
– Progman
Nov 18 at 19:18
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
The problem is that nothing is reacting to the repaint()
request in your B
class. It might trigger a repaint of the B
class but that doesn't mean that the A
class gets repainted, nobody told him. Like as you said:
A's paint() evokes B's paint() so when A is ran both A an B are drawn.
That's right, but it doesn't mean it's the same the other way around.
When you want that the A
class should repaint it's content you have to call repaint()
on the A
object, since that's the class you want to be repainted.
Hi thank you very much but that's not what I asked for. I'm saying that B's repaint should trigger B's paint but it doesn't. I'm not trying to repaint A at all.
– sean sontag
Nov 18 at 19:02
@seansontag How do you display the JAppletB
?
– Progman
Nov 18 at 19:05
I guess I should clarify, to display the JApplet, A's paint() is called once but that's it. After that B should be the one to keep repainting itself.
– sean sontag
Nov 18 at 19:15
@seansontag The problem is that you are displaying the appletA
, notB
. Maybe what you are looking for is a normal JPanel added to the layout manager of your JAppletA
. Please edit your question with the MCVE.
– Progman
Nov 18 at 19:18
add a comment |
up vote
1
down vote
The problem is that nothing is reacting to the repaint()
request in your B
class. It might trigger a repaint of the B
class but that doesn't mean that the A
class gets repainted, nobody told him. Like as you said:
A's paint() evokes B's paint() so when A is ran both A an B are drawn.
That's right, but it doesn't mean it's the same the other way around.
When you want that the A
class should repaint it's content you have to call repaint()
on the A
object, since that's the class you want to be repainted.
Hi thank you very much but that's not what I asked for. I'm saying that B's repaint should trigger B's paint but it doesn't. I'm not trying to repaint A at all.
– sean sontag
Nov 18 at 19:02
@seansontag How do you display the JAppletB
?
– Progman
Nov 18 at 19:05
I guess I should clarify, to display the JApplet, A's paint() is called once but that's it. After that B should be the one to keep repainting itself.
– sean sontag
Nov 18 at 19:15
@seansontag The problem is that you are displaying the appletA
, notB
. Maybe what you are looking for is a normal JPanel added to the layout manager of your JAppletA
. Please edit your question with the MCVE.
– Progman
Nov 18 at 19:18
add a comment |
up vote
1
down vote
up vote
1
down vote
The problem is that nothing is reacting to the repaint()
request in your B
class. It might trigger a repaint of the B
class but that doesn't mean that the A
class gets repainted, nobody told him. Like as you said:
A's paint() evokes B's paint() so when A is ran both A an B are drawn.
That's right, but it doesn't mean it's the same the other way around.
When you want that the A
class should repaint it's content you have to call repaint()
on the A
object, since that's the class you want to be repainted.
The problem is that nothing is reacting to the repaint()
request in your B
class. It might trigger a repaint of the B
class but that doesn't mean that the A
class gets repainted, nobody told him. Like as you said:
A's paint() evokes B's paint() so when A is ran both A an B are drawn.
That's right, but it doesn't mean it's the same the other way around.
When you want that the A
class should repaint it's content you have to call repaint()
on the A
object, since that's the class you want to be repainted.
answered Nov 18 at 9:45
Progman
6,17231935
6,17231935
Hi thank you very much but that's not what I asked for. I'm saying that B's repaint should trigger B's paint but it doesn't. I'm not trying to repaint A at all.
– sean sontag
Nov 18 at 19:02
@seansontag How do you display the JAppletB
?
– Progman
Nov 18 at 19:05
I guess I should clarify, to display the JApplet, A's paint() is called once but that's it. After that B should be the one to keep repainting itself.
– sean sontag
Nov 18 at 19:15
@seansontag The problem is that you are displaying the appletA
, notB
. Maybe what you are looking for is a normal JPanel added to the layout manager of your JAppletA
. Please edit your question with the MCVE.
– Progman
Nov 18 at 19:18
add a comment |
Hi thank you very much but that's not what I asked for. I'm saying that B's repaint should trigger B's paint but it doesn't. I'm not trying to repaint A at all.
– sean sontag
Nov 18 at 19:02
@seansontag How do you display the JAppletB
?
– Progman
Nov 18 at 19:05
I guess I should clarify, to display the JApplet, A's paint() is called once but that's it. After that B should be the one to keep repainting itself.
– sean sontag
Nov 18 at 19:15
@seansontag The problem is that you are displaying the appletA
, notB
. Maybe what you are looking for is a normal JPanel added to the layout manager of your JAppletA
. Please edit your question with the MCVE.
– Progman
Nov 18 at 19:18
Hi thank you very much but that's not what I asked for. I'm saying that B's repaint should trigger B's paint but it doesn't. I'm not trying to repaint A at all.
– sean sontag
Nov 18 at 19:02
Hi thank you very much but that's not what I asked for. I'm saying that B's repaint should trigger B's paint but it doesn't. I'm not trying to repaint A at all.
– sean sontag
Nov 18 at 19:02
@seansontag How do you display the JApplet
B
?– Progman
Nov 18 at 19:05
@seansontag How do you display the JApplet
B
?– Progman
Nov 18 at 19:05
I guess I should clarify, to display the JApplet, A's paint() is called once but that's it. After that B should be the one to keep repainting itself.
– sean sontag
Nov 18 at 19:15
I guess I should clarify, to display the JApplet, A's paint() is called once but that's it. After that B should be the one to keep repainting itself.
– sean sontag
Nov 18 at 19:15
@seansontag The problem is that you are displaying the applet
A
, not B
. Maybe what you are looking for is a normal JPanel added to the layout manager of your JApplet A
. Please edit your question with the MCVE.– Progman
Nov 18 at 19:18
@seansontag The problem is that you are displaying the applet
A
, not B
. Maybe what you are looking for is a normal JPanel added to the layout manager of your JApplet A
. Please edit your question with the MCVE.– Progman
Nov 18 at 19:18
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53358299%2fcalling-repaint-of-an-inner-class-does-not-trigger-paint-actually-does-nothing%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Remove
private class B extends JApplet implements MouseListener{ public B() { }
(but addimplements MouseListener
to the outer applet) & it should work as expected (AFAIU). Which leads to the question.. Why are you trying to do this?– Andrew Thompson
Nov 18 at 8:00
1
Please edit your question to include a MCVE which can be compiled and tested by others which shows that your debug
System.out.println()
calls are printed, but the content is not reloaded. Also include the code which shows/loads your applet.– Progman
Nov 18 at 19:10
1
@Progman "include a MCVE" Great idea, and a tip:
[mcve]
in a comment auto-expands to Minimal, Complete, and Verifiable example.– Andrew Thompson
Nov 19 at 3:12
1
@AndrewThompson Didn't know, thank you ;)
– Progman
Nov 19 at 18:33