个性化阅读
专注于IT技术分析

Java JFrame

点击下载

javax.swing.JFrame类是一种继承了java.awt.Frame类的容器。 JFrame的工作原理类似于主窗口, 在其中添加了标签, 按钮, 文本字段等组件以创建GUI。

与Frame不同, JFrame可以选择使用setDefaultCloseOperation(int)方法来隐藏或关闭窗口。

嵌套类

修饰符和类型 描述
protected class JFrame.AccessibleJFrame 此类实现对JFrame类的可访问性支持。

领域

修饰符和类型 领域 描述
受保护的AccessibleContext accessibleContext 可访问的上下文属性。
static int EXIT_ON_CLOSE 退出应用程序默认窗口关闭操作。
protected JRootPane rootPane 管理此框架的contentPane和可选menuBar以及glassPane的JRootPane实例。
protected boolean rootPaneCheckingEnabled 如果为true, 则对add和setLayout的调用将转发到contentPane。

建设者

建设者 描述
JFrame() 它构造了一个最初不可见的新框架。
JFrame(GraphicsConfiguration gc) 它在屏幕设备的指定GraphicsConfiguration和空白标题中创建一个Frame。
JFrame(String title) 它使用指定的标题创建一个新的, 最初不可见的Frame。
JFrame(String title, GraphicsConfiguration gc) 它使用屏幕设备的指定标题和指定GraphicsConfiguration创建一个JFrame。

有用的方法

修饰符和类型 方法 描述
受保护的空白 addImpl(Component comp, Object constraints, int index) 添加指定的子组件。
protected JRootPane createRootPane() 由构造方法调用以创建默认的rootPane。
受保护的空白 frameInit() 由构造函数调用以正确初始化JFrame。
void setContentPane(Containe contentPane) 设置contentPane属性
静态空隙 setDefaultLookAndFeelDecorated(boolean defaultLookAndFeelDecorated) 提供有关新创建的JFrame是否应具有当前外观提供的其Window装饰(例如边框, 关闭窗口的小部件, 标题…)的提示。
void setIconImage(Image image) 它将图像设置为该窗口的图标。
void setJMenuBar(JMenuBar menubar) 它为此框架设置菜单栏。
void setLayeredPane(JLayeredPane layeredPane) 它设置了layeredPane属性。
JRootPane getRootPane() 它返回此框架的rootPane对象。
TransferHandler getTransferHandler() 它获取transferHandler属性。

JFrame示例

import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.Jpanel;
public class JFrameExample {
	public static void main(String s[]) {
		JFrame frame = new JFrame("JFrame Example");
		JPanel panel = new JPanel();
		panel.setLayout(new FlowLayout());
		JLabel label = new JLabel("JFrame By Example");
		JButton button = new JButton();
		button.setText("Button");
		panel.add(label);
		panel.add(button);
		frame.add(panel);
		frame.setSize(200, 300);
		frame.setLocationRelativeTo(null);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}
}

输出量

Java Jframe
赞(0)
未经允许不得转载:srcmini » Java JFrame

评论 抢沙发

评论前必须登录!