Skip to main content

[JAVA2D] Regarding graphics

3 replies [Last post]
Anonymous

Hi all,
I am working on a problem in which I display images on the screen
(a JPanel). I can display them move them etc. But when I minimize the
screen or bring some other window on top of this Panel. The images
disappear on my returning back to it. Can anyone give me a good hint?

Thanx
Adil Raja

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Dmitri Trembovetski

Hi Adil,

I think you have a repainting issue caused by incorrect painting
code. Could you post your paintComponent() method?

Thanks,
Dmitri

On Mon, Jul 04, 2005 at 03:04:18PM +0100, Adil Raja wrote:
> Hi all,
> I am working on a problem in which I display images on the screen
> (a JPanel). I can display them move them etc. But when I minimize the
> screen or bring some other window on top of this Panel. The images
> disappear on my returning back to it. Can anyone give me a good hint?
>
> Thanx
> Adil Raja
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Adil Raja

Thanx for the concern.
Let me elaborate to you the scenario first and then I shall give you
the pseudo code.

Well the scenario is that: - I have a Frame class which extends from
the JFrame class. In this class I make an object of type JPanel and
add it to the JFrame as below.
JPanel myPanel=new JPanel();
this.add(myPanel).
Now myPanel has two events namely, mouseDragged event and mousePressed event.
The panels job is to display a number of images which make a network
topology by having edges between them. This topology is drawn using a
myPaint method (not the paint(Graphics g) method. The reason why I am
not using a paint(g) method is that I have to override it within the
Frame class and as a result it paints the whole myFrame (rather than
painting the myPanel). So I chose this (somewhat naive alternative).
The myPaint method has the following pseudocode: -
public void myPaint()//no arguments
{
Graphics g=myPanel.getGraphics();
myPanel.paint(g);
Use g to draw appropraite lines between nodes (btw their coordinates)
Use g to draw the image on their coordinates();
}
the event handlers
mousePressed(evt)
{
compare evt.getX and evt.Gety with the coordinates of nodes. if
they match remember the coordinates and keep them in two other
variables.
}
mouseDragged(evt)
{
keep updating the coordinates of the node as the mouse moves.
}
So the actual problem I c is with myPaint().
I shall send you the actual code of these methods in a short while as well.
As I am far from my system I am sending you the pseudocode right now.

Thanx alot
I shall really appreciate a clean solution.

On 7/8/05, Dmitri Trembovetski wrote:
>
> Hi Adil,
>
> I think you have a repainting issue caused by incorrect painting
> code. Could you post your paintComponent() method?
>
> Thanks,
> Dmitri
>
>
> On Mon, Jul 04, 2005 at 03:04:18PM +0100, Adil Raja wrote:
> > Hi all,
> > I am working on a problem in which I display images on the screen
> > (a JPanel). I can display them move them etc. But when I minimize the
> > screen or bring some other window on top of this Panel. The images
> > disappear on my returning back to it. Can anyone give me a good hint?
> >
> > Thanx
> > Adil Raja
> >
> > ===========================================================================
> > To unsubscribe, send email to listserv@java.sun.com and include in the body
> > of the message "signoff JAVA2D-INTEREST". For general help, send email to
> > listserv@java.sun.com and include in the body of the message "help".
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Dmitri Trembovetski

Hi Adil,

First of all, for Swing components (JComponent children) you should
override not paint(), but paintComponent(). The reason is that Swing
is double-buffered, and the graphics context which is passed to
paintComponent is that of a back-buffer, while in your case you're
trying to render directly to the screen, interfering with the
Swing repainting mechanism.

BTW, this is the reason you see the flickering you complained about
in a separate email.

Note that this is more of a swing than Java2D-related question, so
I'd suggest to ask further questions on the swing feedback forum:
http://www.javadesktop.org/forums/forum.jspa?forumID=2

Thanks,
Dmitri

On Sat, Jul 09, 2005 at 03:35:51PM +0100, Adil Raja wrote:
> Thanx for the concern.
> Let me elaborate to you the scenario first and then I shall give you
> the pseudo code.
>
> Well the scenario is that: - I have a Frame class which extends from
> the JFrame class. In this class I make an object of type JPanel and
> add it to the JFrame as below.
> JPanel myPanel=new JPanel();
> this.add(myPanel).
> Now myPanel has two events namely, mouseDragged event and mousePressed event.
> The panels job is to display a number of images which make a network
> topology by having edges between them. This topology is drawn using a
> myPaint method (not the paint(Graphics g) method. The reason why I am
> not using a paint(g) method is that I have to override it within the
> Frame class and as a result it paints the whole myFrame (rather than
> painting the myPanel). So I chose this (somewhat naive alternative).
> The myPaint method has the following pseudocode: -
> public void myPaint()//no arguments
> {
> Graphics g=myPanel.getGraphics();
> myPanel.paint(g);
> Use g to draw appropraite lines between nodes (btw their coordinates)
> Use g to draw the image on their coordinates();
> }
> the event handlers
> mousePressed(evt)
> {
> compare evt.getX and evt.Gety with the coordinates of nodes. if
> they match remember the coordinates and keep them in two other
> variables.
> }
> mouseDragged(evt)
> {
> keep updating the coordinates of the node as the mouse moves.
> }
> So the actual problem I c is with myPaint().
> I shall send you the actual code of these methods in a short while as well.
> As I am far from my system I am sending you the pseudocode right now.
>
> Thanx alot
> I shall really appreciate a clean solution.
>
>
> On 7/8/05, Dmitri Trembovetski wrote:
> >
> > Hi Adil,
> >
> > I think you have a repainting issue caused by incorrect painting
> > code. Could you post your paintComponent() method?
> >
> > Thanks,
> > Dmitri
> >
> >
> > On Mon, Jul 04, 2005 at 03:04:18PM +0100, Adil Raja wrote:
> > > Hi all,
> > > I am working on a problem in which I display images on the screen
> > > (a JPanel). I can display them move them etc. But when I minimize the
> > > screen or bring some other window on top of this Panel. The images
> > > disappear on my returning back to it. Can anyone give me a good hint?
> > >
> > > Thanx
> > > Adil Raja
> > >
> > > ===========================================================================
> > > To unsubscribe, send email to listserv@java.sun.com and include in the body
> > > of the message "signoff JAVA2D-INTEREST". For general help, send email to
> > > listserv@java.sun.com and include in the body of the message "help".
> >
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".