A Frame is a top-level window with a title and a border. A Window object is a top-level window with no borders and no menubar. The default layout for a window is BorderLayout. A window must have either a frame, dialog, or another window defined as its owner when it's constructed.
import java.awt.*; import java.awt.event.*;public class FrameWindow extends Frame { public FrameWindow() { Window win = new Window(this); win.setBackground(Color.lightGray); setSize(300,200); setTitle("Frame"); addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); show(); win.setSize(360,200); win.setLocation(200,200); win.show(); } public static void main(String args[]) { new FrameWindow(); } }
window是一个窗口,什么都没有,包括边框。并且要放在一个frame之上,当然也可放在一个共享的Frame上(系统提供),主要应用于快闪窗口,也就是应用程序运行前的哪个屏幕居中显示的图片窗。在swing中的工具按钮提示(tooltip)也是用窗口的方式实现的。
import java.awt.event.*;public class FrameWindow extends Frame
{
public FrameWindow()
{
Window win = new Window(this);
win.setBackground(Color.lightGray);
setSize(300,200);
setTitle("Frame");
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
show();
win.setSize(360,200);
win.setLocation(200,200);
win.show();
}
public static void main(String args[])
{
new FrameWindow();
}
}