JFrame的show()方法 问题

uling uling 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
在练习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()方法,为什么?
应该怎样修改呢?
...全文
评论 4
收藏 已收藏
分享
返回顶部
uling
Java SE 62,621 成员 307,251 内容