Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java GUI 设计  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:如何在通过一个button打开一个窗口的同时关闭button所在的窗口 [Re:yezongbo]
yezongbo





发贴: 8
积分: 0
于 2005-09-24 15:13 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
button的界面

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class button extends WindowAdapter implements ActionListener
{
JButton b1 = null;
JButton b2 = null;
JFrame f;
public button()
{
JFrame f = new JFrame("EventDemo6");
Container contentPane = f.getContentPane();
contentPane.setLayout(new GridLayout(1,2));
b1 = new JButton("按我有声音喔");
b2 = new JButton("按我可开新窗口");
b1.addActionListener(this);
b2.addActionListener(this);
contentPane.add(b1);
contentPane.add(b2);
f.pack();
f.show();
f.addWindowListener(this);
}

public void actionPerformed(ActionEvent e)
{
if((e.getActionCommand()).equals("按我有声音喔")) //getActionCommand()方法会返回按钮上的文字字符串。
Toolkit.getDefaultToolkit().beep();
if((e.getActionCommand()).equals("按我可开新窗口"))
{
file newF = new file();
newF.setSize(200,200);
newF.setVisible(true);

f.setVisible(false);

}
}

public void windowClosing(WindowEvent e)
{
System.exit(0);
}

public static void main(String args[])
{
new button();
}
}

新窗口的界面import java.awt.event.*;
import java.awt.*;
import javax.swing.*;

public class file extends JFrame{
  JLabel label ;
  
  public file(){
    
    Container container=getContentPane();
    JLabel label =new JLabel("label");
    container.add(label);
    }
  
  
  public static void main(String [] args)
  {file c=new file();
  c.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
  }




话题树型展开
人气 标题 作者 字数 发贴时间
6890 如何在通过一个button打开一个窗口的同时关闭button所在的窗口 yezongbo 35 2005-09-23 20:45
5765 Re:如何在通过一个button打开一个窗口的同时关闭button所在的窗口 zcjl 32 2005-09-23 23:37
5516 Re:如何在通过一个button打开一个窗口的同时关闭button所在的窗口 yezongbo 10 2005-09-24 15:12
5793 Re:如何在通过一个button打开一个窗口的同时关闭button所在的窗口 yezongbo 1720 2005-09-24 15:13
5602 Re:如何在通过一个button打开一个窗口的同时关闭button所在的窗口 zcjl 32 2005-09-24 15:56
5581 Re:如何在通过一个button打开一个窗口的同时关闭button所在的窗口 yezongbo 11 2005-09-24 18:05
5627 Re:如何在通过一个button打开一个窗口的同时关闭button所在的窗口 q_yuan 1396 2005-09-26 16:27
5661 Re:如何在通过一个button打开一个窗口的同时关闭button所在的窗口 夏日的亮 16 2005-09-28 23:40

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   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