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)
}
}









share|improve this question




















  • 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








  • 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















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)
}
}









share|improve this question




















  • 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








  • 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













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)
}
}









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 at 9:33









Andrew Thompson

152k27159333




152k27159333










asked Nov 18 at 5:56









sean sontag

31




31








  • 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








  • 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














  • 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








  • 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








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












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.






share|improve this answer





















  • 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










  • 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











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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

























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.






share|improve this answer





















  • 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










  • 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















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.






share|improve this answer





















  • 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










  • 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













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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










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 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










  • @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


















  • 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










  • 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
















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


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin