/******just a demo*****************/public class MyFrame extends JFrame implements ActionListener{/*********** other codes */ public MyFrame(){ JMenuItem item=new JMenuItem("跳转"); item.addActionListener(this); } public void actionPerformed(ActionEvent e) this.dispose();// 关闭MyFrame new AnotherFrame();//打开AnotherFrame }public class AnotherFrame extends JFrame{ /****************/ } 没问题了吧?
用listener可以嗎
點擊了以后執行new一個新窗口 和 隱藏或關閉當前窗口的操作?
other codes
*/
public MyFrame(){
JMenuItem item=new JMenuItem("跳转");
item.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
this.dispose();// 关闭MyFrame
new AnotherFrame();//打开AnotherFrame
}public class AnotherFrame extends JFrame{
/****************/
}
没问题了吧?
JTextField field1=new JTextField(12);
JButton button1=new JButton("confirm");
怎么写一个监听器
当按下button1按钮时在另一个地方显示field1内用户输入的内容,并将field1的内容存入一个String中以便后面程序调用!
急!!!!!!!!!!!!!!!!!!!!!!!!!!1
JTextField field1=new JTextField(12);
JButton button1=new JButton("confirm");
在frame窗口中添加上面两个组件
现在在field1中输入内容,当按下button1键时输出field1中的内容
怎么添加这个事件了?就没有人知道了嗎
首先用声明一个String的成员变量,在JTextField输入文本后,保存至这个字符串
if(e.getSource()==button1) {
JOptionPane.showMessageDialog(this,string);}
然后在按下button1按钮,时间处理怎么得到的是空值啊!