Posted by Steve Hawkinson on 1999-07-17
> > Date: Fri, 16 Jul 1999 00:31:31 0100 > From: Nicolas DUTEIL <happy.shine@xxxxxxx.xxx> > Subject: setVisible() in Java > > Does anybody knows how to make an object visible or unvisible just by > clicking on 2 different buttons ? > In my applet, it only works when my object is visible at first. > If I use the seVisible(false) function in my init proc, and click on the button, > the object keeps unvisible. > I used the action proc to handle the events (is there a better way ? -jsk 1.2) You have to register the buttons with an ActionListener, in the class that implements ActionListener you have to define the method actionPerformed(ActionEvent e) in this method you can figure out which button was pressed using e.getActionCommand(); Once you figure out which button was pressed you can call setVisible(true) or setVisible(false). I would have the applet implement the MouseListener interface so you don't need another class. It sounds like you are doing something like this already, but maybe this will help. Steve > Date: Fri, 16 Jul 1999 16:38:17 EDT > From: Kspansel@xxx.xxx > Subject: Closing a subclassed frame in java > > Hi.. > I have created a simple subclass of a frame and then I have displayed > it on the screen. How would I now, close the window that I have created just > choosing close doesn't work. Is it supposed to be this way or is there > something wrong? Thanks. > > Kory Spansel Have the class implement a WindowListener. You have to define 6 methods suchas windowClosed, windowClosing, etc... In the window closing method you have to say something like this.setVisible(false); this.destroy(); and the window will close when you hit the little 'x' in the top right hand corner. All of the awt event listeners are defined in the java.awt.event package. You can look up the exact methods you need to define in the API spec. If you don't have a book, there is one on line at java.sun.com Steve
Previous post | Next post | Timeline | Home