Re: Callbacks, and using interfaces as arguments
- From: IchBin <weconsul@xxxxxxx>
- Date: Sat, 31 Dec 2005 00:39:18 -0500
Mike wrote:
I have the following code snippets. Both has a method call to addWindowListener
It is my understanding that BookOrderFrame is using a callback method to implement the interface for WindowListener. Am I correct?
LoanCalculatorFrame otoh, does it substantially different and does not even state "implements WindowListener".
So can anyone please explain what LoanCalculatorFrame does and whether and how it is better/worse than what BookOrderFrame is doing?
Thanks.
import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.text.*;
public class LoanCalculatorFrame extends JFrame { public LoanCalculatorFrame() { setTitle("Loan Calculator"); Toolkit tk = Toolkit.getDefaultToolkit(); Dimension d = tk.getScreenSize(); System.out.println("Screen:" + d.width + " by " + d.height + " pixels"); int height = 200; int width = 267; setBounds((d.width-width)/2, (d.height-height)/2, width, height); setResizable(false); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } ); Container contentPane = getContentPane(); JPanel panel = new JPanel(); contentPane.add(panel);
} }
import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.text.*;
public class BookOrderFrame extends JFrame implements WindowListener { public BookOrderFrame() { setTitle("Book Order"); setBounds(267, 200, 267, 200); addWindowListener(this); }
public void windowDeactivated(WindowEvent e) { }
public void windowActivated(WindowEvent e) { }
public void windowDeiconified(WindowEvent e) { }
public void windowIconified(WindowEvent e) { }
public void windowClosed(WindowEvent e) { }
public void windowClosing(WindowEvent e) { System.exit(0); }
public void windowOpened(WindowEvent e) { } }
The Docs for WindowListener Interface I think explains it.
The listener interface for receiving window events. The class that is interested in processing a window event either implements this interface (*and all the methods it contains*) or extends the abstract WindowAdapter class (*overriding only the methods of interest*).
--
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"' -William E. Taylor, Regular Guy (1952-) .
- Follow-Ups:
- References:
- Callbacks, and using interfaces as arguments
- From: Mike
- Callbacks, and using interfaces as arguments
- Prev by Date: Callbacks, and using interfaces as arguments
- Next by Date: Re: Callbacks, and using interfaces as arguments
- Previous by thread: Callbacks, and using interfaces as arguments
- Next by thread: Re: Callbacks, and using interfaces as arguments
- Index(es):
Relevant Pages
|