java jwindow 键盘_Swing JWindow类

JWindow类是一个可以显示但没有标题栏或窗口管理按钮的容器。

类声明

以下是javax.swing.JWindow类的声明 -

public class JWindow

extends Window

implements Accessible, RootPaneContainer

字段

以下是java.awt.Component类的字段 -

protected AccessibleContext accessibleContext - 可访问的上下文属性。

protected JRootPane rootPane - 管理此框架的contentPane和可选menuBar的JRootPane实例。

protected boolean rootPaneCheckingEnabled - 如果为true,则对add和setLayout的调用将转发到contentPane。

类构造函数编号

类构造函数

描述

1

JWindow()

创建一个没有指定所有者的窗口。

2

JWindow(Frame owner)

创建具有指定所有者框架的窗口。

3

JWindow(GraphicsConfiguration gc)

使用屏幕设备的指定GraphicsConfiguration创建一个窗口。

4

JWindow(Window owner)

使用指定的所有者窗口创建一个窗口。

5

JWindow(Window owner, GraphicsConfiguration gc)

使用指定的所有者窗口和屏幕设备的GraphicsConfiguration创建一个窗口。

类方法编号

类方法

描述

1

protected void addImpl(Component comp, Object constraints, int index)

添加指定的子组件。

2

protected JRootPane createRootPane()

由构造函数方法调用以创建默认的rootPane。

3

AccessibleContext getAccessibleContext()

获取与此JWindow关联的AccessibleContext。

4

Container getContentPane()

返回Container,它是此窗口的contentPane。

5

Component getGlassPane()

返回此窗口的glassPane组件。

6

Graphics getGraphics()

为此组件创建图形上下文。

7

JLayeredPane getLayeredPane()

返回此窗口的layeredPane对象。

8

JRootPane getRootPane()

返回此窗口的rootPane对象。

9

TransferHandler getTransferHandler()

获取transferHandler属性。

10

protected boolean isRootPaneCheckingEnabled()

返回对add和setLayout的调用是否转发到contentPane。

11

protected String paramString()

返回此JWindow的字符串表示形式。

12

void remove(Component comp)

从容器中删除指定的组件。

13

void repaint(long time, int x, int y, int width, int height)

在时间毫秒内重新绘制此组件的指定矩形。

14

void setContentPane(Container contentPane)

设置此窗口的contentPane属性。

15

void setGlassPane(Component glassPane)

设置glassPane属性。

16

void setLayeredPane(JLayeredPane layeredPane)

设置layeredPane属性。

17

void setLayout(LayoutManager manager)

设置LayoutManager。

18

protected void setRootPane(JRootPane root)

为此窗口设置新的rootPane对象。

19

protected void setRootPaneCheckingEnabled(boolean enabled)

设置是否将对add和setLayout的调用转发到contentPane。

20

void setTransferHandler(TransferHandler newHandler)

设置transferHandler属性,该属性是一种支持将数据传输到此组件的机制。

21

void update(Graphics g)

调用:paint(g)

22

protected void windowInit()

由构造函数调用以正确初始化JWindow。

方法继承

该类继承以下类中的方法 -

java.awt.Window

java.awt.Container

java.awt.Component

java.lang.Object

JWindow示例

使用编辑器创建以下Java程序:JWindowDemo.java

package com.yiibai.menu;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class JWindowDemo {

private JFrame mainFrame;

private JLabel headerLabel;

private JLabel statusLabel;

private JPanel controlPanel;

private JLabel msglabel;

public JWindowDemo() {

prepareGUI();

}

public static void main(String[] args) {

JWindowDemo swingContainerDemo = new JWindowDemo();

swingContainerDemo.showJWindowDemo();

}

private void prepareGUI() {

mainFrame = new JFrame("Java Swing JWindowDemo(yiibai.com)");

mainFrame.setSize(400, 400);

mainFrame.setLayout(new GridLayout(3, 1));

mainFrame.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent windowEvent) {

System.exit(0);

}

});

headerLabel = new JLabel("", JLabel.CENTER);

statusLabel = new JLabel("", JLabel.CENTER);

statusLabel.setSize(350, 100);

msglabel = new JLabel("欢迎您来到易百教程~", JLabel.CENTER);

controlPanel = new JPanel();

controlPanel.setLayout(new FlowLayout());

mainFrame.add(headerLabel);

mainFrame.add(controlPanel);

mainFrame.add(statusLabel);

mainFrame.setVisible(true);

}

private void showJWindowDemo() {

headerLabel.setText("Container in action: JWindow");

final MessageWindow window = new MessageWindow(mainFrame, "欢迎您来到易百教程/Swing~");

JButton okButton = new JButton("打开一个窗口");

okButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

window.setVisible(true);

statusLabel.setText("A Window shown to the user.");

}

});

controlPanel.add(okButton);

mainFrame.setVisible(true);

}

class MessageWindow extends JWindow {

private String message;

public MessageWindow(JFrame parent, String message) {

super(parent);

this.message = message;

setSize(300, 300);

setLocationRelativeTo(parent);

}

public void paint(Graphics g) {

super.paint(g);

g.drawRect(0, 0, getSize().width - 1, getSize().height - 1);

g.drawString(message, 50, 150);

}

}

}

执行上面示例代码,得到以下结果:

f77d38f4113825a4430e460de444c1fa.png

打开新的窗口如下:

52965da3170619bc1c53456ca0ca806f.png

¥ 我要打赏

纠错/补充

收藏

下一篇:哥,这回真没有了

加QQ群啦,易百教程官方技术学习群

注意:建议每个人选自己的技术方向加群,同一个QQ最多限加 3 个群。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值