jingweimo的个人博客分享 http://blog.sciencenet.cn/u/jingweimo

博文

GUI: Pop-up Menu and Listbox, Button group and Panel

已有 1853 次阅读 2015-9-13 02:33 |系统分类:科研笔记

%% Part1

function varargout = ex6(varargin)

%Pop-up Menu and Listbox

gui_Singleton = 1;

gui_State = struct('gui_Name',       mfilename, ...

'gui_Singleton',  gui_Singleton, ...

'gui_OpeningFcn', @ex6_OpeningFcn, ...

'gui_OutputFcn',  @ex6_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


function ex6_OpeningFcn(hObject, eventdata, handles, varargin)

handles.output = hObject;

guidata(hObject, handles);


function varargout = ex6_OutputFcn(hObject, eventdata, handles)

varargout{1} = handles.output;


function province_Callback(hObject, eventdata, handles)

sel = get(hObject,'value');

stra = {'Zhengzhou','Luoyan','Kaifeng','Shangqiu'};

strb = {'Hefei','Wuhu','Bengbu','Huaibei','Xuancheng'};

switch sel

case 1

       set(handles.city,'string','');

case 2

       set(handles.city,'string',stra);

case 3

       set(handles.city,'string',strb);

end


function province_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

   set(hObject,'BackgroundColor','white');

end


function city_Callback(hObject, eventdata, handles)


function city_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

   set(hObject,'BackgroundColor','white');

end

%%Part2

function varargout = ex7(varargin)

% Number conversion

gui_Singleton = 1;

gui_State = struct('gui_Name',       mfilename, ...

'gui_Singleton',  gui_Singleton, ...

'gui_OpeningFcn', @ex7_OpeningFcn, ...

'gui_OutputFcn',  @ex7_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


function ex7_OpeningFcn(hObject, eventdata, handles, varargin)

handles.output = hObject;

guidata(hObject, handles);


function varargout = ex7_OutputFcn(hObject, eventdata, handles)

varargout{1} = handles.output;


function num_Callback(hObject, eventdata, handles)


function num_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

   set(hObject,'BackgroundColor','white');

end


% --- Executes when selected object is changed in bin_dec.

function bin_dec_SelectionChangeFcn(hObject, eventdata, handles)

str = get(handles.num,'string');

switch get(hObject,'tag')

case'bin'

%decimal to binary

       val = floor(str2double(str));

if (~isempty(val)) && (val>= 0)

           set(handles.num,'string',dec2bin(val)); %dec2bin

else

           set(handles.num,'string','wrong input!');

end

case'dec'

%binary to decimal

if all(str =='0' | str=='1') % for vector '|'

           set(handles.num,'string',num2str(bin2dec(str)));

else

           set(handles.num,'string','wrong input!')

end

end




https://blog.sciencenet.cn/blog-578676-920459.html

上一篇:GUI运行报错:Attempt to reference field of non-structure arr
下一篇:Specify image rectangle by mouse
收藏 IP: 68.48.108.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2025-1-8 12:47

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部