Sunteți pe pagina 1din 5

function varargout = MengukurBerat(varargin)

% MENGUKURBERAT M-file for MengukurBerat.fig


%
MENGUKURBERAT, by itself, creates a new MENGUKURBERAT or raises the
existing
%
singleton*.
%
%
H = MENGUKURBERAT returns the handle to a new MENGUKURBERAT or the
handle to
%
the existing singleton*.
%
%
MENGUKURBERAT('CALLBACK',hObject,eventData,handles,...) calls the local
%
function named CALLBACK in MENGUKURBERAT.M with the given input
arguments.
%
%
MENGUKURBERAT('Property','Value',...) creates a new MENGUKURBERAT or
raises the
%
existing singleton*. Starting from the left, property value pairs are
%
applied to the GUI before MengukurBerat_OpeningFcn gets called. An
%
unrecognized property name or invalid value makes property application
%
stop. All inputs are passed to MengukurBerat_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
% Edit the above text to modify the response to help MengukurBerat
% Last Modified by GUIDE v2.5 03-Jan-2016 08:04:43
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',
mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @MengukurBerat_OpeningFcn, ...
'gui_OutputFcn', @MengukurBerat_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 MengukurBerat is made visible.


function MengukurBerat_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 MengukurBerat (see VARARGIN)

% Choose default command line output for MengukurBerat


handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes MengukurBerat wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = MengukurBerat_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 tinggi_Callback(hObject, eventdata, handles)


% hObject
handle to tinggi (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 tinggi as text
%
str2double(get(hObject,'String')) returns contents of tinggi as a
double
tinggi = str2double(get(hObject,'String'));
if isnan(tinggi)
set(handles.berat,'Enable','off');
get(hObject,'String');
errordlg('tinggi harus diisi dengan angka !!','Ada yang salah ?');
set(handles.hasil_tinggi,'string','');
elseif (tinggi <= 0)
set(handles.tinggi,'Enable','off');
set(hObject, 'String', '');
errordlg('tinggi tidak boleh nol !!','Ada yang salah ?');
elseif isempty(tinggi)
set(handles.tinggi,'Enable','off');
errordlg('tinggi tidak boleh kosong !!','Ada yang salah ?');
else
set(handles.berat,'Enable','on');
% --- Executes during object creation, after setting all properties.
function tinggi_CreateFcn(hObject, eventdata, handles)
% hObject
handle to tinggi (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 && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function berat_Callback(hObject, eventdata, handles)


% hObject
handle to berat (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 berat as text
%
str2double(get(hObject,'String')) returns contents of berat as a
double
berat = str2double(get(hObject, 'String'));
if isnan(berat)
set(handles.tmbl_hitung,'Enable','off');
set(hObject, 'String', '');
errordlg('berat harus diisi dengan angka !!','Ada yang salah ?');
elseif (berat <= 0)
set(handles.tmbl_hitung,'Enable','off');
set(hObject, 'String', '');
errordlg('berat tidak boleh nol !!','Ada yang salah ?');
elseif isempty(berat)
set(handles.tmbl_hitung,'Enable','off');
errordlg('berat tidak boleh kosong !!','Ada yang salah ?');
else
set(handles.tmbl_hitung,'Enable','on');
end
% --- Executes during object creation, after setting all properties.
function berat_CreateFcn(hObject, eventdata, handles)
% hObject
handle to berat (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 && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in tmbl_hitung.


function tmbl_hitung_Callback(hObject, eventdata, handles)
% hObject
handle to tmbl_hitung (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
tinggi=str2num(get(handles.panjang, 'String'));
berat=str2num(get(handles.lebar, 'String'));

hasil=berat/tinggi.^2;
set(handles.tinggi,'string','');
set(handles.berat,'string','');
set(handles.tmbl_hitung,'Enable','off');
set(handles.berat,'Enable','off');
% --- Executes on button press in tmbl_keluar.
function tmbl_keluar_Callback(hObject, eventdata, handles)
% hObject
handle to tmbl_keluar (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
selection=questdlg(['Anda Yakin Ingin Menutup Aplikasi',' ?'],...
['bertanya' '' '...'],...
'Ya','Batal','Ya');
if strcmp(selection,'Batal')
return
end
close;

Menerapkan Pada GUI


1. Pilih File - New - GUI - Pilih Blank GUI (Default) - Ok

2. Buat Panel seperti gambar dengan mengklik ikon panel .

Komponen
Static text 1
Panel 1
Panel 2

Title
Aplikasi Pengukur Berat Badan
Ukur Berat Ideal
Hasil

Tag
judul
panel
panel_hasil

3. Buat lagi statistic text dan edit text seperti gambar :

Komponen
Static text 2
Static text 3
Panel 3
Panel 4
Push Button 1
Push Button 2

Title
Tinggi badan
Berat badan
Hitung
X

Tag
lbl_tinggi
lbl_berat
tinggi
berat
tmbl_hitung
tmbl_keluar

Enable
On
Off
Off
On

S-ar putea să vă placă și