Matlab创建密码隐藏的GUI登录界面

Matlab创建密码隐藏的GUI登录界面

1.在GUI中添加控件

在matlab中工作窗口输入运行guide,进入GUI,设计界面如下
Matlab创建密码隐藏的GUI登录界面_第1张图片
这里密码框先不急的插入

2.控件插入回调函数

2.1登录按钮的回调函数

function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% str2=get(handles.edit2,'string');
global a1;
a2 = str2double(handles.hPass.Text);

% global a2;
if (a1==1234)&&(a2==56789)
     c=Zunihuan;
     set(c,'Visible','on');
     close(Log_on);
end

2.2账户对应的可编辑框的回调函数

function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double
global a1;
a1=str2double(get(handles.edit1,'String'));

3.设置密码框

在 function Log_on_OpeningFcn(hObject, eventdata, handles, varargin)插入如下函数

function Log_on_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to Log_on (see VARARGIN)

% Choose default command line output for Log_on
handles.output = hObject;
%设置密码框
jPass = javax.swing.JPasswordField;
hPass= javacomponent(jPass,[248.5 268 150 28]);%位置横纵坐标和长宽
jPass.setHorizontalAlignment(javax.swing.JPasswordField.CENTER); %水平位置
handles.hPass = hPass;
% Update handles structure
guidata(hObject, handles);

4.运行结果

Matlab创建密码隐藏的GUI登录界面_第2张图片

你可能感兴趣的:(登录界面)