滚动字幕

在屏幕上从左到右滚动当前时间

import java.awt.BorderLayout;  
import java.awt.Color;  
import java.awt.Font;  
import java.awt.Graphics;  
import java.awt.event.ActionEvent;  
import java.awt.event.ActionListener;  
import java.text.SimpleDateFormat;  
import java.util.Calendar;  
  
import javax.swing.JFrame;  
import javax.swing.JLabel;  
import javax.swing.JPanel;  
import javax.swing.Timer;  
  
public class ZiMu extends JFrame  
{  
  
    private static final long serialVersionUID = 1L;  
  
    public ZiMu()  
    {  
  
        Font font1 = new Font("幼圆", Font.BOLD, 16);  
        Calendar cal = Calendar.getInstance();  
        SimpleDateFormat formatter = new SimpleDateFormat("EEEE,MMMMdd日,yyyy年 HH:mm:ss");  
        String mDateTime = formatter.format(cal.getTime());  
  
        MovingMessagePanel messagePanel = new MovingMessagePanel(mDateTime);  
        messagePanel.setFont(font1);  
        messagePanel.setBackground(Color.BLACK);  
        messagePanel.setForeground(Color.PINK);  
  
        add(messagePanel);  
  
    }  
  
    public static void main(String[] args)  
    {  
  
    	ZiMu frame = new ZiMu();  
        JLabel label = new JLabel("开始调试时间:X月X日     结束调试时间:X月X日");  
        label.setBackground(Color.black);  
        frame.setTitle("滚动字幕");  
        frame.setLocationRelativeTo(null);  
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
        frame.setSize(320, 120);  
        frame.setVisible(true);  
        frame.add(label, BorderLayout.SOUTH);  
    }  
  
    static class MovingMessagePanel extends JPanel  
    {  
  
         
        private static final long serialVersionUID = 1L;  
        private String message = " ";  
        private int xCoordinate = 0;  
        private int yCoordinate = 40;  
          
        public MovingMessagePanel(String message)  
        {  
            this.message = message;  
            Timer timer = new Timer(100, new TimerListener());  
            timer.start();  
        }  
  
        public void paintComponent(Graphics g)  
        {  
            super.paintComponent(g);  
  
            if (xCoordinate > getWidth())  
            {  
                xCoordinate = -100;  
            }  
  
            xCoordinate += 5;  
            g.drawString(message, xCoordinate, yCoordinate);  
        }  
  
        class TimerListener implements ActionListener  
        {  
  
            public void actionPerformed(ActionEvent e)  
            {  
                repaint();  
            }  
        }  
    }  
}  

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
class ZiMupanel extends JFrame { public ZiMupanel() { Container con = this.getContentPane(); // 设置窗口名称 this.setTitle("滚动字幕"); // 设置布局管理器为 null ,方便 面板定位,一般使用null 布局时,将窗口设置不可改变大小 this.setLayout(null); // 设置窗口位置和大小 this.setBounds(300, 300, 460, 330); // 设置窗口可见 this.setVisible(true); // 设置不可改变大小 this.setResizable(false); // 设置当点击窗口的关闭按钮时退出 // 设置此窗体关闭,滚动面板不关闭 this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Panelfont1 p1 = new Panelfont1(); con.add(p1); p1.setBounds(15, 15, 175, 60); Panelfont2 p2 = new Panelfont2(); con.add(p2); p2.setBounds(195, 15, 250, 60); Panelneizi p3 = new Panelneizi(); con.add(p3); p3.setBounds(15, 80, 175, 80); Paneldirection p4 = new Paneldirection(); con.add(p4); p4.setBounds(195, 80, 250, 80); Panel5 p5 = new Panel5(); con.add(p5); p5.setBounds(15, 155, 430, 70); Panel6 p6 = new Panel6(); con.add(p6); p6.setBounds(15, 220, 430, 70); } } class Panelfont1 extends JPanel implements ActionListener{ public Panelfont1() { this.setBorder(BorderFactory.createTitledBorder("滚动字幕的文字大小控制"));//设置 面板边框 this.setLayout(new GridLayout(1, 2)); bigfont = new JRadioButton("大字体", false); smallfont = new JRadioButton("小字体", true); bigfont.addActionListener(this); smallfont.addActionListener(this); ButtonGroup sexRadioButtonGroup = new ButtonGroup();// 创建一个选按钮组 sexRadioButtonGroup.add(bigfont);// 将单选按钮对象添加到按钮组中 sexRadioButtonGroup.add(smallfont);// 将单选按钮对象添加到按钮组中 //Enumeration elements = sexRadioButtonGroup.getElements();// 遍历按钮组中的所有按钮 this.add(bigfont); this.add(smallfont); } public void actionPerformed(ActionEvent e) { if(bigfont.isSelected()){ fontSize = 50; }else { fontSize = 36; } Font font = new Font(fontName,Font.BOLD,fontSize);
Delphi是一种编程语言和开发环境,能够用于创建各种类型的应用程序,包括滚动字幕滚动字幕是一种以持续滚动的方式显示信息的文本效果。下面让我详细介绍一下如何使用Delphi来实现滚动字幕。 在Delphi中,我们可以使用TLabel控件来实现滚动字幕效果。首先,需要在窗体上放置一个TLabel控件,并设置其属性来适应滚动字幕的需求。比如,将Label的AutoSize属性设置为False,将其Width属性设置为窗体的宽度。这样,Label就能够在窗体上水平滚动显示文本了。 接下来,我们需要使用定时器来控制滚动字幕的速度。在Delphi中,我们可以使用TTimer组件来实现定时器功能。我们需要将TTimer的Interval属性设置为一个适当的值,控制滚动字幕的速度。然后,在TTimer的OnTimer事件中,可以编写代码来实现滚动字幕的效果。 在OnTimer事件中,我们可以通过调整Label的Left属性来实现滚动字幕的效果。通过每次将Label的Left属性减小一个固定值,就能够使Label向左滚动。当Label的Left属性减小到一定值后,我们可以将其重置为窗体的宽度,实现循环滚动的效果。 此外,我们还可以通过设置Label的字体、颜色等属性来定制滚动字幕的外观。比如,可以设置Label的Font属性来改变字体样式,设置Label的Color属性来改变背景颜色,以及设置Label的Caption属性来显示滚动的文本内容。 总的来说,使用Delphi实现滚动字幕是相对简单的。通过合理设置Label和TTimer的属性,并在OnTimer事件中编写代码来控制滚动效果,即可实现一个滚动字幕的效果。当然,我们还可以进一步定制滚动字幕的外观和实现其他的功能,这需要根据具体的需求和编程技巧来实现。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值