Callbacks, and using interfaces as arguments
- From: "Mike" <MPBrede@xxxxxxxxx>
- Date: 30 Dec 2005 21:13:09 -0800
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)
{
}
}
.
- Follow-Ups:
- Re: Callbacks, and using interfaces as arguments
- From: Thomas Hawtin
- Re: Callbacks, and using interfaces as arguments
- From: IchBin
- Re: Callbacks, and using interfaces as arguments
- Prev by Date: Yahoo Games
- Next by Date: Re: Callbacks, and using interfaces as arguments
- Previous by thread: Yahoo Games
- Next by thread: Re: Callbacks, and using interfaces as arguments
- Index(es):