-
GUI Refresh problem?
OK, I have a JPanel that is tied to MouseListener. I have a menubar also.
Therefore I can draw things on it with drawRect(), drawLine(), etc.
However, if I select the menubar, which drops down the menus or alternating
between two applications, the drawn items will be erased from the JPanel.
It's something like the application cannot keep the currently drawn items
intact and cannot refresh it.
Please help.
--
Best Regards,
Wing Hoe
---------------------------------------------------------------
ICQ: 2213281
Email: winghoe@hotmail.com
www: http://pwp.maxis.net.my/winghoe
Job Seeking Status : Active
Availability : May 2001 (after degree course finish)
---------------------------------------------------------------
-
Re: GUI Refresh problem?
"Lim Wing Hoe" <winghoe@hotmail.com> wrote:
>OK, I have a JPanel that is tied to MouseListener. I have a menubar also.
>Therefore I can draw things on it with drawRect(), drawLine(), etc.
>
>However, if I select the menubar, which drops down the menus or alternating
>between two applications, the drawn items will be erased from the JPanel.
>
>It's something like the application cannot keep the currently drawn items
>intact and cannot refresh it.
>
>Please help.
>
>
>--
>
>
>
>Best Regards,
>Wing Hoe
>---------------------------------------------------------------
>ICQ: 2213281
>Email: winghoe@hotmail.com
>www: http://pwp.maxis.net.my/winghoe
>Job Seeking Status : Active
>Availability : May 2001 (after degree course finish)
>---------------------------------------------------------------
>
>
>
>
You should keep the drawn items with Vector or other Class in java.util.*
package.
-
Re: GUI Refresh problem?
I did that also.
I tried using the paint() method. The good thing is, it works. The bad thing
is, the entire JInternalFrame shows nothing, although when I draw a line it
is captured and displayed. The rest of the GUI components somehow got
'erased'.
Also, what do paint(), repaint(), update() methods do? I read thru the API
documentation, but I couldn't understand it.
--
Best Regards,
Wing Hoe
---------------------------------------------------------------
ICQ: 2213281
Email: winghoe@hotmail.com
www: http://pwp.maxis.net.my/winghoe
Job Seeking Status : Active
Availability : May 2001 (after degree course finish)
---------------------------------------------------------------
"zfq" <zfqjcl@371.net> wrote in message news:3a116bd3$1@news.devx.com...
>
> You should keep the drawn items with Vector or other Class in java.util.*
> package.
>
-
Re: GUI Refresh problem?
OK, this is what I've done. I pulled out the necessary methods and put them
in a class that extends JPanel.
Everything works OK, except that setBackground(Color.white) doesn't seem to
work. I'm out of my wits trying to figure out how to get this extended
JPanel class to have it's background set to white.
Also, how do I clear the panel after I have lots of stuff drawn there?
--
Best Regards,
Wing Hoe
---------------------------------------------------------------
ICQ: 2213281
Email: winghoe@hotmail.com
www: http://pwp.maxis.net.my/winghoe
Job Seeking Status : Active
Availability : May 2001 (after degree course finish)
---------------------------------------------------------------
"zfq" <zfqjcl@371.net> wrote in message news:3a116bd3$1@news.devx.com...
>
> "Lim Wing Hoe" <winghoe@hotmail.com> wrote:
> >OK, I have a JPanel that is tied to MouseListener. I have a menubar also.
> >Therefore I can draw things on it with drawRect(), drawLine(), etc.
> >
> >However, if I select the menubar, which drops down the menus or
alternating
> >between two applications, the drawn items will be erased from the JPanel.
> >
> >It's something like the application cannot keep the currently drawn items
> >intact and cannot refresh it.
> >
> >Please help.
> >
> >
> >--
> >
> >
> >
> >Best Regards,
> >Wing Hoe
> >---------------------------------------------------------------
> >ICQ: 2213281
> >Email: winghoe@hotmail.com
> >www: http://pwp.maxis.net.my/winghoe
> >Job Seeking Status : Active
> >Availability : May 2001 (after degree course finish)
> >---------------------------------------------------------------
> >
> >
> >
> >
> You should keep the drawn items with Vector or other Class in java.util.*
> package.
>
-
Re: GUI Refresh problem?
it wouldnt' hurt posting your code here..
"Lim Wing Hoe" <winghoe@hotmail.com> wrote:
>OK, this is what I've done. I pulled out the necessary methods and put them
>in a class that extends JPanel.
>Everything works OK, except that setBackground(Color.white) doesn't seem
to
>work. I'm out of my wits trying to figure out how to get this extended
>JPanel class to have it's background set to white.
>
>Also, how do I clear the panel after I have lots of stuff drawn there?
>
>--
>
>
>
>Best Regards,
>Wing Hoe
>---------------------------------------------------------------
>ICQ: 2213281
>Email: winghoe@hotmail.com
>www: http://pwp.maxis.net.my/winghoe
>Job Seeking Status : Active
>Availability : May 2001 (after degree course finish)
>---------------------------------------------------------------
>
>
>"zfq" <zfqjcl@371.net> wrote in message news:3a116bd3$1@news.devx.com...
>>
>> "Lim Wing Hoe" <winghoe@hotmail.com> wrote:
>> >OK, I have a JPanel that is tied to MouseListener. I have a menubar also.
>> >Therefore I can draw things on it with drawRect(), drawLine(), etc.
>> >
>> >However, if I select the menubar, which drops down the menus or
>alternating
>> >between two applications, the drawn items will be erased from the JPanel.
>> >
>> >It's something like the application cannot keep the currently drawn items
>> >intact and cannot refresh it.
>> >
>> >Please help.
>> >
>> >
>> >--
>> >
>> >
>> >
>> >Best Regards,
>> >Wing Hoe
>> >---------------------------------------------------------------
>> >ICQ: 2213281
>> >Email: winghoe@hotmail.com
>> >www: http://pwp.maxis.net.my/winghoe
>> >Job Seeking Status : Active
>> >Availability : May 2001 (after degree course finish)
>> >---------------------------------------------------------------
>> >
>> >
>> >
>> >
>> You should keep the drawn items with Vector or other Class in java.util.*
>> package.
>>
>
>
-
Re: GUI Refresh problem?
OK here's the code. Like I mentioned before, the setBackground(Color.white) doesn't seem to work.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
class DrawingPanel extends JPanel
{//begin class DrawingPanel
private PublicWhiteBoard publicWhiteBoard;
private Vector drawnObjects;
private int x1;
private int y1;
private int x2;
private int y2;
private int width;
private int height;
public DrawingPanel(PublicWhiteBoard publicWhiteBoard)
{//begin DrawingPanel()
super(new BorderLayout());
this.publicWhiteBoard = publicWhiteBoard;
this.setOpaque(true);
this.setBackground(Color.white);
this.setForeground(Color.black);
this.setEnabled(true);
this.setVisible(true);
drawnObjects = new Vector();
listenToMouseEvents();
}//end DrawingPanel()
public void listenToMouseEvents()
{//begin listenToMouseEvents()
addMouseListener(
new MouseAdapter()
{//begin MouseAdapter()
public void mousePressed(MouseEvent e)
{//begin mousePressed()
x1 = e.getX();
y1 = e.getY();
}//end mousePressed()
public void mouseReleased(MouseEvent e)
{//begin mouseReleased()
x2 = e.getX();
y2 = e.getY();
sendToTransmitMessage();
}//end mouseReleased()
public void mouseEntered(MouseEvent e)
{//begin mouseEntered()
setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
}//end mouseEntered()
public void mouseExited(MouseEvent e)
{//begin mouseExited()
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}//end mouseExited()
}//end MouseAdapter()
);//complete addMouseListener()
addMouseMotionListener(
new MouseMotionAdapter()
{//begin MouseMotionAdapter()
public void mouseDragged(MouseEvent e)
{//begin mouseDragged()
if(publicWhiteBoard.strTool.equals("FreeHand"))
{//begin if
x1 = e.getX();
y1 = e.getY();
x2 = e.getX();
y2 = e.getY();
sendToTransmitMessage();
}//end if
}//end mouseDragged()
}//end MouseMotionAdapter()
);//complete addMouseMotionListener()
}//end listenToMouseEvents()
public void sendToTransmitMessage()
{//begin sendToTransmitMessage()
calculateWidthHeight();
publicWhiteBoard.transmitMessage(this.x1, this.y1,
this.width, this.height);
}//end sentToTransmitMessage()
public void clearScreen()
{//begin clearScreen()
drawnObjects.clear();
this.repaint();
}//end clearScreen()
public void paint(Graphics g)
{//begin paint()
for (int count = 0; count < drawnObjects.size(); count++)
{//begin for loop
if (drawnObjects.elementAt(count) instanceof WBLine)
{//begin if
WBLine wbLine = (WBLine) drawnObjects.elementAt(count);
g.setColor(wbLine.strColor);
g.drawLine(wbLine.x1, wbLine.y1, wbLine.x2, wbLine.y2);
}//end if
else if (drawnObjects.elementAt(count) instanceof WBFreeHand)
{//begin else if
WBFreeHand wbFreeHand =
(WBFreeHand) drawnObjects.elementAt(count);
g.setColor(wbFreeHand.strColor);
g.fillRect(wbFreeHand.x1,wbFreeHand.y1,2,2);
}//end else if
else if (drawnObjects.elementAt(count) instanceof WBOval)
{//begin else if
WBOval wbOval = (WBOval) drawnObjects.elementAt(count);
g.setColor(wbOval.strColor);
if (wbOval.isFilled.equals("Filled"))
{//begin if
g.fillOval(wbOval.x1, wbOval.y1, wbOval.x2, wbOval.y2);
}//end if
else
{//begin else
g.drawOval(wbOval.x1, wbOval.y1, wbOval.x2, wbOval.y2);
}//end else
}//end else if
else if (drawnObjects.elementAt(count) instanceof WBRectangle)
{//begin else if
WBRectangle wbRectangle =
(WBRectangle) drawnObjects.elementAt(count);
g.setColor(wbRectangle.strColor);
if (wbRectangle.isFilled.equals("Filled"))
{//begin if
g.fillRect(wbRectangle.x1, wbRectangle.y1,
wbRectangle.x2, wbRectangle.y2);
}//end if
else
{//begin else
g.drawRect(wbRectangle.x1, wbRectangle.y1,
wbRectangle.x2, wbRectangle.y2);
}//end else
}//end else if
}//end for loop
g.dispose();
}//end paint()
public void calculateWidthHeight()
{//begin calculateWidthHeight()
if(publicWhiteBoard.strTool.equals("Line"))
{//begin if
width = x2;
height = y2;
}//end if
else if (publicWhiteBoard.strTool.equals("FreeHand"))
{//begin else if
width = x2;
height = y2;
}//end else if
else
{//begin else
//get the width between two coordinates
if (x1<=x2)
{//begin if
width = x2 - x1;
}//end if
else
{//begin else
width = x1 - x2;
}//end else
//get the height between two coordinates
if (y1 <= y2)
{//begin if
height = y2 - y1;
}//end if
else
{//begin else
height = y1 - y2;
}//end else
//get the x1 and y1 when the user draws the object
//backwards. this is a must because the methods
//drawLine(), drawRect() and so on, draws the object
//from the last coordinate to the width and height.
//it will draw forward and down from the first coordinates.
if ((x1 <= x2) && (y2 >= y1))
{//begin if
x1 = x1;
y1 = y1;
}//end if
else if ((x1 <= x2) && (y2 <= y1))
{//begin else if
x1 = x1;
y1 = y2;
}//end else if
else if ((x1 >= x2) && (y2 >= y1))
{//begin else if
x1 = x2;
y1 = y1;
}//end else if
else if ((x1 >= x2) && (y2 <= y1))
{//begin else if
x1 = x2;
y1 = y2;
}//end else if
}//end else
}//end calculateWidthHeight()
public void updateCanvas(String strTool, String strColor,
String isFilled, int x1, int y1,
int x2, int y2, String userName)
{//begin updateCanvas()
Graphics g = this.getGraphics();
g.setColor(this.determineColor(strColor));
if(strTool.equals("Line"))
{//begin if
//add to the drawnObjects Vector so that when the paint()
//method is called, the objects can be redrawn.
drawnObjects.addElement(
new WBLine(g.getColor(), x1, y1, x2, y2));
g.drawLine(x1, y1, x2, y2);
publicWhiteBoard.lblStatusBarEvent.setText(userName +
" drew a line...");
}//end if
else if(strTool.equals("FreeHand"))
{//begin else if
//add to the drawnObjects Vector so that when the paint()
//method is called, the objects can be redrawn.
drawnObjects.addElement(
new WBFreeHand(g.getColor(), x1, y1));
g.fillRect(x1,y1,2,2);
publicWhiteBoard.lblStatusBarEvent.setText(userName +
" drew a FreeHand line...");
}//end else if
else if(strTool.equals("Rectangle"))
{//begin if
//add to the drawnObjects Vector so that when the paint()
//method is called, the objects can be redrawn.
drawnObjects.addElement(
new WBRectangle(g.getColor(), isFilled, x1, y1, x2, y2));
if(isFilled.equals("Filled"))
{//begin if
g.fillRect(x1, y1, x2, y2);
publicWhiteBoard.lblStatusBarEvent.setText(userName +
" drew a filled rectangle...");
}//end if
else
{//begin else
g.drawRect(x1, y1, x2, y2);
publicWhiteBoard.lblStatusBarEvent.setText(userName +
" drew a hollow rectangle...");
}//end else
}//end if
else if(strTool.equals("Oval"))
{//begin if
//add to the drawnObjects Vector so that when the paint()
//method is called, the objects can be redrawn.
drawnObjects.addElement(
new WBOval(g.getColor(), isFilled, x1, y1, x2, y2));
if(isFilled.equals("Filled"))
{//begin if
g.fillOval(x1, y1, x2, y2);
publicWhiteBoard.lblStatusBarEvent.setText(userName +
" drew a filled Oval...");
}//end if
else
{//begin else
g.drawOval(x1, y1, x2, y2);
publicWhiteBoard.lblStatusBarEvent.setText(userName +
" drew a hollow Oval...");
}//end else
}//end if
else
{//begin else
publicWhiteBoard.lblStatusBarEvent.setText(
"Unknown tool used...");
}//end else
g.dispose();
}//end updateCanvas()
public Color determineColor(String strWhatColor)
{//begin determineColor()
if (strWhatColor.equals("Black"))
{//begin if
return Color.black;
}//end if
else if (strWhatColor.equals("DarkGray"))
{//begin if
return Color.darkGray;
}//end if
else if (strWhatColor.equals("LightGray"))
{//begin if
return Color.lightGray;
}//end if
else if (strWhatColor.equals("Gray"))
{//begin if
return Color.gray;
}//end if
else if (strWhatColor.equals("Blue"))
{//begin if
return Color.blue;
}//end if
else if (strWhatColor.equals("Green"))
{//begin if
return Color.green;
}//end if
else if (strWhatColor.equals("Cyan"))
{//begin if
return Color.cyan;
}//end if
else if (strWhatColor.equals("Magenta"))
{//begin if
return Color.magenta;
}//end if
else if (strWhatColor.equals("Pink"))
{//begin if
return Color.pink;
}//end if
else if (strWhatColor.equals("Red"))
{//begin if
return Color.red;
}//end if
else if (strWhatColor.equals("Orange"))
{//begin if
return Color.orange;
}//end if
else if (strWhatColor.equals("Yellow"))
{//begin if
return Color.yellow;
}//end if
else if (strWhatColor.equals("White"))
{//begin if
return Color.white;
}//end if
else
{//begin else
return Color.black;
}//end else
}//end determineColor()
}//end class DrawingPanel
--
Best Regards,
Wing Hoe
---------------------------------------------------------------
ICQ: 2213281
Email: winghoe@hotmail.com
www: http://pwp.maxis.net.my/winghoe
Job Seeking Status : Active
Availability : May 2001 (after degree course finish)
---------------------------------------------------------------
"alberto" <albert77@rocketmail.com> wrote in message news:3a11f47f$1@news.devx.com...
>
> it wouldnt' hurt posting your code here..
> "Lim Wing Hoe" <winghoe@hotmail.com> wrote:
> >OK, this is what I've done. I pulled out the necessary methods and put them
> >in a class that extends JPanel.
> >Everything works OK, except that setBackground(Color.white) doesn't seem
> to
> >work. I'm out of my wits trying to figure out how to get this extended
> >JPanel class to have it's background set to white.
> >
> >Also, how do I clear the panel after I have lots of stuff drawn there?
> >
> >--
> >
> >
> >
> >Best Regards,
> >Wing Hoe
> >---------------------------------------------------------------
> >ICQ: 2213281
> >Email: winghoe@hotmail.com
> >www: http://pwp.maxis.net.my/winghoe
> >Job Seeking Status : Active
> >Availability : May 2001 (after degree course finish)
> >---------------------------------------------------------------
> >
> >
> >"zfq" <zfqjcl@371.net> wrote in message news:3a116bd3$1@news.devx.com...
> >>
> >> "Lim Wing Hoe" <winghoe@hotmail.com> wrote:
> >> >OK, I have a JPanel that is tied to MouseListener. I have a menubar also.
> >> >Therefore I can draw things on it with drawRect(), drawLine(), etc.
> >> >
> >> >However, if I select the menubar, which drops down the menus or
> >alternating
> >> >between two applications, the drawn items will be erased from the JPanel.
> >> >
> >> >It's something like the application cannot keep the currently drawn items
> >> >intact and cannot refresh it.
> >> >
> >> >Please help.
> >> >
> >> >
> >> >--
> >> >
> >> >
> >> >
> >> >Best Regards,
> >> >Wing Hoe
> >> >---------------------------------------------------------------
> >> >ICQ: 2213281
> >> >Email: winghoe@hotmail.com
> >> >www: http://pwp.maxis.net.my/winghoe
> >> >Job Seeking Status : Active
> >> >Availability : May 2001 (after degree course finish)
> >> >---------------------------------------------------------------
> >> >
> >> >
> >> >
> >> >
> >> You should keep the drawn items with Vector or other Class in java.util.*
> >> package.
> >>
> >
> >
>
-
Re: GUI Refresh problem?
"Lim Wing Hoe" <winghoe@hotmail.com> wrote:
>This is a multi-part message in MIME format.
>
>------=_NextPart_000_0029_01C04F14.D484FF40
>Content-Type: text/plain;
> charset="Windows-1252"
>Content-Transfer-Encoding: quoted-printable
>
>OK here's the code. Like I mentioned before, the =
>setBackground(Color.white) doesn't seem to work.
>
>import java.awt.*;
>import java.awt.event.*;
>import javax.swing.*;
>import javax.swing.event.*;
>import java.util.*;
>
>class DrawingPanel extends JPanel
>{//begin class DrawingPanel
>
> private PublicWhiteBoard publicWhiteBoard;
> private Vector drawnObjects;
> private int x1;
> private int y1;
> private int x2;
> private int y2;
> private int width;
> private int height;
>
> public DrawingPanel(PublicWhiteBoard publicWhiteBoard)
> {//begin DrawingPanel()
> super(new BorderLayout());
> this.publicWhiteBoard =3D publicWhiteBoard;
> this.setOpaque(true);
> this.setBackground(Color.white);
> this.setForeground(Color.black);
> this.setEnabled(true);
> this.setVisible(true); =20
> drawnObjects =3D new Vector();
> listenToMouseEvents();
> }//end DrawingPanel()
>
> public void listenToMouseEvents()
> {//begin listenToMouseEvents()
> addMouseListener(
> new MouseAdapter()
> {//begin MouseAdapter()
> public void mousePressed(MouseEvent e)
> {//begin mousePressed()
> x1 =3D e.getX();
> y1 =3D e.getY();=20
> }//end mousePressed()
> =20
> public void mouseReleased(MouseEvent e)
> {//begin mouseReleased()
> x2 =3D e.getX();
> y2 =3D e.getY();=20
> sendToTransmitMessage();
> }//end mouseReleased()
> =20
> public void mouseEntered(MouseEvent e)
> {//begin mouseEntered()
> setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
> }//end mouseEntered()
> =20
> public void mouseExited(MouseEvent e)
> {//begin mouseExited()
> setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
> }//end mouseExited()
> }//end MouseAdapter()
> );//complete addMouseListener()
>
> addMouseMotionListener(
> new MouseMotionAdapter()
> {//begin MouseMotionAdapter()
> public void mouseDragged(MouseEvent e)
> {//begin mouseDragged()
> if(publicWhiteBoard.strTool.equals("FreeHand"))
> {//begin if
> x1 =3D e.getX();
> y1 =3D e.getY();
> x2 =3D e.getX();
> y2 =3D e.getY();=20
> sendToTransmitMessage();
> }//end if
> }//end mouseDragged()
> }//end MouseMotionAdapter()
> );//complete addMouseMotionListener()
> }//end listenToMouseEvents()
>
>
> public void sendToTransmitMessage()
> {//begin sendToTransmitMessage()
> calculateWidthHeight();
> publicWhiteBoard.transmitMessage(this.x1, this.y1,=20
> this.width, this.height);
> }//end sentToTransmitMessage()
>
> public void clearScreen()
> {//begin clearScreen()
> drawnObjects.clear();
> this.repaint();=20
> }//end clearScreen()
>
> public void paint(Graphics g)
> {//begin paint()
> for (int count =3D 0; count < drawnObjects.size(); count++)
> {//begin for loop
>
> if (drawnObjects.elementAt(count) instanceof WBLine)
> {//begin if
> WBLine wbLine =3D (WBLine) drawnObjects.elementAt(count);
> g.setColor(wbLine.strColor);
> g.drawLine(wbLine.x1, wbLine.y1, wbLine.x2, wbLine.y2);
> }//end if
> else if (drawnObjects.elementAt(count) instanceof WBFreeHand)
> {//begin else if
> WBFreeHand wbFreeHand =3D=20
> (WBFreeHand) drawnObjects.elementAt(count);
> g.setColor(wbFreeHand.strColor);
> g.fillRect(wbFreeHand.x1,wbFreeHand.y1,2,2);
> }//end else if
> else if (drawnObjects.elementAt(count) instanceof WBOval)
> {//begin else if
> WBOval wbOval =3D (WBOval) drawnObjects.elementAt(count);
> g.setColor(wbOval.strColor);
> if (wbOval.isFilled.equals("Filled"))
> {//begin if
> g.fillOval(wbOval.x1, wbOval.y1, wbOval.x2, wbOval.y2);
> }//end if
> else
> {//begin else
> g.drawOval(wbOval.x1, wbOval.y1, wbOval.x2, wbOval.y2);
> }//end else=20
> }//end else if
> else if (drawnObjects.elementAt(count) instanceof WBRectangle)
> {//begin else if
> WBRectangle wbRectangle =3D=20
> (WBRectangle) drawnObjects.elementAt(count);
> g.setColor(wbRectangle.strColor);
> if (wbRectangle.isFilled.equals("Filled"))
> {//begin if
> g.fillRect(wbRectangle.x1, wbRectangle.y1,=20
> wbRectangle.x2, wbRectangle.y2);
> }//end if
> else
> {//begin else
> g.drawRect(wbRectangle.x1, wbRectangle.y1,=20
> wbRectangle.x2, wbRectangle.y2);
> }//end else=20
> }//end else if
> }//end for loop
> g.dispose();
> }//end paint()
>
>
> public void calculateWidthHeight()
> {//begin calculateWidthHeight()
> if(publicWhiteBoard.strTool.equals("Line"))
> {//begin if
> width =3D x2;
> height =3D y2;
> }//end if
> else if (publicWhiteBoard.strTool.equals("FreeHand"))
> {//begin else if
> width =3D x2;
> height =3D y2;
> }//end else if
> else
> {//begin else
> //get the width between two coordinates
> if (x1<=3Dx2)
> {//begin if
> width =3D x2 - x1;
> }//end if
> else
> {//begin else
> width =3D x1 - x2;
> }//end else=20
> =20
> //get the height between two coordinates
> if (y1 <=3D y2)
> {//begin if
> height =3D y2 - y1;
> }//end if
> else
> {//begin else
> height =3D y1 - y2;
> }//end else=20
>
> //get the x1 and y1 when the user draws the object
> //backwards. this is a must because the methods
> //drawLine(), drawRect() and so on, draws the object
> //from the last coordinate to the width and height.
> //it will draw forward and down from the first coordinates.=20
> if ((x1 <=3D x2) && (y2 >=3D y1))
> {//begin if
> x1 =3D x1;=20
> y1 =3D y1;
> }//end if
> else if ((x1 <=3D x2) && (y2 <=3D y1))
> {//begin else if
> x1 =3D x1;
> y1 =3D y2;
> }//end else if
> else if ((x1 >=3D x2) && (y2 >=3D y1))
> {//begin else if
> x1 =3D x2;
> y1 =3D y1;
> }//end else if
> else if ((x1 >=3D x2) && (y2 <=3D y1))
> {//begin else if
> x1 =3D x2;
> y1 =3D y2;
> }//end else if
> }//end else
> }//end calculateWidthHeight()
>
> public void updateCanvas(String strTool, String strColor,=20
> String isFilled, int x1, int y1,=20
> int x2, int y2, String userName)
> {//begin updateCanvas()
>=20
> Graphics g =3D this.getGraphics();
> g.setColor(this.determineColor(strColor));
>=20
> if(strTool.equals("Line"))
> {//begin if
> //add to the drawnObjects Vector so that when the paint()
> //method is called, the objects can be redrawn.
> drawnObjects.addElement(
> new WBLine(g.getColor(), x1, y1, x2, y2));
> g.drawLine(x1, y1, x2, y2);
> publicWhiteBoard.lblStatusBarEvent.setText(userName +=20
> " drew a line...");
> }//end if
> else if(strTool.equals("FreeHand"))
> {//begin else if
> //add to the drawnObjects Vector so that when the paint()
> //method is called, the objects can be redrawn.
> drawnObjects.addElement(
> new WBFreeHand(g.getColor(), x1, y1));
> g.fillRect(x1,y1,2,2);
> publicWhiteBoard.lblStatusBarEvent.setText(userName +=20
> " drew a FreeHand line...");
> }//end else if
> else if(strTool.equals("Rectangle"))
> {//begin if
> //add to the drawnObjects Vector so that when the paint()
> //method is called, the objects can be redrawn.
> drawnObjects.addElement(
> new WBRectangle(g.getColor(), isFilled, x1, y1, x2, y2));
>
> if(isFilled.equals("Filled"))
> {//begin if
> g.fillRect(x1, y1, x2, y2);
> publicWhiteBoard.lblStatusBarEvent.setText(userName +=20
> " drew a filled rectangle...");
> }//end if
> else
> {//begin else
> g.drawRect(x1, y1, x2, y2);
> publicWhiteBoard.lblStatusBarEvent.setText(userName +=20
> " drew a hollow rectangle...");
> }//end else =20
> }//end if
> else if(strTool.equals("Oval"))
> {//begin if
> //add to the drawnObjects Vector so that when the paint()
> //method is called, the objects can be redrawn.
> drawnObjects.addElement(
> new WBOval(g.getColor(), isFilled, x1, y1, x2, y2));
>
> if(isFilled.equals("Filled"))
> {//begin if
> g.fillOval(x1, y1, x2, y2);
> publicWhiteBoard.lblStatusBarEvent.setText(userName +=20
> " drew a filled Oval...");
> }//end if
> else
> {//begin else
> g.drawOval(x1, y1, x2, y2);
> publicWhiteBoard.lblStatusBarEvent.setText(userName +=20
> " drew a hollow Oval...");
> }//end else
> }//end if
> else
> {//begin else
> publicWhiteBoard.lblStatusBarEvent.setText(
> "Unknown tool used...");
> }//end else
> g.dispose();
> }//end updateCanvas()
>=20
> public Color determineColor(String strWhatColor)
> {//begin determineColor()
> if (strWhatColor.equals("Black"))
> {//begin if
> return Color.black;
> }//end if
> else if (strWhatColor.equals("DarkGray"))
> {//begin if
> return Color.darkGray;
> }//end if
> else if (strWhatColor.equals("LightGray"))
> {//begin if
> return Color.lightGray;
> }//end if
> else if (strWhatColor.equals("Gray"))
> {//begin if
> return Color.gray;
> }//end if
> else if (strWhatColor.equals("Blue"))
> {//begin if
> return Color.blue;
> }//end if
> else if (strWhatColor.equals("Green"))
> {//begin if
> return Color.green;
> }//end if
> else if (strWhatColor.equals("Cyan"))
> {//begin if
> return Color.cyan;
> }//end if
> else if (strWhatColor.equals("Magenta"))
> {//begin if
> return Color.magenta;
> }//end if
> else if (strWhatColor.equals("Pink"))
> {//begin if
> return Color.pink;
> }//end if
> else if (strWhatColor.equals("Red"))
> {//begin if
> return Color.red;
> }//end if
> else if (strWhatColor.equals("Orange"))
> {//begin if
> return Color.orange;
> }//end if
> else if (strWhatColor.equals("Yellow"))
> {//begin if
> return Color.yellow;
> }//end if
> else if (strWhatColor.equals("White"))
> {//begin if
> return Color.white;
> }//end if
> else
> {//begin else
> return Color.black;
> }//end else=20
> }//end determineColor()
>}//end class DrawingPanel
>
>--=20
>
>
>
>Best Regards,
>Wing Hoe
>---------------------------------------------------------------
>ICQ: 2213281
>Email: winghoe@hotmail.com
>www: http://pwp.maxis.net.my/winghoe
>Job Seeking Status : Active
>Availability : May 2001 (after degree course finish)
>---------------------------------------------------------------
>
>
>"alberto" <albert77@rocketmail.com> wrote in message =
>news:3a11f47f$1@news.devx.com...
>>=20
>> it wouldnt' hurt posting your code here..
>> "Lim Wing Hoe" <winghoe@hotmail.com> wrote:
>> >OK, this is what I've done. I pulled out the necessary methods and =
>put them
>> >in a class that extends JPanel.
>> >Everything works OK, except that setBackground(Color.white) doesn't =
>seem
>> to
>> >work. I'm out of my wits trying to figure out how to get this =
>extended
>> >JPanel class to have it's background set to white.
>> >
>> >Also, how do I clear the panel after I have lots of stuff drawn =
>there?
>> >
>> >--
>> >
>> >
>> >
>> >Best Regards,
>> >Wing Hoe
>> >---------------------------------------------------------------
>> >ICQ: 2213281
>> >Email: winghoe@hotmail.com
>> >www: http://pwp.maxis.net.my/winghoe
>> >Job Seeking Status : Active
>> >Availability : May 2001 (after degree course finish)
>> >---------------------------------------------------------------
>> >
>> >
>> >"zfq" <zfqjcl@371.net> wrote in message =
>news:3a116bd3$1@news.devx.com...
>> >>
>> >> "Lim Wing Hoe" <winghoe@hotmail.com> wrote:
>> >> >OK, I have a JPanel that is tied to MouseListener. I have a =
>menubar also.
>> >> >Therefore I can draw things on it with drawRect(), drawLine(), =
>etc.
>> >> >
>> >> >However, if I select the menubar, which drops down the menus or
>> >alternating
>> >> >between two applications, the drawn items will be erased from the
=
>JPanel.
>> >> >
>> >> >It's something like the application cannot keep the currently =
>drawn items
>> >> >intact and cannot refresh it.
>> >> >
>> >> >Please help.
>> >> >
>> >> >
>> >> >--
>> >> >
>> >> >
>> >> >
>> >> >Best Regards,
>> >> >Wing Hoe
>> >> >---------------------------------------------------------------
>> >> >ICQ: 2213281
>> >> >Email: winghoe@hotmail.com
>> >> >www: http://pwp.maxis.net.my/winghoe
>> >> >Job Seeking Status : Active
>> >> >Availability : May 2001 (after degree course finish)
>> >> >---------------------------------------------------------------
>> >> >
>> >> >
>> >> >
>> >> >
>> >> You should keep the drawn items with Vector or other Class in =
>java.util.*
>> >> package.
>> >>
>> >
>> >
>>=20
>
>------=_NextPart_000_0029_01C04F14.D484FF40
>Content-Type: text/html;
> charset="Windows-1252"
>Content-Transfer-Encoding: quoted-printable
>
><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
><HTML><HEAD>
><META http-equiv=3DContent-Type content=3D"text/html; =
>charset=3Dwindows-1252">
><META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR>
><STYLE></STYLE>
></HEAD>
><BODY>
><DIV><FONT size=3D2>OK here's the code. Like I mentioned before, the=20
>setBackground(Color.white) doesn't seem to work.</FONT></DIV>
><DIV><FONT size=3D2></FONT>*</DIV>
><DIV><FONT face=3DCourier size=3D2>import java.awt.*;<BR>import=20
>java.awt.event.*;<BR>import javax.swing.*;<BR>import=20
>javax.swing.event.*;<BR>import java.util.*;</FONT></DIV>
><DIV><FONT face=3DCourier size=3D2></FONT>*</DIV>
><DIV><FONT face=3DCourier size=3D2>class DrawingPanel extends =
>JPanel<BR>{//begin=20
>class DrawingPanel</FONT></DIV>
><DIV><FONT face=3DCourier size=3D2></FONT>*</DIV>
><DIV><FONT face=3DCourier size=3D2>*private PublicWhiteBoard=20
>publicWhiteBoard;<BR>*private Vector drawnObjects;<BR>*private =
>int=20
>x1;<BR>*private int y1;<BR>*private int x2;<BR>*private =
>int=20
>y2;<BR>*private int width;<BR>*private int =
>height;</FONT></DIV>
><DIV><FONT face=3DCourier size=3D2></FONT>*</DIV>
><DIV><FONT face=3DCourier size=3D2>*public =
>DrawingPanel(PublicWhiteBoard=20
>publicWhiteBoard)<BR>*{//begin =
>DrawingPanel()<BR>**super(new=20
>BorderLayout());<BR>**this.publicWhiteBoard =3D=20
>publicWhiteBoard;<BR>**this.setOpaque(true);<BR>**thi=
>s.setBackground(Color.white);<BR>**this.setForeground(Color.bla=
>ck);<BR>**this.setEnabled(true);<BR>**this.setVisible=
>(true);**<BR>**drawnObjects=20
>=3D new Vector();<BR>**listenToMouseEvents();<BR>*}//end=20
>DrawingPanel()</FONT></DIV>
><DIV><FONT face=3DCourier size=3D2></FONT>*</DIV>
><DIV><FONT face=3DCourier size=3D2>*public void=20
>listenToMouseEvents()<BR>*{//begin=20
>listenToMouseEvents()<BR>**addMouseListener(<BR>**&nb=
>sp;new=20
>MouseAdapter()<BR>***{//begin=20
>MouseAdapter()<BR>****public void =
>mousePressed(MouseEvent=20
>e)<BR>****{//begin=20
>mousePressed()<BR>*****x1 =3D=20
>e.getX();<BR>*****y1 =3D=20
>e.getY();*<BR>****}//end=20
>mousePressed()<BR>****<BR>****pub=
>lic=20
>void mouseReleased(MouseEvent e)<BR>****{//begin=20
>mouseReleased()<BR>*****x2 =3D=20
>e.getX();<BR>*****y2 =3D=20
>e.getY();*<BR>*****sendToTransmitMessage();=
><BR>****}//end=20
>mouseReleased()<BR>****<BR>****pu=
>blic=20
>void mouseEntered(MouseEvent e)<BR>****{//begin=20
>mouseEntered()<BR>*****setCursor(new=20
>Cursor(Cursor.CROSSHAIR_CURSOR));<BR>****}//end=20
>mouseEntered()<BR>****<BR>****pub=
>lic=20
>void mouseExited(MouseEvent e)<BR>****{//begin=20
>mouseExited()<BR>*****setCursor(new=20
>Cursor(Cursor.DEFAULT_CURSOR));<BR>****}//end=20
>mouseExited()<BR>***}//end=20
>MouseAdapter()<BR>**);//complete =
>addMouseListener()</FONT></DIV>
><DIV><FONT face=3DCourier size=3D2></FONT>*</DIV>
><DIV><FONT face=3DCourier=20
>size=3D2>**addMouseMotionListener(<BR>***new=20
>MouseMotionAdapter()<BR>***{//begin=20
>MouseMotionAdapter()<BR>****public void=20
>mouseDragged(MouseEvent e)<BR>****{//begin=20
>mouseDragged()<BR>*****if(publicWhiteBoard.strTo=
>ol.equals("FreeHand"))<BR>*****{//begin=20
>if<BR>******x1 =3D=20
>e.getX();<BR>******y1 =3D=20
>e.getY();<BR>******x2 =3D=20
>e.getX();<BR>******y2 =3D=20
>e.getY();*<BR>******sendToTransmitMess=
>age();<BR>*****}//end=20
>if<BR>****}//end =
>mouseDragged()<BR>***}//end=20
>MouseMotionAdapter()<BR>**);//complete=20
>addMouseMotionListener()<BR>*}//end =
>listenToMouseEvents()</FONT></DIV>
><DIV><FONT face=3DCourier size=3D2></FONT>*</DIV>
><DIV><BR><FONT face=3DCourier size=3D2>*public void=20
>sendToTransmitMessage()<BR>*{//begin=20
>sendToTransmitMessage()<BR>**calculateWidthHeight();<BR>*&=
>nbsp;publicWhiteBoard.transmitMessage(this.x1,=20
>this.y1, =
><BR>*********this.width,=20
>this.height);<BR>*}//end sentToTransmitMessage()</FONT></DIV>
><DIV><FONT face=3DCourier size=3D2></FONT>*</DIV>
><DIV><FONT face=3DCourier size=3D2>*public void =
>clearScreen()<BR>*{//begin=20
>clearScreen()<BR>**drawnObjects.clear();<BR>**this.re=
>paint();*<BR>*}//end=20
>clearScreen()</FONT></DIV>
><DIV><FONT face=3DCourier size=3D2></FONT>*</DIV>
><DIV><FONT face=3DCourier size=3D2>*public void paint(Graphics=20
>g)<BR>*{//begin paint()<BR>**for (int count =3D 0; count =
><=20
>drawnObjects.size(); count++)<BR>**{//begin for =
>loop</FONT></DIV>
><DIV><FONT face=3DCourier size=3D2></FONT>*</DIV>
><DIV><FONT face=3DCourier size=3D2>***if=20
>(drawnObjects.elementAt(count) instanceof =
>WBLine)<BR>***{//begin=20
>if<BR>****WBLine wbLine =3D (WBLine)=20
>drawnObjects.elementAt(count);<BR>****g.setColor(wbLi=
>ne.strColor);<BR>****g.drawLine(wbLine.x1,=20
>wbLine.y1, wbLine.x2, wbLine.y2);<BR>***}//end=20
>if<BR>***else if (drawnObjects.elementAt(count) =
>instanceof=20
>WBFreeHand)<BR>***{//begin else=20
>if<BR>****WBFreeHand wbFreeHand =3D=20
><BR>*****(WBFreeHand)=20
>drawnObjects.elementAt(count);<BR>****g.setColor(wbFr=
>eeHand.strColor);<BR>****g.fillRect(wbFreeHand.x1,wbF=
>reeHand.y1,2,2);<BR>***}//end=20
>else if<BR>***else if (drawnObjects.elementAt(count) =
>instanceof=20
>WBOval)<BR>***{//begin else =
>if<BR>****WBOval=20
>wbOval =3D (WBOval)=20
>drawnObjects.elementAt(count);<BR>****g.setColor(wbOv=
>al.strColor);<BR>****if=20
>(wbOval.isFilled.equals("Filled"))<BR>****{//begin=20
>if<BR>*****g.fillOval(wbOval.x1, wbOval.y1, =
>wbOval.x2,=20
>wbOval.y2);<BR>****}//end=20
>if<BR>****else<BR>****{//begin=20
>else<BR>*****g.drawOval(wbOval.x1, wbOval.y1,=20
>wbOval.x2, wbOval.y2);<BR>****}//end=20
>else*<BR>***}//end else if<BR>***else =
>if=20
>(drawnObjects.elementAt(count) instanceof=20
>WBRectangle)<BR>***{//begin else=20
>if<BR>****WBRectangle wbRectangle =3D=20
><BR>*****(WBRectangle)=20
>drawnObjects.elementAt(count);<BR>****g.setColor(wbRe=
>ctangle.strColor);<BR>****if=20
>(wbRectangle.isFilled.equals("Filled"))<BR>****{//beg=
>in=20
>if<BR>*****g.fillRect(wbRectangle.x1, =
>wbRectangle.y1,=20
><BR>******wbRectangle.x2,=20
>wbRectangle.y2);<BR>****}//end=20
>if<BR>****else<BR>****{//begin=20
>else<BR>*****g.drawRect(wbRectangle.x1, =
>wbRectangle.y1,=20
><BR>******wbRectangle.x2,=20
>wbRectangle.y2);<BR>****}//end=20
>else*<BR>***}//end else if<BR>**}//end for =
>
>loop<BR>**g.dispose();<BR>*}//end paint()</FONT></DIV>
><DIV><FONT face=3DCourier size=3D2></FONT>*</DIV>
><DIV><BR><FONT face=3DCourier size=3D2>*public void=20
>calculateWidthHeight()<BR>*{//begin=20
>calculateWidthHeight()<BR>**if(publicWhiteBoard.strTool.equals(=
>"Line"))<BR>**{//begin=20
>if<BR>***width =3D x2;<BR>***height =3D=20
>y2;<BR>**}//end if<BR>**else if=20
>(publicWhiteBoard.strTool.equals("FreeHand"))<BR>**{//begin =
>else=20
>if<BR>***width =3D x2;<BR>***height =3D=20
>y2;<BR>**}//end else =
>if<BR>**else<BR>**{//begin=20
>else<BR>***//get the width between two=20
>coordinates<BR>***if =
>(x1<=3Dx2)<BR>***{//begin=20
>if<BR>****width* =3D x2 - =
>x1;<BR>***}//end=20
>if<BR>***else<BR>***{//begin=20
>else<BR>****width* =3D x1 -=20
>x2;<BR>***}//end=20
>else*<BR>***<BR>***//get the height =
>between=20
>two coordinates<BR>***if (y1 <=3D=20
>y2)<BR>***{//begin if<BR>****height =
>=3D y2 -=20
>y1;<BR>***}//end=20
>if<BR>***else<BR>***{//begin=20
>else<BR>****height =3D y1 - =
>y2;<BR>***}//end=20
>else*</FONT></DIV>
><DIV><FONT face=3DCourier size=3D2></FONT>*</DIV>
><DIV><FONT face=3DCourier size=3D2>***//get the x1 and y1 =
>when the=20
>user draws the object<BR>***//backwards. this is a must =
>because=20
>the methods<BR>***//drawLine(), drawRect() and so on, =
>draws the=20
>object<BR>***//from the last coordinate to the width and=20
>height.<BR>***//it will draw forward and down from the =
>first=20
>coordinates. <BR>***if ((x1 <=3D x2) && (y2 =
>>=3D=20
>y1))<BR>***{//begin if<BR>****x1 =3D =
>x1;=20
><BR>****y1 =3D y1;<BR>***}//end=20
>if<BR>***else if ((x1 <=3D x2) && (y2 <=3D=20
>y1))<BR>***{//begin else if<BR>****x1 =
>=3D=20
>x1;<BR>****y1 =3D y2;<BR>***}//end =
>else=20
>if<BR>***else if ((x1 >=3D x2) && (y2 >=3D=20
>y1))<BR>***{//begin else if<BR>****x1 =
>=3D=20
>x2;<BR>****y1 =3D y1;<BR>***}//end =
>else=20
>if<BR>***else if ((x1 >=3D x2) && (y2 <=3D=20
>y1))<BR>***{//begin else if<BR>****x1 =
>=3D=20
>x2;<BR>****y1 =3D y2;<BR>***}//end =
>else=20
>if<BR>**}//end else<BR>*}//end=20
>calculateWidthHeight()</FONT></DIV>
><DIV><FONT face=3DCourier size=3D2></FONT>*</DIV>
><DIV><FONT face=3DCourier size=3D2>*public void updateCanvas(String =
>strTool,=20
>String strColor,=20
><BR>********** String=20
>isFilled, int x1, int y1, <BR>******* =
>int x2,=20
>int y2, String userName)<BR>*{//begin=20
>updateCanvas()<BR>*<BR>**Graphics g =3D=20
>this.getGraphics();<BR>**g.setColor(this.determineColor(strColo=
>r));<BR>*<BR>**if(strTool.equals("Line"))<BR>**{=
>//begin=20
>if<BR>***//add to the drawnObjects Vector so that when =
>the=20
>paint()<BR>***//method is called, the objects can be=20
>redrawn.<BR>***drawnObjects.addElement(<BR>**&nb=
>sp;*new=20
>WBLine(g.getColor(), x1, y1, x2, =
>y2));<BR>***g.drawLine(x1, y1,=20
>x2,=20
>y2);<BR>***publicWhiteBoard.lblStatusBarEvent.setText(user=
>Name +=20
><BR>***********&nb=
>sp;*"=20
>drew a line...");<BR>**}//end if<BR>**else=20
>if(strTool.equals("FreeHand"))<BR>**{//begin else=20
>if<BR>***//add to the drawnObjects Vector so that when =
>the=20
>paint()<BR>***//method is called, the objects can be=20
>redrawn.<BR>***drawnObjects.addElement(<BR>**&nb=
>sp;*new=20
>WBFreeHand(g.getColor(), x1,=20
>y1));<BR>***g.fillRect(x1,y1,2,2);<BR>***pu=
>blicWhiteBoard.lblStatusBarEvent.setText(userName=20
>+ <BR>**********" drew =
>a=20
>FreeHand line...");<BR>**}//end else if<BR>**else=20
>if(strTool.equals("Rectangle"))<BR>**{//begin=20
>if<BR>***//add to the drawnObjects Vector so that when =
>the=20
>paint()<BR>***//method is called, the objects can be=20
>redrawn.<BR>***drawnObjects.addElement(<BR>**&nb=
>sp;*new=20
>WBRectangle(g.getColor(), isFilled, x1, y1, x2, y2));</FONT></DIV>
><DIV><FONT face=3DCourier size=3D2></FONT>*</DIV>
><DIV><FONT face=3DCourier=20
>size=3D2>***if(isFilled.equals("Filled"))<BR>**&=
>nbsp;{//begin=20
>if<BR>****g.fillRect(x1, y1, x2,=20
>y2);<BR>****publicWhiteBoard.lblStatusBarEvent.setTex=
>t(userName=20
>+ <BR>**********" drew =
>a=20
>filled rectangle...");<BR>***}//end=20
>if<BR>***else<BR>***{//begin=20
>else<BR>****g.drawRect(x1, y1, x2,=20
>y2);<BR>****publicWhiteBoard.lblStatusBarEvent.setTex=
>t(userName=20
>+ <BR>**********" drew =
>a=20
>hollow rectangle...");<BR>***}//end=20
>else***<BR>**}//end if<BR>**else=20
>if(strTool.equals("Oval"))<BR>**{//begin =
>if<BR>***//add=20
>to the drawnObjects Vector so that when the=20
>paint()<BR>***//method is called, the objects can be=20
>redrawn.<BR>***drawnObjects.addElement(<BR>**&nb=
>sp;*new=20
>WBOval(g.getColor(), isFilled, x1, y1, x2, y2));</FONT></DIV>
><DIV><FONT face=3DCourier size=3D2></FONT>*</DIV>
><DIV><FONT face=3DCourier=20
>size=3D2>***if(isFilled.equals("Filled"))<BR>**&=
>nbsp;{//begin=20
>if<BR>****g.fillOval(x1, y1, x2,=20
>y2);<BR>****publicWhiteBoard.lblStatusBarEvent.setTex=
>t(userName=20
>+ =
><BR>***********" =
>drew a=20
>filled Oval...");<BR>***}//end=20
>if<BR>***else<BR>***{//begin=20
>else<BR>****g.drawOval(x1, y1, x2,=20
>y2);<BR>****publicWhiteBoard.lblStatusBarEvent.setTex=
>t(userName=20
>+ =
><BR>***********" =
>drew a=20
>hollow Oval...");<BR>***}//end else<BR>**}//end =
>
>if<BR>**else<BR>**{//begin=20
>else<BR>***publicWhiteBoard.lblStatusBarEvent.setText(<BR>=
>**********"Unknown=20
>tool used...");<BR>**}//end=20
>else<BR>**g.dispose();<BR>*}//end=20
>updateCanvas()<BR>*<BR>*public Color determineColor(String=20
>strWhatColor)<BR>*{//begin determineColor()<BR>**if=20
>(strWhatColor.equals("Black"))<BR>**{//begin=20
>if<BR>***return Color.black;<BR>**}//end=20
>if<BR>**else if=20
>(strWhatColor.equals("DarkGray"))<BR>**{//begin=20
>if<BR>***return Color.darkGray;<BR>**}//end=20
>if<BR>**else if=20
>(strWhatColor.equals("LightGray"))<BR>**{//begin=20
>if<BR>***return Color.lightGray;<BR>**}//end=20
>if<BR>**else if =
>(strWhatColor.equals("Gray"))<BR>**{//begin=20
>if<BR>***return Color.gray;<BR>**}//end=20
>if<BR>**else if =
>(strWhatColor.equals("Blue"))<BR>**{//begin=20
>if<BR>***return Color.blue;<BR>**}//end=20
>if<BR>**else if =
>(strWhatColor.equals("Green"))<BR>**{//begin=20
>if<BR>***return Color.green;<BR>**}//end=20
>if<BR>**else if =
>(strWhatColor.equals("Cyan"))<BR>**{//begin=20
>if<BR>***return Color.cyan;<BR>**}//end=20
>if<BR>**else if=20
>(strWhatColor.equals("Magenta"))<BR>**{//begin=20
>if<BR>***return Color.magenta;<BR>**}//end=20
>if<BR>**else if =
>(strWhatColor.equals("Pink"))<BR>**{//begin=20
>if<BR>***return Color.pink;<BR>**}//end=20
>if<BR>**else if =
>(strWhatColor.equals("Red"))<BR>**{//begin=20
>if<BR>***return Color.red;<BR>**}//end=20
>if<BR>**else if=20
>(strWhatColor.equals("Orange"))<BR>**{//begin=20
>if<BR>***return Color.orange;<BR>**}//end=20
>if<BR>**else if=20
>(strWhatColor.equals("Yellow"))<BR>**{//begin=20
>if<BR>***return Color.yellow;<BR>**}//end=20
>if<BR>**else if =
>(strWhatColor.equals("White"))<BR>**{//begin=20
>if<BR>***return Color.white;<BR>**}//end=20
>if<BR>**else<BR>**{//begin =
>else<BR>***return=20
>Color.black;<BR>**}//end else*<BR>*}//end=20
>determineColor()</FONT></DIV>
><DIV><FONT face=3DCourier size=3D2>}//end class =
>DrawingPanel</FONT></DIV>
><DIV><BR><FONT size=3D2>-- <BR></FONT></DIV>
><DIV><FONT size=3D2></FONT>*</DIV>
><DIV><BR><FONT size=3D2>Best Regards,<BR>Wing=20
>Hoe<BR>---------------------------------------------------------------<BR=
>>ICQ:=20
>2213281<BR>Email: </FONT><A href=3D"mailto:winghoe@hotmail.com"><FONT=20
>size=3D2>winghoe@hotmail.com</FONT></A><BR><FONT size=3D2>www: </FONT><A
=
>
>href=3D"http://pwp.maxis.net.my/winghoe"><FONT=20
>size=3D2>http://pwp.maxis.net.my/winghoe</FONT></A><BR><FONT =
>size=3D2>Job Seeking=20
>Status : Active<BR>Availability : May 2001 (after degree course=20
>finish)<BR>--------------------------------------------------------------=
>-</FONT></DIV>
><DIV><FONT size=3D2></FONT>*</DIV>
><DIV><FONT size=3D2></FONT>*</DIV>
><DIV><FONT size=3D2>"alberto" <</FONT><A=20
>href=3D"mailto:albert77@rocketmail.com"><FONT=20
>size=3D2>albert77@rocketmail.com</FONT></A><FONT size=3D2>> wrote in =
>message=20
></FONT><A href=3D"news:3a11f47f$1@news.devx.com"><FONT=20
>size=3D2>news:3a11f47f$1@news.devx.com</FONT></A><FONT=20
>size=3D2>...</FONT></DIV><FONT size=3D2>> <BR>> it wouldnt' hurt =
>posting your=20
>code here..<BR>> "Lim Wing Hoe" <</FONT><A=20
>href=3D"mailto:winghoe@hotmail.com"><FONT=20
>size=3D2>winghoe@hotmail.com</FONT></A><FONT size=3D2>> =
>wrote:<BR>> >OK,=20
>this is what I've done. I pulled out the necessary methods and put =
>them<BR>>=20
>>in a class that extends JPanel.<BR>> >Everything works OK, =
>except that=20
>setBackground(Color.white) doesn't seem<BR>> to<BR>> >work. I'm =
>out of=20
>my wits trying to figure out how to get this extended<BR>> >JPanel =
>class=20
>to have it's background set to white.<BR>> ><BR>> >Also, how =
>do I=20
>clear the panel after I have lots of stuff drawn there?<BR>> =
>><BR>>=20
>>--<BR>> ><BR>> ><BR>> ><BR>> >Best =
>Regards,<BR>>=20
>>Wing Hoe<BR>>=20
>>---------------------------------------------------------------<BR>&g=
>t;=20
>>ICQ: 2213281<BR>> >Email: </FONT><A=20
>href=3D"mailto:winghoe@hotmail.com"><FONT=20
>size=3D2>winghoe@hotmail.com</FONT></A><BR><FONT size=3D2>> >www: =
></FONT><A=20
>href=3D"http://pwp.maxis.net.my/winghoe"><FONT=20
>size=3D2>http://pwp.maxis.net.my/winghoe</FONT></A><BR><FONT =
>size=3D2>> >Job=20
>Seeking Status : Active<BR>> >Availability : May 2001 (after =
>degree course=20
>finish)<BR>>=20
>>---------------------------------------------------------------<BR>&g=
>t;=20
>><BR>> ><BR>> >"zfq" <</FONT><A=20
>href=3D"mailto:zfqjcl@371.net"><FONT =
>size=3D2>zfqjcl@371.net</FONT></A><FONT=20
>size=3D2>> wrote in message </FONT><A=20
>href=3D"news:3a116bd3$1@news.devx.com"><FONT=20
>size=3D2>news:3a116bd3$1@news.devx.com</FONT></A><FONT =
>size=3D2>...<BR>>=20
>>><BR>> >> "Lim Wing Hoe" <</FONT><A=20
>href=3D"mailto:winghoe@hotmail.com"><FONT=20
>size=3D2>winghoe@hotmail.com</FONT></A><FONT size=3D2>> =
>wrote:<BR>> >>=20
>>OK, I have a JPanel that is tied to MouseListener. I have a menubar=20
>also.<BR>> >> >Therefore I can draw things on it with =
>drawRect(),=20
>drawLine(), etc.<BR>> >> ><BR>> >> >However, if =
>I select=20
>the menubar, which drops down the menus or<BR>> =
>>alternating<BR>>=20
>>> >between two applications, the drawn items will be erased =
>from the=20
>JPanel.<BR>> >> ><BR>> >> >It's something like =
>the=20
>application cannot keep the currently drawn items<BR>> >> =
>>intact=20
>and cannot refresh it.<BR>> >> ><BR>> >> >Please =
>
>help.<BR>> >> ><BR>> >> ><BR>> >>=20
>>--<BR>> >> ><BR>> >> ><BR>> >> =
>><BR>>=20
>>> >Best Regards,<BR>> >> >Wing Hoe<BR>> =
>>>=20
>>---------------------------------------------------------------<BR>&g=
>t;=20
>>> >ICQ: 2213281<BR>> >> >Email: </FONT><A=20
>href=3D"mailto:winghoe@hotmail.com"><FONT=20
>size=3D2>winghoe@hotmail.com</FONT></A><BR><FONT size=3D2>> >> =
>>www:=20
></FONT><A href=3D"http://pwp.maxis.net.my/winghoe"><FONT=20
>size=3D2>http://pwp.maxis.net.my/winghoe</FONT></A><BR><FONT =
>size=3D2>> >>=20
>>Job Seeking Status : Active<BR>> >> >Availability : May =
>2001=20
>(after degree course finish)<BR>> >>=20
>>---------------------------------------------------------------<BR>&g=
>t;=20
>>> ><BR>> >> ><BR>> >> ><BR>> =
>>>=20
>><BR>> >> You should keep the drawn items with Vector or =
>other Class=20
>in java.util.*<BR>> >> package.<BR>> >><BR>> =
>><BR>>=20
>><BR>> </FONT></BODY></HTML>
>
>------=_NextPart_000_0029_01C04F14.D484FF40--
>
You can use Panel, unuse JPanel.Don't use swing widgets in your code. This
can solove you problem.
The reason, I haven't completly unsterdand now.
-
Re: GUI Refresh problem?
It's OK. I fixed, I placed a call to the superclass's (JPanel) paint()
method inside the current paint() method that I've overridden. This allows
the setBackground() method to be executed correctly.
Thanks for helping.
--
Best Regards,
Wing Hoe
---------------------------------------------------------------
ICQ: 2213281
Email: winghoe@hotmail.com
www: http://pwp.maxis.net.my/winghoe
Job Seeking Status : Active
Availability : May 2001 (after degree course finish)
---------------------------------------------------------------
"zfq" <zfqjcl@371.net> wrote in message news:3a15584c$1@news.devx.com...
>
> You can use Panel, unuse JPanel.Don't use swing widgets in your code. This
> can solove you problem.
> The reason, I haven't completly unsterdand now.
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks