调试时报错
BounceApplet.java 使用或覆盖了已过时的API
了解详细信息,请使用 -Xlint:deprecation 重新编
请问如何解决这问题
谢谢
源代码如下
////////////////////////////////////////////////////////////
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class BounceApplet extends Applet
{ public BounceApplet ()
{ BounceExpress bounce = new BounceExpress();
bounce.setSize(300,200);
bounce.show();}
}
class BounceExpress extends Frame
{ Canvas canvas;
Button blackButton,redButton,closeButton;
public BounceExpress()
{ canvas =new Canvas();
Panel p = new Panel();
blackButton = new Button("Add minor ball of black ");
redButton = new Button ("Add minor ball of red ");
closeButton = new Button ("Close window");
Listener listener = new Listener();
setTitle ("BounceExpress");
canvas.setBackground(Color.lightGray);
add("Center",canvas);
add("South",p);
p.add(blackButton);
p.add(redButton);
p.add(closeButton);
blackButton.addActionListener(listener);
redButton.addActionListener(listener);
closeButton.addActionListener(listener);
this.addWindowListener(new WListener());}
class WListener extends WindowAdapter
{ public void windowClosing(WindowEvent e)
{ dispose();}
}
class Listener implements ActionListener
{ public void actionPerformed(ActionEvent e)
{ if(e.getSource() == blackButton)
{ Ball b = new Ball(canvas,Color.black);
b.setPriority(Thread.NORM_PRIORITY);
b.start();}
else
if(e.getSource() == redButton)
{ Ball b = new Ball(canvas,Color.red);
b.setPriority(Thread.NORM_PRIORITY+2);
b.start();}
else
if (e.getSource() == closeButton)
{ dispose();}
}
}
}
class Ball extends Thread
{ private Canvas box;
private static final int XSIZE =10;
private static final int YSIZE =10;
private int x=0,y=0;
private int dx = 2, dy=2;
private Color color;
public Ball(Canvas _canvas,Color _color)
{ box = _canvas;
color = _color;
this.setDaemon(true);}
public void draw()
{ Graphics g = box.getGraphics();
g.setColor(color);
g.fillOval(x,y,XSIZE,YSIZE);}
public void move()
{ Graphics g = box.getGraphics();
if(g== null) return;
g.setColor(color);
g.setXORMode(box.getBackground());
g.fillOval(x,y,XSIZE,YSIZE);
x+= dx;
y+= dy;
Dimension d= box.getSize();
if (x<0)
{ x=0;dx = -dx;}
if (x+XSIZE>=d.width)
{ x=d.width - XSIZE;dx = -dx;}
if (y<0)
{ y=0;dy = -dy;}
if (y+XSIZE>=d.height)
{ y=d.height - YSIZE;dy = -dy;}
g.fillOval(x,y,XSIZE,YSIZE);
}
public void run()
{ draw();
for(;;)
{
move();
try
{ Thread.sleep(5);}
catch(InterruptedException e)
{ e.printStackTrace();}
}
}
}///////////////////////////////////////////////////////////////
BounceApplet.java 使用或覆盖了已过时的API
了解详细信息,请使用 -Xlint:deprecation 重新编
请问如何解决这问题
谢谢
源代码如下
////////////////////////////////////////////////////////////
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class BounceApplet extends Applet
{ public BounceApplet ()
{ BounceExpress bounce = new BounceExpress();
bounce.setSize(300,200);
bounce.show();}
}
class BounceExpress extends Frame
{ Canvas canvas;
Button blackButton,redButton,closeButton;
public BounceExpress()
{ canvas =new Canvas();
Panel p = new Panel();
blackButton = new Button("Add minor ball of black ");
redButton = new Button ("Add minor ball of red ");
closeButton = new Button ("Close window");
Listener listener = new Listener();
setTitle ("BounceExpress");
canvas.setBackground(Color.lightGray);
add("Center",canvas);
add("South",p);
p.add(blackButton);
p.add(redButton);
p.add(closeButton);
blackButton.addActionListener(listener);
redButton.addActionListener(listener);
closeButton.addActionListener(listener);
this.addWindowListener(new WListener());}
class WListener extends WindowAdapter
{ public void windowClosing(WindowEvent e)
{ dispose();}
}
class Listener implements ActionListener
{ public void actionPerformed(ActionEvent e)
{ if(e.getSource() == blackButton)
{ Ball b = new Ball(canvas,Color.black);
b.setPriority(Thread.NORM_PRIORITY);
b.start();}
else
if(e.getSource() == redButton)
{ Ball b = new Ball(canvas,Color.red);
b.setPriority(Thread.NORM_PRIORITY+2);
b.start();}
else
if (e.getSource() == closeButton)
{ dispose();}
}
}
}
class Ball extends Thread
{ private Canvas box;
private static final int XSIZE =10;
private static final int YSIZE =10;
private int x=0,y=0;
private int dx = 2, dy=2;
private Color color;
public Ball(Canvas _canvas,Color _color)
{ box = _canvas;
color = _color;
this.setDaemon(true);}
public void draw()
{ Graphics g = box.getGraphics();
g.setColor(color);
g.fillOval(x,y,XSIZE,YSIZE);}
public void move()
{ Graphics g = box.getGraphics();
if(g== null) return;
g.setColor(color);
g.setXORMode(box.getBackground());
g.fillOval(x,y,XSIZE,YSIZE);
x+= dx;
y+= dy;
Dimension d= box.getSize();
if (x<0)
{ x=0;dx = -dx;}
if (x+XSIZE>=d.width)
{ x=d.width - XSIZE;dx = -dx;}
if (y<0)
{ y=0;dy = -dy;}
if (y+XSIZE>=d.height)
{ y=d.height - YSIZE;dy = -dy;}
g.fillOval(x,y,XSIZE,YSIZE);
}
public void run()
{ draw();
for(;;)
{
move();
try
{ Thread.sleep(5);}
catch(InterruptedException e)
{ e.printStackTrace();}
}
}
}///////////////////////////////////////////////////////////////
show
@Deprecated
public void show(boolean b)已过时。 从 JDK version 1.1 开始,由 setVisible(boolean) 取代。 这么改
public class BounceApplet extends Applet
{ public BounceApplet ()
{ BounceExpress bounce = new BounceExpress();
bounce.setSize(300,200);
bounce.setVisible(true);}
}
我还以为是什么呢........
show
@Deprecated
public void show(boolean b)已过时。 从 JDK version 1.1 开始,由 setVisible(boolean) 取代。 这么改
public class BounceApplet extends Applet
{ public BounceApplet ()
{ BounceExpress bounce = new BounceExpress();
bounce.setSize(300,200);
bounce.setVisible(true); //*******************
}
}
用下面代码 老是报错 请问为什么?
////////////////////////////////
<html>
<head>
<title>BounceApplet</title>
<body>
<APPLET CODE = "BounceApplet.class"
width =300;
height = 200;>
</APPLET>
</body>
</html>
/////////////////////
报错内容为
Exception in thread "main" java.util.MissingResourceException: Can't find resource for bundle sun.applet.resources.MsgAppletViewer, key appletpanel.badattribute.exception
at java.util.ResourceBundle.getObject(ResourceBundle.java:325)
at java.util.ResourceBundle.getObject(ResourceBundle.java:322)
at java.util.ResourceBundle.getString(ResourceBundle.java:285)
at sun.applet.AppletMessageHandler.getMessage(AppletMessageHandler.java:39)
at sun.applet.AppletPanel.showAppletStatus(AppletPanel.java:866)
at sun.applet.AppletPanel.init(AppletPanel.java:197)
at sun.applet.AppletViewer.<init>(AppletViewer.java:177)
at sun.applet.StdAppletViewerFactory.createAppletViewer(AppletViewer.java:82)
at sun.applet.AppletViewer.parse(AppletViewer.java:1122)
at sun.applet.AppletViewer.parse(AppletViewer.java:1056)
at sun.applet.Main.run(Main.java:138)
at sun.applet.Main.main(Main.java:80)
里面不该有";" 删掉就可以了