G
Guest
I had a little demo standalone applet with a working mouse listener. I
am now trying to have it work in a Swing Japplet, but I can't.
The working example has
public class myApplet13 extends Applet implements MouseListener {
then in the applet init method I have
addMouseListener(this);
then in the applet paint method I have some custom image drawing
g2.drawImage(img,xoff,yoff,null) ;
and finally I have a mouseClicked(MouseEvent e) method which does some
basic things like reading the screen coordinates and returning the image
coordinates, and the value (in physical units) in the array underlying
the displayed image (so far prints to stdout, I use appletviewer for
testing)
In the non working case I have
public class myApplet17 extends JApplet {
The init method is the standard swing thing from the tutorial which
uses SwingUtilities.invokeAndWait(new Runnable() to run realMain() ;
this in turn invokes a custom class
private void realMain() {
myGui=new myGui();
myGui.setOpaque(true);
setContentPane(myGui);
}
which defines a top tabbed pane and a bottom text area
class myGui extends JPanel {
JTextArea msg;
JComponent tabPane;
myGui() {
super(new BorderLayout());
JPanel panel = new JPanel(new GridLayout(2, 1));
tabPane = new myTabPane();
...
msg = new JTextArea(20,80) ;
panel.add(msg);
...
the tabbed pane consist of 4 tabs
class myTabPane extends JPanel implements myListener {
myDisplay panel1 ;
public myTabPane() {
super(new GridLayout(1, 1));
JTabbedPane tabbedPane = new JTabbedPane();
// first tab is main display
panel1 = new myDisplay() ;
of which the first panel is an invocation of a class corresponding to
the former standalone applet
class myDisplay extends JPanel { // implements MouseListener ?? {
namely its paintComponent(Graphics g) method is the equivalent of the
standalone applet custom image painting (which works)
I have a custom interface
interface myListener extends
ActionListener,PropertyChangeListener,ItemListener {
which collects the listeners used by the various buttons etc. in the
tabbed pane
I tried adding MouseListener there, or to the myDisplay (commented
above)
interface myListener extends
ActionListener,PropertyChangeListener,ItemListener,MouseListener {
and to place addMouseListener(this); in different places, but in all
cases I get no effect.
Where should I do this ?
am now trying to have it work in a Swing Japplet, but I can't.
The working example has
public class myApplet13 extends Applet implements MouseListener {
then in the applet init method I have
addMouseListener(this);
then in the applet paint method I have some custom image drawing
g2.drawImage(img,xoff,yoff,null) ;
and finally I have a mouseClicked(MouseEvent e) method which does some
basic things like reading the screen coordinates and returning the image
coordinates, and the value (in physical units) in the array underlying
the displayed image (so far prints to stdout, I use appletviewer for
testing)
In the non working case I have
public class myApplet17 extends JApplet {
The init method is the standard swing thing from the tutorial which
uses SwingUtilities.invokeAndWait(new Runnable() to run realMain() ;
this in turn invokes a custom class
private void realMain() {
myGui=new myGui();
myGui.setOpaque(true);
setContentPane(myGui);
}
which defines a top tabbed pane and a bottom text area
class myGui extends JPanel {
JTextArea msg;
JComponent tabPane;
myGui() {
super(new BorderLayout());
JPanel panel = new JPanel(new GridLayout(2, 1));
tabPane = new myTabPane();
...
msg = new JTextArea(20,80) ;
panel.add(msg);
...
the tabbed pane consist of 4 tabs
class myTabPane extends JPanel implements myListener {
myDisplay panel1 ;
public myTabPane() {
super(new GridLayout(1, 1));
JTabbedPane tabbedPane = new JTabbedPane();
// first tab is main display
panel1 = new myDisplay() ;
of which the first panel is an invocation of a class corresponding to
the former standalone applet
class myDisplay extends JPanel { // implements MouseListener ?? {
namely its paintComponent(Graphics g) method is the equivalent of the
standalone applet custom image painting (which works)
I have a custom interface
interface myListener extends
ActionListener,PropertyChangeListener,ItemListener {
which collects the listeners used by the various buttons etc. in the
tabbed pane
I tried adding MouseListener there, or to the myDisplay (commented
above)
interface myListener extends
ActionListener,PropertyChangeListener,ItemListener,MouseListener {
and to place addMouseListener(this); in different places, but in all
cases I get no effect.
Where should I do this ?