美文网首页
窗口内容滚动播放

窗口内容滚动播放

作者: _Raye | 来源:发表于2017-04-04 11:40 被阅读0次
    package org.mobiletrain;
    
    
    import java.awt.Font;
    
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.Timer;
    
    @SuppressWarnings("serial")
    public class Test02 extends JFrame{
        
        public Test02(){
            this.setTitle("滚动播放");
            this.setSize(320, 140);
            this.setResizable(false);
            this.setLocationRelativeTo(null);
            this.setDefaultCloseOperation(EXIT_ON_CLOSE);
            
            JLabel label = new JLabel("欢迎来到成都千锋                      ");
            label.setFont(new Font("微软雅黑", Font.PLAIN, 18));
            this.add(label);
            Timer timer = new Timer(200, evt -> {
                //从Java 8开始在lambda表达式接口或者接口回调中使用的局部变量
                //默认是final的,所以不能重新赋值
                String string = label.getText();
                //迎来到成都千锋                      + 欢(第一遍的执行结果)
                string = string.substring(1) + string.charAt(0);
                label.setText(string);
            });
            timer.start();
        }
        
            
        public static void main(String[] args) {
            new Test02().setVisible(true);
        }
    }
    

    相关文章

      网友评论

          本文标题:窗口内容滚动播放

          本文链接:https://www.haomeiwen.com/subject/zrvaottx.html