⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 a1.m

📁 用matlab来实现密码登陆窗口代码
💻 M
字号:
function varargout = a1(varargin)
% A1 M-file for a1.fig
%      A1, by itself, creates a new A1 or raises the existing
%      singleton*.
%
%      H = A1 returns the handle to a new A1 or the handle to
%      the existing singleton*.
%
%      A1('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in A1.M with the given input arguments.
%
%      A1('Property','Value',...) creates a new A1 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before a1_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to a1_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Copyright 2002-2003 The MathWorks, Inc.

% Edit the above text to modify the response to help a1

% Last Modified by GUIDE v2.5 25-Oct-2008 21:22:30

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @a1_OpeningFcn, ...
                   'gui_OutputFcn',  @a1_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 a1 is made visible.
function a1_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 a1 (see VARARGIN)

% Choose default command line output for a1
handles.output = hObject;
set(handles.a1_code,'String','');
set(handles.a1_user,'String','');
handles.xinghao = '';
handles.user='dafei0214';
handles.code='87406';
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes a1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = a1_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)

% Get default command line output from handles structure
varargout{1} = handles.output;

function a1_user_Callback(hObject, eventdata, handles)
% hObject    handle to a1_user (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 a1_user as text
%        str2double(get(hObject,'String')) returns contents of a1_user as a double


% --- Executes during object creation, after setting all properties.
function a1_user_CreateFcn(hObject, eventdata, handles)
% hObject    handle to a1_user (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

function a1_code_Callback(hObject, eventdata, handles)
% hObject    handle to a1_code (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)set(hObject,'foregroundcolor',[1 1 1]); 40% Hints: get(hObject,'String') returns contents of a1_code as text
%        str2double(get(hObject,'String')) returns contents of a1_code as a double
% set(handles.a1_code,'foregroundcolor',[1 1 1]);
        
% --- Executes during object creation, after setting all properties.
function a1_code_CreateFcn(hObject, eventdata, handles)
% hObject    handle to a1_code (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
set(hObject,'UserData','');
set(hObject,'String','');
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% --- Executes on button press in a1_cancer.
function a1_cancer_Callback(hObject, eventdata, handles)
% hObject    handle to a1_cancer (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% set(handles.a1_user,'UserData','','string','');
set(handles.a1_code,'UserData','','string','');
close(gcf);
clear
clc
% --- Executes on button press in a1_ok.
function a1_ok_Callback(hObject, eventdata, handles)
% hObject    handle to a1_ok (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
passChar = get(handles.a1_code,'UserData'); 
userChar = get(handles.a1_user,'String');
if strcmp(passChar,handles.code)&strcmp(userChar,handles.user)
   msgbox('登陆成功!'); 
   close(gcf);
   close(a1);
   figure(lianxi02);
   set(gcf,'name','系统界面BY罗华飞QQ335340681');
else 
   set(handles.a1_code,'string','','UserData','');
   msgbox('用户名或密码错误!'); 
end 

% --- Executes when figure1 is resized.
function figure1_ResizeFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% --- Executes on key press over a1_code with no controls selected.
function a1_code_KeyPressFcn(hObject, eventdata, handles)
% hObject    handle to a1_code (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% set(hObject,'fontSize',10);
currChar = get(gcf,'CurrentCharacter');
oldChar = get(hObject,'UserData');
xinghao=get(hObject,'string');
userChar=get(handles.a1_user,'string');
if (currChar>='0'&currChar<='9')|(currChar>='a'&currChar<='z')...
        |(currChar>='A'&currChar<='Z')
    oldChar = [oldChar currChar];
    xinghao=[handles.xinghao '*'];
    set(hObject,'UserData',oldChar,'string',xinghao);
    handles.xinghao=xinghao;
    guidata(hObject,handles);
elseif double(currChar)==26|double(currChar)==8
           oldChar='';
           handles.xinghao='';
           set(hObject,'UserData',oldChar,'string',handles.xinghao); 
           guidata(hObject,handles);
elseif double(currChar)==13
           set(hObject,'string',xinghao);
           if strcmp(oldChar,handles.code)&strcmp(userChar,handles.user) 
               msgbox('登陆成功!');
               close(gcf);
               close(a1);
               figure(lianxi02);
               set(gcf,'name','系统界面BY罗华飞QQ335340681');
           else 
               set(hObject,'string','','UserData','');
               handles.xinghao='';
               guidata(hObject,handles);
               msgbox('用户名或密码错误!');
           end 
else 
               set(hObject,'UserData',oldChar);
               set(hObject,'string',handles.xinghao);
end 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -