【matlab】----GUI编程-登录框实现(纯m文件)

来源:互联网 发布:数据如何分析 编辑:程序博客网 时间:2024/05/17 23:43

1. 功能

  • 用户名输入
  • 密码输入(隐藏密码,带星号)
  • 输入正确错误提示
  • 带背景图片
  • 带logo修改

2. 界面 
FreeApe 
FreeApe 
FreeApe 
FreeApe 
3. 源代码

【loginSys.m
  • 1
  • 1
function loginSys%% 清除变量,清命令窗口屏,清除图形clear;clc;%% 新建图形并设置相关属性%scrsz = get(0,'ScreenSize');Hd_login = figure('NumberTitle', 'off', 'Resize','off','Color',[0.753,0.753,0.753],'Name', '登录','tag','Hd_login');%取得Figure的JavaFrame。%修改图标newIcon = javax.swing.ImageIcon('.\images\icon.png');figFrame = get(Hd_login,'JavaFrame');            figFrame.setFigureIcon(newIcon);%转换图形窗口菜单条的“开”与“关”5set(Hd_login,'menubar','none','Unit','normalized','Position',[0.28,0.32,0.38,0.45]);%% 设置登录窗口背景图片%% 添加背景图片Hd_axes = axes('units','normalized','position',[0 0 1 1],'tag','Hd_axes');uistack(Hd_axes,'down')II=imread('.\images\login.jpg');image(II)% colormap grayset(Hd_axes,'handlevisibility','off','visible','off');%% 添加登录所需控件:用户名框、密码框等%用户名Hd_user = uicontrol('Parent',Hd_login,'Style','text',...    'String','用户名',...    'Units','normalized',...    'FontWeight','bold',...        'Background',[0.8 0.8 0.8],...    'ForegroundColor','black',...    'Units','normalized',...    'FontSize',25,...    'Enable','inactive',...    'tag','Hd_user',...    'Position',[0.1,0.68,0.25,0.15],...    'CallBack','');Hd_unserin = uicontrol('Parent',Hd_login,'Style','Edit',...    'String','',...    'FontWeight','bold',...    'ForegroundColor',[0.871,0.49,0],...    'Units','normalized',...    'FontSize',10,...    'HorizontalAlignment','left',...    'tag','Hd_unserin',...    'Position',[0.38,0.68,0.55,0.15],...    'CallBack','');%密码Hd_passwd = uicontrol('Parent',Hd_login,'Style','text',...    'String','密    码',...    'Units','normalized',...    'FontWeight','bold',...        'Background',[0.8 0.8 0.8],...    'ForegroundColor','black',...    'Units','normalized',...    'FontSize',25,...    'Enable','inactive',...    'tag','Hd_passwd',...    'Position',[0.1,0.48,0.25,0.15],...    'CallBack','');%java 实现密码文本框输入jPass = javax.swing.JPasswordField;J_passwdin = javacomponent(jPass,[198 167 287 52]);%提示 文本框hTip = uicontrol('style','text','visible','off','String','',...    'FontSize',18,...    'FontWeight','bold',...    'ForegroundColor','red',...    'position',[150 300 250 30]);%登录,修改密码uicontrol('pos',[100 80 140 40],'string','确认','FontWeight','bold',...    'ForegroundColor',[0 0 1],...    'FontSize',18,...    'callback',{@loginCheck,Hd_unserin,J_passwdin,hTip});uicontrol('pos',[290 80 140 40],'string','修改密码','FontWeight','bold',...    'ForegroundColor',[0 0 1],...    'FontSize',18,...    'callback',{@modifyPasswd,hTip});function modifyPasswd(~,~,hTip)    set(hTip,'Visible','on','string','请联系开发人员!');    pause(3);    set(hTip,'Visible','off');
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
【loginCheck.m
  • 1
  • 1
function loginCheck(~, ~,hUser,hPass,hTip)    user = get(hUser,'String')    pswd = hPass.text    if (strcmp(pswd, '111111') && strcmp(user,'FreeApe'))        set(hTip,'Visible','off','string','密码正确');        out = '密码正确'        %do something...(比如进入系统主界面等)    else        set(hTip,'Visible','on','string','用户名或密码错误!');        pause(2);        set(hTip,'Visible','off');        out = '密码错误'    end
0 0