Filter löschen
Filter löschen

Guide: alphabet and symbols

20 Ansichten (letzte 30 Tage)
john
john am 22 Mär. 2012
Hi,
I have edittext and pushbutton.
If I write any letter from alphabet {a,A,b,B,c,C.....y,Y,z,Z}, then I want to enable pushbutton.
If I write any other symbols for example {" ? * & # !}, then I want to disable pushbutton.
Please, how Can I do this? . It is any different between alphabet a,b,c,d and symbols?.
Thank you

Akzeptierte Antwort

Oleg Komarov
Oleg Komarov am 22 Mär. 2012
Try this GUI
function myGUI
% Create figure
S.fh = figure('units','pixels',...
'position',[500 500 200 100],...
'menubar','none',...
'name','myGUI',...
'numbertitle','off',...
'resize','off');
% Create java edit text box
% I avoid he MATLAB uicontrol because the KeyPressFunction has a bug which
% doesn't update in real time the string
S.ed = javax.swing.JTextField();
S.ed.setHorizontalAlignment(javax.swing.JTextField.CENTER)
javacomponent(S.ed, [10 60 180 35]);
% Create push button
S.pb = uicontrol('style','push',...
'units','pix',...
'position',[10 10 180 40],...
'fontsize',14,...
'string','Do smt');
% Add check of the string in the edit text box
set(S.ed, 'KeyReleasedCallback', @ed_krc);
function ed_krc(varargin)
% If the string contains symbols
if any(regexp(char(S.ed.getText),'\W+'))
% Disable push button
set(S.pb,'Enable','off')
else
% Otherwise enable it
set(S.pb,'Enable','on')
end
end
end
  14 Kommentare
Oleg Komarov
Oleg Komarov am 26 Mär. 2012
Example with subfunctions:
function mainGUI
end
function callback
end
Example with nested functions
function mainGUI
function callback
end
end
john
john am 28 Mär. 2012
Hi, can I define typ of the number? if permissible numbers are: 4,3 or 3*10^3 or 4.3*10^(-4) or 3.5e2 or 4.6e(-2).
.
.
all others are not permissible.
.
.
if any(regexp(char(get(handles.edit7,'String')),'[^0-9.*^()-]'))
set(handles.edit,'String','Error');
else
set(handles.edit, 'String','OK');
end;

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by