在eclipse中如何运行applet
importjavax.swing.Timer;importjava.awt.*;importjavax.swing.*;importjava.awt.event.*;p...
import javax.swing.Timer;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Ball extends JPanel{
private int delay = 10;
protected Timer timer = new Timer(delay, new TimerListener());
private int x = 0; private int y = 0;
private int radius = 5;
private int dx = 2;
private int dy = 2;
public Ball(){
timer.start();
}
private class TimerListener implements ActionListener{
public void actionPerformed(ActionEvent e){
repaint();
}
}
protected void paintComonent(Graphics g){
super.paintComponent(g);
g.setColor(Color.red);
if(x<radius) dx = Math.abs(dx);
if(x>getWidth() - radius) dx= -Math.abs(dx);
if(y< radius) dy= Math.abs(dy);
if(y>getHeight() - radius) dy = -Math.abs(dy);
x+=dx;
y+=dy;
g.fillOval(x - radius,y - radius, radius * 2, radius * 2);
}
public void suspend(){
timer.stop();
}
public void resume(){
timer.start();
}
public void setDelay(int delay){
this.delay = delay;
timer.setDelay(delay);
}
}
在eclipse如何运行这条程序 展开
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Ball extends JPanel{
private int delay = 10;
protected Timer timer = new Timer(delay, new TimerListener());
private int x = 0; private int y = 0;
private int radius = 5;
private int dx = 2;
private int dy = 2;
public Ball(){
timer.start();
}
private class TimerListener implements ActionListener{
public void actionPerformed(ActionEvent e){
repaint();
}
}
protected void paintComonent(Graphics g){
super.paintComponent(g);
g.setColor(Color.red);
if(x<radius) dx = Math.abs(dx);
if(x>getWidth() - radius) dx= -Math.abs(dx);
if(y< radius) dy= Math.abs(dy);
if(y>getHeight() - radius) dy = -Math.abs(dy);
x+=dx;
y+=dy;
g.fillOval(x - radius,y - radius, radius * 2, radius * 2);
}
public void suspend(){
timer.stop();
}
public void resume(){
timer.start();
}
public void setDelay(int delay){
this.delay = delay;
timer.setDelay(delay);
}
}
在eclipse如何运行这条程序 展开
3个回答
展开全部
html文件,直接右击鼠标,选择直接applet运行那个选项即可
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
右键-run as - java applet
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询