java swing的一个小问题

用swing里的JFrame写了个窗口谁能告诉我怎么在点按钮后弹出一个新的窗口??代码:importjava.awt.*;importjava.awt.event.*;i... 用swing里的JFrame写了个窗口 谁能告诉我怎么在点按钮后弹出一个新的窗口??
代码:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;
public class JFrameDemo extends JFrame
{
Container ct;
JButton jButton1=new JButton();
JButton jButton2=new JButton();
JButton jButton3=new JButton();
JButton jButton4=new JButton();
JButton jButton5=new JButton();
public JFrameDemo(){
jbInit();
}
private void jbInit() {
ct=getContentPane(); //得到内容面板添加组件
this.setSize(new Dimension(200,200)); //设定窗口的宽度为200,高度为100
this.setTitle("Fram Title"); //设定窗口的标题
jButton1.setText("connect");
jButton2.setText("connect1");
jButton3.setText("connect2");
jButton4.setText("connect3");
jButton5.setText("connect4"); //设定按钮的标签
Icon ic=new ImageIcon("local.gif");
jButton1.setIcon(ic);
//jButton1.setBorder(BorderFactory.createLineBorder(Color.red));
ct.add(jButton1,"Center");
ct.add(jButton2,"West");
ct.add(jButton3,"East"); //方位控制
ct.add(jButton4,"South");
ct.add(jButton5,"North");//将按钮加入内容面板
this.setVisible(true); //显示窗口
}
public static void main(String []args) throws ClassNotFoundException,
InstantiationException, IllegalAccessException,
UnsupportedLookAndFeelException
{
//打印默认风格
System.out.println("default"+UIManager.getLookAndFeel().getName());
LookAndFeelInfo[] lAndF=UIManager.getInstalledLookAndFeels();
//遍历L&F风格种类
for(int j=0;j<lAndF.length;j++)
System.out.println("feel is "+lAndF[j].getClassName());
//设置窗口风格
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
//UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
JFrameDemo jf=new JFrameDemo();
jf.addWindowListener(new WindowAdapter(){//匿名类用于注册监听者
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}

求高手呀!!!!
图在下面:
展开
 我来答
atem26
2011-01-11
知道答主
回答量:5
采纳率:0%
帮助的人:0
展开全部
弹出什么窗口啊,对话框? 中间按钮添加了事件。
package tree2;
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;
public class JFrameDemo extends JFrame implements ActionListener
{
Container ct;
JButton jButton1=new JButton();
JButton jButton2=new JButton();
JButton jButton3=new JButton();
JButton jButton4=new JButton();
JButton jButton5=new JButton();
public JFrameDemo(){
jbInit();
}
private void jbInit() {
ct=getContentPane(); //得到内容面板添加组件
this.setSize(new Dimension(200,200)); //设定窗口的宽度为200,高度为100
this.setTitle("Fram Title"); //设定窗口的标题
jButton1.setText("connect");
jButton2.setText("connect1");
jButton3.setText("connect2");
jButton4.setText("connect3");
jButton5.setText("connect4"); //设定按钮的标签
Icon ic=new ImageIcon("local.gif");
jButton1.addActionListener(this);
jButton1.setIcon(ic);
//jButton1.setBorder(BorderFactory.createLineBorder(Color.red));
ct.add(jButton1,"Center");
ct.add(jButton2,"West");
ct.add(jButton3,"East"); //方位控制
ct.add(jButton4,"South");
ct.add(jButton5,"North");//将按钮加入内容面板
this.setVisible(true); //显示窗口
}
public static void main(String []args) throws ClassNotFoundException,
InstantiationException, IllegalAccessException,
UnsupportedLookAndFeelException
{
//打印默认风格
System.out.println("default"+UIManager.getLookAndFeel().getName());
LookAndFeelInfo[] lAndF=UIManager.getInstalledLookAndFeels();
//遍历L&F风格种类
for(int j=0;j<lAndF.length;j++)
System.out.println("feel is "+lAndF[j].getClassName());
//设置窗口风格
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
//UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
JFrameDemo jf=new JFrameDemo();
jf.addWindowListener(new WindowAdapter(){//匿名类用于注册监听者
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String name = JOptionPane.showInputDialog("随便写:");
if(name != null){
System.out.println("是不:" + name);
}
}
}
伏松桖0k
2011-01-11 · TA获得超过1826个赞
知道小有建树答主
回答量:1410
采纳率:100%
帮助的人:726万
展开全部
jFileChooser1.setVisible(false);你可以在全局的时候把你需要弹出的窗口用这个方法隐藏了,然后在你需要按的弹出的那个按钮上设置单击事件里写上这句jFileChooser1.setVisible(true);把前面的改成你需要弹出的窗口就行了,至于大小什么的自己弄吧,
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式