JFrame的show()方法 问题

uling 2010-11-17 03:55:18
在练习Swing书上的代码 代码如下

package Swing2;

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

public class EventDemo1 implements ActionListener,WindowListener {

public EventDemo1()
{
JFrame f=new JFrame("EventDemo1");
Container contentPane=f.getContentPane();
JButton b=new JButton("L can speak!");
b.addActionListener(this);
contentPane.add(b);
f.pack();
f.show(); //这里有一处警告!!!
f.addWindowListener(this);
}

public void actionPerformed(ActionEvent e)
{
Toolkit.getDefaultToolkit().beep();
}
public void windowIconified(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowOpened(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowClosing(WindowEvent e){
System.exit(0);
}

public static void main(String arg[])
{
new EventDemo1();
}

}


代码的功能是 按钮可以发出哔的声音 但是没有
有一个警告 The method show() from the type Window is deprecated

不大清楚是什么意思
去手册上 在JFrame类里没有找到show()方法,为什么?
应该怎样修改呢?
...全文
391 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
youfeng445 2010-11-17
  • 打赏
  • 举报
回复
楼上正解
fdhsfdsjh 2010-11-17
  • 打赏
  • 举报
回复
对,用上面他们说的setVisible()方法
sunyiz 2010-11-17
  • 打赏
  • 举报
回复
过时的方法
API文档中有说明
该方法已经被setVisible(true);所代替
houjin_cn 2010-11-17
  • 打赏
  • 举报
回复
show() 方法过时了, 建议不要用; 使用 setVisible(true)代替

62,634

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧