如果新建一个JFrame frametestone 在里面新建一个JButton button
然后新建一个JFrame frametesttwo 并添加按钮事件,怎样点击button按钮出现frametesttwo ,关闭frametestone?菜鸟请指教!
然后新建一个JFrame frametesttwo 并添加按钮事件,怎样点击button按钮出现frametesttwo ,关闭frametestone?菜鸟请指教!
解决方案 »
- 关于static的问题
- 转义字符的使用,怎么没效果?
- 高分求解数据库难题,高手来接受挑战
- JFrame&JPanel
- 我的tomcat服务嚣不能关闭了(用shutdown命令)提示说duplicate name in mainfest: classes-paht!!
- 关于继承类方面的求助
- *** vj 和 borland j++ builder 哪个好?***
- 如何正确安装java plug-in?
- JFreeChart生成折线图,如何实现X轴显示自定义值?
- 各位大佬帮忙解答一下萌新的疑问,感激不尽!!
- foreach循环中不用break,如何跳出循环
- javaMail+JEditorPane 显示html邮件(带图片时)遇问题
public void actionPerformed(ActionEvent e) {
//System.exit(1);
//System.out.print("yeah");
JFrame jf=new JFrame();
jf.setVisible(true);
}
});
import java.awt.event.ActionListener;import javax.swing.*;public class TT extends JFrame implements ActionListener{ /**
* @param args
*/
JButton b;
public TT()
{
b = new JButton("button ");
b.addActionListener(this);
this.add(b);
this.setSize(300,200);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new TT();
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
this.dispose();
JFrame jf = new JFrame("My Frame");
jf.setSize(300,200);
jf.setLocation(200, 300);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}}
请问一下如果添加两个按钮? 再就是如果我想用三个按钮建立三个ActionEvent类分别定义对象怎么点击按钮的时候打开下一个窗口,关闭this窗口呢?
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.*;public class TT extends JFrame implements ActionListener{ /**
* @param args
*/
JButton a,b,c;
public TT()
{ a = new JButton("buttona ");
b = new JButton("buttonb ");
c = new JButton("buttonc ");
a.addActionListener(this);
b.addActionListener(this);
c.addActionListener(this);
this.add(a);
this.add(b);
this.add(c);
this.setLayout(new GridLayout(1, 3));
this.setSize(300,200);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new TT();
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
this.dispose();
if (arg0.getSource() == a )
{JFrame jfA = new JFrame("My FrameA");
jfA.setSize(300,200);
jfA.setLocation(200, 300);
jfA.setVisible(true);
jfA.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}
else if (arg0.getSource() == b){
JFrame jfB = new JFrame("My FrameB");
jfB.setSize(300,200);
jfB.setLocation(200, 300);
jfB.setVisible(true);
jfB.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}else if (arg0.getSource() == c) {
JFrame jfC = new JFrame("My FrameB");
jfC.setSize(300,200);
jfC.setLocation(200, 300);
jfC.setVisible(true);
jfC.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}}