Topic: 关于事件的问题 |
Print this page |
1.关于事件的问题 | Copy to clipboard |
Posted by: hulizhong Posted on: 2005-12-21 17:43 程序1: package brower; .............. public class Frame1 extends JFrame{ .................... public void Frame1 (){ ............ JButton jButton9 = new JButton(); jButton9.addMouseListener(new MouseAdapter(){//单击jButton9时,出现history_1窗口 public void mouseReleased(MouseEvent e) { history history_1=new history (); //类history在程序2中定义 }}); (JPanel) getContentPane().add( jButton9 ) ........... }//end Frame1 ......................................... } 程序2: package brower; .............. public class history extends JFrame{ JButton Button1,Button2; contentPane = (JPanel) getContentPane(); .......... public void JFrame(){ Button1=new JButton("删除1"); Button2=new JButton("删除2"); contentPane.add(Button1); contentPane.add(Button2); Button1.addMouseListener(new MouseAdapter(){ public void keyPressed(KeyEvent e){ JFrame frmae=new JFrame(); frmae.setVisible(true); ............................... }}//end MouseListener setVisible(true); }//end JFrame() .......... } 运行程序1,这时会出现一个 Frame1 类型的窗口(窗口里一个jButton9按钮).单击jButton9,会出来一个history类型的窗口(history窗口上有两个按钮:Button1,Button2),我又单击history窗口上的Button1,按理说这时Button1按钮产生了MouseListener类型的事件,它应该调用public void keyPressed()函数,产生一个frmae窗口啊.可是frmae窗口并出现.请问问题出在哪了? |
2.Re:关于事件的问题 [Re: hulizhong] | Copy to clipboard |
Posted by: bagpipe117 Posted on: 2005-12-23 11:53 只可以使用一个JFrame,所以Frame1中不会再出现另外一个frame了 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |