类框架(Frame )是一个顶层窗口边框和标题。它使用BorderLayout作为默认的布局管理器。
类的声明
以下是的声明的java.awt.Frame类:
public class Frame extends Window implements MenuContainer
字段域
以下java.awt.Frame类的字段:
- 
		
static float BOTTOM_ALIGNMENT -- Ease-of-use constant for getAlignmentY.
 - 
		
static int CROSSHAIR_CURSOR -- Deprecated. replaced by Cursor.CROSSHAIR_CURSOR.
 - 
		
static int DEFAULT_CURSOR -- Deprecated. replaced by Cursor.DEFAULT_CURSOR.
 - 
		
static int E_RESIZE_CURSOR -- Deprecated. replaced by Cursor.E_RESIZE_CURSOR.
 - 
		
static int HAND_CURSOR -- Deprecated. replaced by Cursor.HAND_CURSOR.
 - 
		
static int ICONIFIED -- This state bit indicates that frame is iconified.
 - 
		
static int MAXIMIZED_BOTH -- This state bit mask indicates that frame is fully maximized (that is both horizontally and vertically).
 - 
		
static int MAXIMIZED_HORIZ -- This state bit indicates that frame is maximized in the horizontal direction.
 - 
		
static int MAXIMIZED_VERT -- This state bit indicates that frame is maximized in the vertical direction.
 - 
		
static int MOVE_CURSOR -- Deprecated. replaced by Cursor.MOVE_CURSOR.
 - 
		
static int N_RESIZE_CURSOR -- Deprecated. replaced by Cursor.N_RESIZE_CURSOR.
 - 
		
static int NE_RESIZE_CURSOR -- Deprecated. replaced by Cursor.NE_RESIZE_CURSOR.
 - 
		
static int NORMAL -- Frame is in the "normal" state.
 - 
		
static int NW_RESIZE_CURSOR -- Deprecated. replaced by Cursor.NW_RESIZE_CURSOR.
 - 
		
static int S_RESIZE_CURSOR -- Deprecated. replaced by Cursor.S_RESIZE_CURSOR.
 - 
		
static int SE_RESIZE_CURSOR -- Deprecated. replaced by Cursor.SE_RESIZE_CURSOR.
 - 
		
static int SW_RESIZE_CURSOR -- Deprecated. replaced by Cursor.SW_RESIZE_CURSOR.
 - 
		
static int TEXT_CURSOR -- Deprecated. replaced by Cursor.TEXT_CURSOR.
 - 
		
static int W_RESIZE_CURSOR -- Deprecated. replaced by Cursor.W_RESIZE_CURSOR.
 - 
		
static int WAIT_CURSOR -- Deprecated. replaced by Cursor.WAIT_CURSOR.
 
类的构造函数
| S.N. | 构造函数与说明 | 
|---|---|
| 1 | 
				Frame()  Constructs a new instance of Frame that is initially invisible.  | 
		
| 2 | 
				Frame(GraphicsConfiguration gc)  Constructs a new, initially invisible Frame with the specified GraphicsConfiguration.  | 
		
| 3 | 
				Frame(String title)  Constructs a new, initially invisible Frame object with the specified title.  | 
		
| 4 | 
				Frame(String title, GraphicsConfiguration gc)  Constructs a new, initially invisible Frame object with the specified title and a GraphicsConfiguration.  | 
		
类方法
| S.N. | 方法及说明 | 
|---|---|
| 1 | 
				void addNotify()  Makes this Frame displayable by connecting it to a native screen resource.  | 
		
| 2 | 
				AccessibleContext getAccessibleContext()  Gets the AccessibleContext associated with this Frame.  | 
		
| 3 | 
				int getCursorType()  Deprecated. As of JDK version 1.1, replaced by Component.getCursor().  | 
		
| 4 | 
				int getExtendedState()  Gets the state of this frame.  | 
		
| 5 | 
				static Frame[] getFrames()  Returns an array of all Frames created by this application.  | 
		
| 6 | 
				Image getIconImage()  Returns the image to be displayed as the icon for this frame.  | 
		
| 7 | 
				Rectangle getMaximizedBounds()  Gets maximized bounds for this frame.  | 
		
| 8 | 
				MenuBar getMenuBar()  Gets the menu bar for this frame.  | 
		
| 9 | 
				int getState()  Gets the state of this frame (obsolete).  | 
		
| 10 | 
				String getTitle() Gets the title of the frame.  | 
		
| 11 | 
				boolean isResizable()  Indicates whether this frame is resizable by the user.  | 
		
| 12 | 
				boolean isUndecorated()  Indicates whether this frame is undecorated.  | 
		
| 13 | 
				protected String paramString()  Returns a string representing the state of this Frame.  | 
		
| 14 | 
				void remove(MenuComponent m)  Removes the specified menu bar from this frame.  | 
		
| 15 | 
				void removeNotify()  Makes this Frame undisplayable by removing its connection to its native screen resource.  | 
		
| 16 | 
				void setCursor(int cursorType)  Deprecated. As of JDK version 1.1, replaced by Component.setCursor(Cursor).  | 
		
| 17 | 
				void setExtendedState(int state)  Sets the state of this frame.  | 
		
| 18 | 
				void setIconImage(Image image)  Sets the image to be displayed as the icon for this window.  | 
		
| 19 | 
				void setMaximizedBounds(Rectangle bounds)  Sets the maximized bounds for this frame.  | 
		
| 20 | 
				void setMenuBar(MenuBar mb)  Sets the menu bar for this frame to the specified menu bar.  | 
		
| 21 | 
				void setResizable(boolean resizable)  Sets whether this frame is resizable by the user.  | 
		
| 22 | 
				void setState(int state)  Sets the state of this frame (obsolete).  | 
		
| 23 | 
				void setTitle(String title)  Sets the title for this frame to the specified string.  | 
		
| 24 | 
				void setUndecorated(boolean undecorated)  Disables or enables decorations for this frame.  | 
		
继承的方法
这个类继承的方法从以下类:
- 
		
java.awt.Window
 - 
		
java.awt.Container
 - 
		
java.awt.Component
 - 
		
java.lang.Object
 
Frame 实例
选择使用任何编辑器创建以下java程序 D:/ > AWT > com > zaixian > gui >
AwtContainerDemopackage com.zaixian.gui; import java.awt.*; import java.awt.event.*; public class AwtContainerDemo { private Frame mainFrame; private Label headerLabel; private Label statusLabel; private Panel controlPanel; private Label msglabel; public AwtContainerDemo(){ prepareGUI(); } public static void main(String[] args){ AwtContainerDemo awtContainerDemo = new AwtContainerDemo(); awtContainerDemo.showFrameDemo(); } private void prepareGUI(){ mainFrame = new Frame("Java AWT Examples"); mainFrame.setSize(400,400); mainFrame.setLayout(new GridLayout(3, 1)); mainFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent windowEvent){ System.exit(0); } }); headerLabel = new Label(); headerLabel.setAlignment(Label.CENTER); statusLabel = new Label(); statusLabel.setAlignment(Label.CENTER); statusLabel.setSize(350,100); msglabel = new Label(); msglabel.setAlignment(Label.CENTER); msglabel.setText("Welcome to TutorialsPoint AWT Tutorial."); controlPanel = new Panel(); controlPanel.setLayout(new FlowLayout()); mainFrame.add(headerLabel); mainFrame.add(controlPanel); mainFrame.add(statusLabel); mainFrame.setVisible(true); } private void showFrameDemo(){ headerLabel.setText("Container in action: Frame"); final Frame frame = new Frame(); frame.setSize(300, 300); frame.setLayout(new FlowLayout()); frame.add(msglabel); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent windowEvent){ frame.dispose(); } }); Button okButton = new Button("Open a Frame"); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { statusLabel.setText("A Frame shown to the user."); frame.setVisible(true); } }); controlPanel.add(okButton); mainFrame.setVisible(true); } }
编译程序,使用命令提示符。进入到D:/> AWT,然后键入以下命令。
D:AWT>javac comzaixianguiAwtContainerDemo.java
如果没有错误出现,这意味着编译成功。使用下面的命令来运行程序。
D:AWT>java com.zaixian.gui.AwtContainerDemo
验证下面的输出
