JAVA中点击按钮事件弹出子窗口:JInternalFrame的使用
来源:互联网 发布:keil优化等级设置 编辑:程序博客网 时间:2024/05/19 17:09
要求:
1、在父窗口中添加一个按钮
2、点击按钮弹出子窗口
注意:这是JDK1.7版本
在JDK1.7之前,JFrame是不能直接添加子窗口的,要先将JInternalFrame添加到JDesktopPane
中,
再将JDesktopPane
添加到父窗口内,完成这个操作。
(一)建立父类JFrame
package com.java.view;import java.awt.BorderLayout;import java.awt.EventQueue;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.border.EmptyBorder;import javax.swing.JDesktopPane;import javax.swing.JButton;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import javax.swing.JMenuBar;public class Testfrm extends JFrame {/** * Launch the application. */public static void main(String[] args) {EventQueue.invokeLater(new Runnable() {public void run() {try {Testfrm frame = new Testfrm();frame.setVisible(true);} catch (Exception e) {e.printStackTrace();}}});}/** * Create the frame. */public Testfrm() {setTitle("\u7236\u7A97\u53E3");//标题setBounds(400, 300, 800, 600);//父窗口的坐标和大小getContentPane().setLayout(null);//自由布局JButton bt = new JButton("\u6309\u94AE");//按钮的变量名为btbt.setBounds(0, 0, 93, 23);//按钮的位置坐标和大小getContentPane().add(bt);//按钮添加到窗口中bt.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {Testinterfrm testinterfrm=new Testinterfrm();//新建子窗口对象testinterfrm.setVisible(true);//子窗口可见getContentPane().add(testinterfrm);//子窗口添加到父窗口中}});}}(二)建立子类JInternalFrame
package com.java.view;import java.awt.BorderLayout;import java.awt.EventQueue;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.border.EmptyBorder;import javax.swing.JDesktopPane;import javax.swing.JButton;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import javax.swing.JMenuBar;public class Testfrm extends JFrame {/** * Launch the application. */public static void main(String[] args) {EventQueue.invokeLater(new Runnable() {public void run() {try {Testfrm frame = new Testfrm();frame.setVisible(true);} catch (Exception e) {e.printStackTrace();}}});}/** * Create the frame. */public Testfrm() {setTitle("\u7236\u7A97\u53E3");//标题setBounds(400, 300, 800, 600);//父窗口的坐标和大小getContentPane().setLayout(null);//自由布局JButton bt = new JButton("\u6309\u94AE");//按钮的变量名为btbt.setBounds(0, 0, 93, 23);//按钮的位置坐标和大小getContentPane().add(bt);//按钮添加到窗口中bt.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {Testinterfrm testinterfrm=new Testinterfrm();//新建子窗口对象testinterfrm.setVisible(true);//子窗口可见getContentPane().add(testinterfrm);//子窗口添加到父窗口中}});}}运行结果:
0 0
- JAVA中点击按钮事件弹出子窗口:JInternalFrame的使用
- vs mfc 点击父窗口的按钮,弹出子窗口
- VS2010 MFC点击父窗口的按钮,弹出子窗口
- vs mfc 点击父窗口的按钮,弹出子窗口
- detailview按钮列 点击弹出窗口中使用datagrid
- java swing中点击按钮后弹出JFrame窗口,关闭弹出的窗口,程序都关了的解决方案
- JavaScript中点击按钮弹出新的浏览器窗口
- [Java学习]JInternalFrame的使用(窗口与面板)
- 点击按钮弹出包含表单的窗口
- vs2010MFC框架下,点击按钮弹出窗口,在子窗口中输入值,将这个值向主窗口传递
- Swing中JInternalFrame的使用
- Swing中JInternalFrame的使用
- Java点击按钮弹出窗口(两种按钮)
- JInternalFrame的使用(窗口与面板)
- linkbutton点击事件,执行javascript函数,弹出子窗口
- ExtAsp.Net 后台按钮绑定弹出窗口事件,需要点击两次才能弹出窗口
- 弹出窗口中点击按钮不打开新网页设置
- Delphi_Webbrowser中自动点击Alert弹出窗口中的按钮
- Android -- EventBus使用
- h5+MUI移动APP和普通H5之间的区别有哪些?
- 前端学HTTP之网络基础
- tableview不响应Cell点击方法
- ASP.NET ZERO 学习 —— (12) 应用开发Demo之测试应用服务
- JAVA中点击按钮事件弹出子窗口:JInternalFrame的使用
- CSDN博客积分规则和获取积分方法
- Mysql允许远程访问
- 【九度OJ】题目1441:人见人爱 A ^ B 解题报告
- LeetCode14. Longest Common Prefix
- 舒伯的生涯彩虹图
- C语言实现dos界面下的文本颜色变色
- python unittest/pyunit
- 【官方教程】使用Quick-Cocos2d-x搭建一个横版过关游戏(三)