MATLAB GUI如何实现字幕滚动

MATLAB GUI如何实现字幕滚动

主要函数及解析

handles.timer = timer(‘Period’,1,‘ExecutionMode’,‘FixedRate’, ‘TimerFcn’,{@timercallback,handles});
function timercallback(obj, event, handles);

start(handles.timer);
stop(handles.timer);
重点在timer设置,以及其对应的回调函数;
本部分介绍如何创建计时器对象,启动计时器运行,以及指定您希望在计时器触发时执行的过程。当计时器对象指定的时间已过且计时器对象执行您指定的命令时,即触发计时器;
要使用计时器,请执行以下步骤:
1.创建一个计时器对象。
可使用 timer 函数创建计时器对象。
2使用Set指定希望在计时器触发时执行的 MATLAB 命令并控制计时器对象的其他各方面的行为
3.启动计时器对象。
创建计时器对象后,必须使用 start 或 startat 函数启动该对象。
4.在处理完计时器对象后将其删除。
具体参阅 https://ww2.mathworks.cn/help/matlab/matlab_prog/use-a-matlab-timer-object.html

代码

下面展示一些 内联代码片

``function varargout = slide_word(varargin)
gui_Singleton = 1;
gui_State = struct(‘gui_Name’, mfilename, …
‘gui_Singleton’, gui_Singleton, …
‘gui_OpeningFcn’, @slide_word_OpeningFcn, …
‘gui_OutputFcn’, @slide_word_OutputFcn, …
‘gui_LayoutFcn’, [] , …
‘gui_Callback’, []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% — Executes just before slide_word is made visible.
function slide_word_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
global word;
word = {‘Hello!’,‘你好’};
handles.timer = timer(‘Period’,1,‘ExecutionMode’,‘FixedRate’, ‘TimerFcn’,{@timercallback,handles});
start(handles.timer);
% Update handles structure
guidata(hObject, handles);
uiwait(handles.figure1);

function timercallback(obj, event, handles)
global word;
Str1 = word{1};
Str2 = word{2};
word = strvcat(Str2, Str1);
set(handles.text, ‘String’, word);
tempStr{1} = word(1, : );
tempStr{2} = word(2, : );
word = tempStr;

% — Outputs from this function are returned to the command line.
function varargout = slide_word_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
stop(handles.timer);
% Get default command line output from handles structure
varargout{1} = handles.output;

运行结果

动态字幕显示

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 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);

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值