Mail...@gmail.com wrote:
> Hiya, I think this is a fairly common JPanel related question ...
Note that questions that are 'fairly common' are
also 'frequently answered'. Did you check the FAQ?
Andrew T.
IchBin - 25 Aug 2006 06:54 GMT
> Mail...@gmail.com wrote:
>> Hiya, I think this is a fairly common JPanel related question ...
[quoted text clipped - 3 lines]
>
> Andrew T.
He may not know where to find it.

Signature
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Andrew Thompson - 25 Aug 2006 10:54 GMT
> > Mail...@gmail.com wrote:
> >> Hiya, I think this is a fairly common JPanel related question ...
> >
> > Note that questions that are 'fairly common' are
> > also 'frequently answered'. Did you check the FAQ?
...
> He may not know where to find it.
That is one possiblility, here are some others..
a) The OP may know where to find it., and if not,
b) The OP might ...
- discover it by search for it
- ask for directions
- read the group for a few days, in which time the link
will most likely appear.
(And 'He', might be 'She'..)
Andrew T.
Mail987@gmail.com schrieb:
> Hiya, I think this is a fairly common JPanel related question and would
> love any help,
[quoted text clipped - 7 lines]
> updated? Or do I do it on the rectangle itself? Or some other way
> perhas?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test extends JPanel {
private Rectangle rect = new Rectangle(0,0,0,0);
public Dimension getPreferredSize() {
return new Dimension(600,400);
}
public void setRectangle( int x, int y, int w, int h ) {
rect.x = x;
rect.y = y;
rect.width = w;
rect.height = h;
repaint();
}
public void setRectangle( Rectangle r ) {
setRectangle( r.x, r.y, r.width, r.height );
}
public void paintComponent( Graphics g ) {
super.paintComponent( g );
g.drawRect( rect.x, rect.y, rect.width, rect.height );
}
public static final void main( String args[] ) {
final Rectangle r = new Rectangle(10,10,20,20);
final Test test = new Test();
test.setRectangle( r );
test.addMouseListener( new MouseAdapter() {
public void mouseClicked( MouseEvent e ) {
r.x = e.getX();
r.y = e.getY();
test.setRectangle( r );
}
});
JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
frame.setContentPane( test );
frame.pack();
frame.setVisible( true );
}
}
Bye
Michael