2个回答
展开全部
java里面有一个叫做Timer的东西
代码找到了:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
////////////////////////////////////////////////////////////
public class AnimationDemo extends JFrame{
AnimationDemo(){
add(new MPanel("我是要移动的文字"));
}
////////////////////////////////////////////////////////////
public static void main(String[] args){
JFrame frame=new AnimationDemo();
frame.setTitle("AnimationDemo");
frame.setSize(280, 100);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
/////////////////////////////////////////////////////////////
static class MPanel extends JPanel{
private String message="welcome to java!";
private int xZuoBiao=0;
private int yZuoBiao=30;
//...........................................................
public MPanel(String message){
this.message=message;
Timer timer=new Timer(100,new TimerListener());
timer.start();
}
//............................................................
protected void paintComponent(Graphics g){
super.paintComponent(g);
if(xZuoBiao>getWidth()){
xZuoBiao=-20;
}
xZuoBiao+=10;
g.drawString(message, xZuoBiao, yZuoBiao);
}
//.............................................................
class TimerListener implements ActionListener{
public void actionPerformed(ActionEvent e){
repaint();
}
}
}
}
代码找到了:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
////////////////////////////////////////////////////////////
public class AnimationDemo extends JFrame{
AnimationDemo(){
add(new MPanel("我是要移动的文字"));
}
////////////////////////////////////////////////////////////
public static void main(String[] args){
JFrame frame=new AnimationDemo();
frame.setTitle("AnimationDemo");
frame.setSize(280, 100);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
/////////////////////////////////////////////////////////////
static class MPanel extends JPanel{
private String message="welcome to java!";
private int xZuoBiao=0;
private int yZuoBiao=30;
//...........................................................
public MPanel(String message){
this.message=message;
Timer timer=new Timer(100,new TimerListener());
timer.start();
}
//............................................................
protected void paintComponent(Graphics g){
super.paintComponent(g);
if(xZuoBiao>getWidth()){
xZuoBiao=-20;
}
xZuoBiao+=10;
g.drawString(message, xZuoBiao, yZuoBiao);
}
//.............................................................
class TimerListener implements ActionListener{
public void actionPerformed(ActionEvent e){
repaint();
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-11-28
展开全部
百度 java 文字 scrollLabel
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询