Hi all,
I have this piece of code;
Frame containing JTabbedPane (mTabbedPane)
JTabbedPane has a JPanel (finalPanel)
finalPanel contains a JScrollPane which has a ImagePanel*
finalPanel also has three JButtons(SOUTH).
i want to add a JLabel to finalPanel(SOUTH), that displays x and y
co-ordinates of the ImagePanel which implelents MouseMotionListener,
but other that giving a Reference to the JLabel is there another way of
doing this. I thought there was a way of telling other Components that
a event inside another Component has changed ?
Any help will be appreciated.
*P.S: see prevoius post on "JTabbedPane problem" by placid/me.
|
|
0
|
|
|
|
Reply
|
Bulkan (178)
|
12/22/2005 5:23:00 AM |
|
placid wrote:
> Hi all,
>
> I have this piece of code;
>
> Frame containing JTabbedPane (mTabbedPane)
> JTabbedPane has a JPanel (finalPanel)
> finalPanel contains a JScrollPane which has a ImagePanel*
> finalPanel also has three JButtons(SOUTH).
>
> i want to add a JLabel to finalPanel(SOUTH), that displays x and y
> co-ordinates of the ImagePanel which implelents MouseMotionListener,
> but other that giving a Reference to the JLabel is there another way of
> doing this. I thought there was a way of telling other Components that
> a event inside another Component has changed ?
>
> Any help will be appreciated.
>
> *P.S: see prevoius post on "JTabbedPane problem" by placid/me.
>
It looks like you have reached that point in your Java programming where
you can't figure you how to get all the pieces to talk to each other.
Most of the time it is pretty simple. Group all of the related things
together. If for example you are going to have a group of components on
a panel, create a class that extends a panel and add your components to
it. Then the references are local and easy to keep track of. If you
need a reference to the container that the panel is in, pass it in the
constructor. There are a million ways to program anything but simple is
usually best.
import java.awt.*;
import java.awt.event.*;
public class test9 extends Panel {
public test9(final Frame f) {
final Label l = new Label(" ");
add(l,BorderLayout.CENTER);
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent me) {
f.setTitle(Integer.toString(me.getX())+" "+
Integer.toString(me.getY()));
l.setText(Integer.toString(me.getX())+" "+
Integer.toString(me.getY()));
}
});
setPreferredSize(new Dimension(400,300));
}
public static void main(String[] args) {
Frame f = new Frame();
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
f.add(new test9(f));
f.pack();
f.setVisible(true);
}
}
--
Knute Johnson
email s/nospam/knute/
|
|
0
|
|
|
|
Reply
|
Knute
|
12/22/2005 5:44:57 AM
|
|