鍍金池/ 教程/ Java/ Swing JFrame類和實例
Swing JRadioButton
Swing Layout布局
Swing JTextField
Swing JLabel
Swing開發(fā)環(huán)境安裝
Swing JComponent類
SWING ActionEvent事件類
Swing JScrollBar
Swing教程首頁
Swing JFileChooser
SWING ContainerEvent事件處理類
Swing AdjustmentListener接口
Swing WindowAdapter類
SWING ComponentListener接口
Swing JMenuBar類
Swing JPanel類及實例
Swing
SWING AdjustmentEvent事件處理
Swing JWindow類及實例
Swing介紹
Swing MouseMotionAdapter類
SWING WindowEvent事件類
Swing ItemListener接口
SWING MouseEvent事件類
Swing JMenu類
SWING KeyEvent事件類
Swing MouseMotionListener接口
Swing JProgressBar
SWING AWTEvent事件類
Swing JRadioButtonMenuItem類及例子
Swing KeyAdapter類
SWING ActionListener接口
Swing LayoutManager接口
SWING MouseMotionEvent事件處理
Swing Component類
Swing Container類
Swing CardLayout布局
Swing MouseAdapter類
Swing JSlider
Swing KeyListener接口
Swing FocusAdapter類
Swing JColorChooser
Swing ImageIcon
Swing JComboBox
Swing GroupLayout布局類
Swing JOptionPane
Swing GridBagLayout布局類
Swing JMenuItem類
Swing MouseListener Interface
Swing事件適配器
SWING ComponentEvent處理類
SWING PaintEvent事件類
Swing FlowLayout布局類
SWING Event事件類
Swing FocusListener接口
Swing控件
Swing JButton
Swing JCheckBox
Swing SpringLayout布局類
Swing容器
Swing事件處理
Swing事件監(jiān)聽器
Swing Menu菜單類
Swing JList
Swing ContainerListener接口
Swing LayoutManager2接口
Swing JFrame類和實例
Swing JTextArea
SWING InputEvent事件類
Swing BorderLayout布局
Swing WindowListener接口
Swing JCheckboxMenuItem類及例子
Swing JSpinner
Swing GridLayout布局類
Swing JPopupMenu類及實例

Swing JFrame類和實例

JFrame類是一個擴展版java.awt.Frame添加JFC/Swing組件架構(gòu)的支持。

類聲明

以下是聲明 javax.swing.JFrame類:

public class JFrame
   extends Frame
      implements WindowConstants, Accessible
         , RootPaneContainer

字段域

以下是java.awt.Component類的字段:

  • protected AccessibleContext accessibleContext --訪問上下文屬性。

  • static int EXIT_ON_CLOSE --退出應(yīng)用程序默認的窗口關(guān)閉操作。

  • protected JRootPane rootPane --JRootPane實例管理的contentPane和可選的菜單欄,以及該幀的玻璃面板。

  • protected boolean rootPaneCheckingEnabled -- 如果為true 則調(diào)用添加的setLayout將被轉(zhuǎn)發(fā)到contentPane。

類構(gòu)造函數(shù)

S.N. 構(gòu)造函數(shù) & 描述
1 JFrame()
Constructs a new frame that is initially invisible.
2 JFrame(GraphicsConfiguration gc) 
Creates a Frame in the specified GraphicsConfiguration of a screen device and a blank title.
3 JFrame(String title) 
Creates a new, initially invisible Frame with the specified title.
4 JFrame(String title, GraphicsConfiguration gc) 
Creates a JFrame with the specified title and the specified GraphicsConfiguration of a screen device.

類方法

S.N. 方法 & 描述
1 protected void addImpl(Component comp, Object constraints, int index) 
Adds the specified child Component.
2 protected JRootPane createRootPane() 
Called by the constructor methods to create the default rootPane.
3 protected void frameInit() 
Called by the constructors to init the JFrame properly.
4 AccessibleContext getAccessibleContext() 
Gets the AccessibleContext associated with this JFrame.
5 Container getContentPane() 
Returns the contentPane object for this frame.
6 int getDefaultCloseOperation() 
Returns the operation that occurs when the user initiates a "close" on this frame.
7 Component getGlassPane() 
Returns the glassPane object for this frame.
8 Graphics getGraphics() 
Creates a graphics context for this component.
9 JMenuBar getJMenuBar() 
Returns the menubar set on this frame.
10 JLayeredPane getLayeredPane() 
Returns the layeredPane object for this frame.
11 JRootPane getRootPane() 
Returns the rootPane object for this frame.
12 TransferHandler getTransferHandler() 
Gets the transferHandler property.
13 static boolean isDefaultLookAndFeelDecorated() 
Returns true if newly created JFrames should have their Window decorations provided by the current look and feel.
14 protected boolean isRootPaneCheckingEnabled() 
Returns whether calls to add and setLayout are forwarded to the contentPane.
15 protected String paramString() 
Returns a string representation of this JFrame.
16 protected void processWindowEvent(WindowEvent e) 
Processes window events occurring on this component.
17 void remove(Component comp) 
Removes the specified component from the container.
18 void repaint(long time, int x, int y, int width, int height) 
Repaints the specified rectangle of this component within time milliseconds.
19 void setContentPane(Container contentPane) 
Sets the contentPane property.
20 void setDefaultCloseOperation(int operation) 
Sets the operation that will happen by default when the user initiates a "close" on this frame.
21 static void setDefaultLookAndFeelDecorated(boolean defaultLookAndFeelDecorated)
Provides a hint as to whether or not newly created JFrames should have their Window decorations (such as borders, widgets to close the window, title...) provided by the current look and feel.
22 void setGlassPane(Component glassPane) 
Sets the glassPane property.
23 void setIconImage(Image image) 
Sets the image to be displayed as the icon for this window.
24 void setJMenuBar(JMenuBar menubar) 
Sets the menubar for this frame.
25 void setLayeredPane(JLayeredPane layeredPane) 
Sets the layeredPane property.
26 void setLayout(LayoutManager manager) 
Sets the LayoutManager.
27 protected void setRootPane(JRootPane root) 
Sets the rootPane property.
28 protected void setRootPaneCheckingEnabled(boolean enabled) 
Sets whether calls to add and setLayout are forwarded to the contentPane.
29 void setTransferHandler(TransferHandler newHandler) 
Sets the transferHandler property, which is a mechanism to support transfer of data into this component.
30 void update(Graphics g) 
Just calls paint(g).

方法繼承

這個類從以下類繼承的方法:

  • java.awt.Frame

  • java.awt.Window

  • java.awt.Container

  • java.awt.Component

  • java.lang.Object

JFrame 例子

選擇使用任何編輯器創(chuàng)建以下java程序在 D:/ > SWING > com > yiibai > gui >

SwingContainerDemo.java
package com.yiibai.gui;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class SwingContainerDemo {
   private JFrame mainFrame;
   private JLabel headerLabel;
   private JLabel statusLabel;
   private JPanel controlPanel;
   private JLabel msglabel;

   public SwingContainerDemo(){
      prepareGUI();
   }

   public static void main(String[] args){
      SwingContainerDemo  swingContainerDemo = new SwingContainerDemo();  
      swingContainerDemo.showJFrameDemo();
   }

   private void prepareGUI(){
      mainFrame = new JFrame("Java Swing Examples");
      mainFrame.setSize(400,400);
      mainFrame.setLayout(new GridLayout(3, 1));
      mainFrame.