import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class peven extends WindowAdapter implements ActionListener {
JButton btn1=null;
JButton btn2=null;
public peven()
{JFrame f=new JFrame("要学会做人");
Container cp=f.getContentPane();
cp.setLayout(new GridLayout(1,2));
btn1=new JButton("按我就有声音呵");
btn2=new JButton("按我就开新世界");
btn1.addActionListener(this);
btn2.addActionListener(this);
cp.add(btn1);
cp.add(btn2);
f.pack();
f.setVisible(true);
f.addWindowListener(this);}public void actionPerformed(ActionEvent e)
{
if (e.getSource()==btn1)
Toolkit.getDefaultToolkit().beep();
if (e.getSource()==btn2)
{
JFrame fnew=new JFrame();
fnew.setSize(400,500);
fnew.setVisible(true);
}}
public void WindowClosing(WindowEvent e)
{
System.exit(0);
}
public static void main(String args[])
{
peven b;
    b = new peven();
}
}
这样就可以了
show是deprecated,使用setVisible吧