&&国之画&&&&&&
&& &&&&&&&&&&&&&&&&&&
鲁ICP备号-4
打开技术之扣,分享程序人生!中国Java开发网 - 如何给JInternalFrame类的窗口添加关闭事件?
Topic: 如何给JInternalFrame类的窗口添加关闭事件?
1.如何给JInternalFrame类的窗口添加关闭事件?
Posted by: shsen
Posted on:
我有一个类a,继承自JInternalFrame又有另一个类b,继承自a现在要在b里添加关闭事件,执行一些操作,如把界面上文本框的内容保存到数据库,请问如何实现?
2.Re:如何给JInternalFrame类的窗口添加关闭事件?
[Re: shsen]
Posted by: jackycct
Posted on:
You can add an addInternalFrameAdapter and extends this functionsinternalFrameClosing(InternalFrameEvent e)
3.Re:如何给JInternalFrame类的窗口添加关闭事件?
[Re: shsen]
Posted by: shsen
Posted on:
不太清楚怎么写啊,看看我的代码:public class DealInternalFrame extends JInternalFrame {&&&&/**&& * 构造函数&& * @param aTitle 窗口标题&& */&&public DealInternalFrame (String aTitle){&&&&&&&&&&&&super(aTitle,&&&&&&true,
// resizable&&&&&&true,
// closable&&&&&&true,
// maximizable&&&&&&true); // iconifiable&&}&&&&/**&& * 构造函数&& * @param aTitle 窗口标题&& * @param aId 窗口的唯一标识&& */&&public DealInternalFrame (String aTitle, int aId){&&&&this(aTitle);&&&&setId (aId);&&}&&&&public int getId (){&&&&&&}&&public void setId (int aId){&&&&id = aId;&&}&&private int id = 0; //窗口的唯一标识}public class LCApplyD1 extends DealInternalFrame{&&JScrollPane&&jScrollP&&static PaneApply1&&pane =&&public LCApplyD1()&&{&&&&//super("基本数据(1)",11);&&&&super("基本数据",11);&&&&setSize(750,550);&&&&JComponent c = (JComponent) this.getContentPane();&&&&c.setLayout(new BorderLayout());&&&&jScrollPane = new JScrollPane();&&&&pane = new PaneApply1();&&&&jScrollPane.getViewport().add(pane);&&&&c.add(jScrollPane,BorderLayout.CENTER);//如何在这里添加关闭事件处理&&}}
4.Re:如何给JInternalFrame类的窗口添加关闭事件?
[Re: shsen]
Posted by: yakuu
Posted on:
in your LCApplyD1 constructor:addInternalFrameListener(new InternalFrameAdapter() {
public void internalFrameClosing(InternalFrameEvent e) {
// add your close code here.
public void internalFrameClosed(InternalFrameEvent e) {
// after you close it.
}});btw: please browse the java source code for more detail.
Powered by & Version Jute 1.5.6 Ent
Copyright &
Cjsdn Team. All Righits Reserved.
客服电话&&&&&客服信箱&&&&&客服QQ&714923Java中如何关闭Frame窗口
Java中如何关闭Frame窗口
Java中如何关闭Frame窗口?
分三种情况来说明:
&& 1. 用户类继承自Frame;
&& 2. Frame对象作为用户类的数据成员;
&& 3. 用户类继承自WindowAdapter.
1. 用户类继承自Frame:
代码如下:
import java.awt.*;
import java.awt.event.*;
&public& class MyFrame
extends& Frame
&public void display()
& this.setTitle("MyFrame");
& this.setSize(480,200);
& this.setLocation (200,400);
& this.setBackground (Color.lightGray);
& this.setVisible(true);
&public static void main (String args[])
& MyFrame f = new MyFrame();
& f.addWindowListener(new
WindowAdapter()& //为了关闭窗口
&& public void
windowClosing(WindowEvent e)
System.exit(0);
& f.display();
2. Frame对象作为用户类的数据成员:
代码如下:
import java.awt.*;
import java.awt.event.*;
public&& class MyFrame2
Frame f = new Frame();
MyFrame2()
f.addWindowListener(new WindowAdapter()&
//为了关闭窗口
public void windowClosing(WindowEvent e)
&&&&&&&&&&
System.exit(0);
&public void display()
& f.setTitle("MyFrame");
& f.setSize(480,200);
& f.setLocation (200,400);
& f.setBackground (Color.lightGray);
& f.setVisible(true);
&public static void main (String args[])
& new MyFrame2().display();
3. 用户类继承自WindowAdapter,而窗口对象Frame作为用户类的数据成员.
代码如下:
import java.awt.*;
import java.awt.event.*;
public&& class MyFrame3
extends WindowAdapter
&Frame f = new Frame();
&public void display()
& f.setTitle("MyFrame");
& f.setSize(480,200);
& f.setLocation (200,400);
& f.setBackground (Color.lightGray);
& f.addWindowListener (this);&
//窗体f--注册窗体事件监听器
& f.setVisible(true);
&public void windowClosing(WindowEvent e)
& System.exit(0);
&public static void main (String args[])
& new MyFrame3().display();
发表评论:
TA的最新馆藏JAVA关于窗体JFrame的关闭事件_百度知道
JAVA关于窗体JFrame的关闭事件
这里有个问题的是,有看到这样一段代码F.EXIT_ON_CLOSE而不是F:这个常量是定义在JFrame这个类里面的,这个EXIT_ON_CLOSE;其中这个F就是JFrame F=new JFrame()。这种系统自带的都不需要定义是吗.setDefaultCloseOperation(JFrame:新手学JAVA我之前有提问了一个问题.EXIT_ON_CLOSE).EXIT_ON_CLOSE现在的问题是:我不是已经JFrame F=new JFrame()了吗,这个是一个常量,所以你使用的时候才会使用JFrame,我并没有在方法或类成员里指定这个?(VB中都需要再定义常量及常量值) 如下是别人的回答,为什么是JFrame?说明F已经指向了一个对象
我有更好的答案
jLabel_user_name.setBounds(199;注册&*&{
ImageIcon&CODE ,&is&ANY&new&evt)&{
NewJFrame .void .setBounds(199, ,&import , .
jPasswordFnew&display&{
try .awt.setTitle(&{
super();mouseClicked(MouseEvent ,&
jButton_23);Jigloo*&
jTextField_user_({
if(jComboBox1;
new .DEFAULT_OPTION);OR&new&jPasswordField.JButton.ActionECANNOT ,&free&
getContentPane();, ,0;
jLabel_user_name&for&{
if(jComboBox1;catch&
} }}//设置setDefaultCloseOperation(WindowCLICENSE&JButton();COMMERCIAL .DefaultComboBoxModel//设置关闭后直接退出setDefaultCloseOperation(WindowC
jButton_regMouseClicked(evt);
initGUI();{
public&import&
getContentPane();MACHINE.23),0;extends&;CloudGarden'NewJFrame ,&68;company&JLabel();189;235;
jTextField_user_name&JLabel®ister=new .setBounds(0;actionPerformed(ActionEvent&code&JLabel&*& private&of&java.setFont(new&);import&
jLabel_user_import , .setSize(549;Jigloo .setFont(new&&business&ImageIcon(".0版".JTextFstatic&叶根友毛笔行书2;import&
jLabel_School_here
e;*/ /** * .getSelectedIndex()==0)
jLabel_user_new .&handling&java.setText(".setBounds(152;
jButton_); private&=&run()&being&GUI&JFrame */ public&{&{
public&you*&whatever)&Runnable()&JComboBox();logo=new&manager_statue=0,&your .setText(".add(jLabel_School_logo).add(jPasswordField);is&JOptionPimport .add(jLabel_title);HAS& private&evt) .setBounds(199;68;{ private&these ,12));JButton .setIcon(logo).ImageIimport .add(jLabel_passwd).Font(&&);jLabel_of&
getContentPane(),0;If&implies&334);void&jLabel_user_jLabel_Login.JFrame&PURCHASED&e)&or&for .printStackTrace(); private&0;教室管理系统登录&import ,&DefaultComboBoxModel(
jComboBox1;= .DISPOSE_ON_CLOSE);{
setDefaultCloseOperation(WindowConstants, , .or&edited .JComboBox.;学号;
pack();&&to .add(jButton_reg);COMMERCIAL&error .awt,12));;NewJFrame();javax. private&ActionListener()&\u6ce8\u518c&
;31), ,12)).JPasswordF= .void&license&import&java,12));=&{
public ,&
getContentPane();visit&ImageIcon(&23),&JIGLOO&{
jComboBox1ActionPerformed(evt);main(String[]&管理员登录&using&new !&
 .setBounds(199; }
public&using .JPasswordField&
jComboBox1.Font(&SO .swing.invokeLater(new .SwingUjTextField_user_
&NOT&).showMessageDialog(NewJF});84);
}&This&Use&licensing ,*&import&import&LEGALLY , .".addActionListener(new&OR&CORPORATE&管理员帐号不提供注册;for .
jLabel_School_
getContentPane();84);any .add(jButton_login);generated .jpg&jComboBox1ActionPerformed(ActionEvent&{
SwingUreg();JButton().Font(&90.ActionL=& .setFont(new& private&151.0版&叶根友毛笔行书2;String[] .setText(".
getContentPane();each&
jLabel_135;commercially&inst&this&Jigloo, ,&new&new .swing,&/***&&img/235.setLocationRelativeTo(this);a&=&jButton_regMouseClicked(MouseEvent&;import .class&447;51;&then ,&
}).setTitle(&185, ,&evt)& private&used&title=new&
jLabel_user_).jpg",&purchase&THIS&package&);main&JComboBox .Font(&MouseAdapter()&
jPasswordField&
getContentPane();
jButton_void&31);
jComboBox1 .151;code&(Exception&void .swing.*&
jButton_);\u767b\u5f55&
getContentPane();NewJFrame() .setText(&Please&JTextField();86;which :&Ba&void&s&,0; }
private&A , .setText(&
帐号.0版&叶根友毛笔行书2.add(jLabel_user_name);FOR*&THIS .0;
});&USED*&
getContentPane();* .swing,&img/=&Auto-generated .this,你怎么用到你这个F呢;*/
&import&=&
jLabel_title& private .MouseAdapter.setBounds(282.setBounds(155,&=&purpose&JTextField&jLabel_School_JButton .setText(&
this.*&non-commercial*&BEEN&
jLabel_叶根友毛笔行书2;\u5bc6\u7801\uff1a&);
jLabel_School_logo ,&jButton_SWT/Swing .DISPOSE_ON_CLOSE).JRadioButton.net.*/public , ,&
jLabel_passwd.
jLabel_passwd&
inst.setFont(new&JLabel&131;
getContentPane();
jButton_student_statue=0;import&JLabel();acceptance .getSelectedIndex()==1)
JOptionPane, .setLocationRelativeTo(null).addMouseListener(new .0版&
ComboBoxModel& private&
ImageIcon ,&new&JLabel();
jButton_reg&Jigloo&int&在另一个方法.swing.PURPOSE.setBounds(86;
register.MouseEvent.setModel(jComboBox1Model).setLayout(null);import&23);void&JPasswordField();import .add(jComboBox1);args)&was&JLabel&=&
 .&\u5b66\u53f7\uff1a".JOptionPjButton_//add&new&developer&new&23).WindowConstants.setIcon(title););by&51;
jLabel_user_jComboBox1Model&FOR :&should&学生/老师登录&JLabel();
jLabel_passwd.add(jTextField_user_name);BE&initGUI() ,&int& private&
});import ,&evt) ,&method .setVisible(true).JL
jButton_login .URL;
jComboBox1.DISPOSE_ON_CLOSE);).ComboBoxModel.setVisible(true);jComboBox1.event
其他类似问题
为您推荐:
jframe的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁}