function calculette(action)

if nargin==0
	calculette('init')
else

	switch action
	case 'init'
		h0 = figure('Color',[0.8 0.8 0.8], ...
		'Position',[264 172 512 384], ...
		'Tag','Fig1');
		h1 = uicontrol('Parent',h0, ...
		'Units','points', ...
		'BackgroundColor',[0.356862745098039 0.529411764705882 0.949019607843137], ...
		'Position',[134 60 208 244], ...
		'Style','frame', ...
		'Tag','Frame1');
		h1 = uicontrol('Parent',h0, ...
		'Units','points', ...
		'Callback','calculette(''chiffre'')', ...
		'Position',[146 179 36 36], ...
		'String','7', ...
		'Tag','7');
		h1 = uicontrol('Parent',h0, ...
		'Units','points', ...
		'Callback','calculette(''chiffre'')', ...
		'Position',[182 179 36 36], ...
		'String','8', ...
		'Tag','8');
		h1 = uicontrol('Parent',h0, ...
		'Units','points', ...
		'Callback','calculette(''chiffre'')', ...
		'Position',[218 179 36 36], ...
		'String','9', ...
		'Tag','9');
		h1 = uicontrol('Parent',h0, ...
		'Units','points', ...
		'Callback','calculette(''operation'')', ...
		'Position',[254 179 36 36], ...
		'String','/', ...
		'Tag','/');
		h1 = uicontrol('Parent',h0, ...
		'Units','points', ...
		'Callback','calculette(''operation'')', ...
		'Position',[254 143 36 36], ...
		'String','*', ...
		'Tag','*');
		h1 = uicontrol('Parent',h0, ...
		'Units','points', ...
		'Callback','calculette(''chiffre'')', ...
		'Position',[218 143 36 36], ...
		'String','6', ...
		'Tag','6');
		h1 = uicontrol('Parent',h0, ...
		'Units','points', ...
		'Callback','calculette(''chiffre'')', ...
		'Position',[182 143 36 36], ...
		'String','5', ...
		'Tag','5');
		h1 = uicontrol('Parent',h0, ...
		'Units','points', ...
		'Callback','calculette(''chiffre'')', ...
		'Position',[146 143 36 36], ...
		'String','4', ...
		'Tag','4');
		h1 = uicontrol('Parent',h0, ...
		'Units','points', ...
		'Callback','calculette(''operation'')', ...
		'Position',[254 107 36 36], ...
		'String','-', ...
		'Tag','-');
		h1 = uicontrol('Parent',h0, ...
		'Units','points', ...
		'Callback','calculette(''chiffre'')', ...
		'Position',[218 107 36 36], ...
		'String','3', ...
		'Tag','3');
		h1 = uicontrol('Parent',h0, ...
		'Units','points', ...
		'Callback','calculette(''chiffre'')', ...
		'Position',[182 107 36 36], ...
		'String','2', ...
		'Tag','2');
		h1 = uicontrol('Parent',h0, ...
		'Units','points', ...
		'Callback','calculette(''chiffre'')', ...
		'Position',[146 107 36 36], ...
		'String','1', ...
		'Tag','1');
		h1 = uicontrol('Parent',h0, ...
		'Units','points', ...
		'Callback','calculette(''operation'')', ...
		'Position',[254 71 36 36], ...
		'String','+', ...
		'Tag','+');
		h1 = uicontrol('Parent',h0, ...
		'Units','points', ...
		'Callback','calculette(''virgule'')', ...
		'Position',[218 71 36 36], ...
		'String','.', ...
		'Tag','.');
		h1 = uicontrol('Parent',h0, ...
		'Units','points', ...
		'Callback','calculette(''plusmoins'')', ...
		'Position',[182 71 36 36], ...
		'String','+/-', ...
		'Tag','+/-');
		h1 = uicontrol('Parent',h0, ...
		'Units','points', ...
		'Callback','calculette(''chiffre'')', ...
		'Position',[146 71 36 36], ...
		'String','0', ...
		'Tag','0');
		h1 = uicontrol('Parent',h0, ...
		'Units','points', ...
		'Callback','calculette(''efface'')', ...
		'Position',[293 179 36 36], ...
		'String','C', ...
		'Tag','C');
		h1 = uicontrol('Parent',h0, ...
		'Units','points', ...
		'BackgroundColor',[1 1 1], ...
		'HorizontalAlignment','right', ...
		'Position',[144 219 186 32], ...
		'String','0', ...
		'Style','edit', ...
		'Tag','solution');
		h1 = uicontrol('Parent',h0, ...
		'Units','points', ...
		'Callback','calculette(''egal'')', ...
		'Position',[293 71 36 36], ...
		'String','=', ...
		'Tag','=');
		h1 = uicontrol('Parent',h0, ...
		'Units','points', ...
		'HorizontalAlignment','left', ...
		'Position',[145 257 185 28], ...
		'Style','text', ...
		'Tag','trouve');
		h1 = uicontrol('Parent',h0, ...
		'Units','points', ...
		'Callback','calculette(''nouveau'')', ...
		'Position',[231 31 111 22], ...
		'String','Nouveau', ...
		'Tag','Pushbutton2');
		calculette('nouveau')
		
	case 'egal'
		avant=get(gcf,'userdata');
		if ~isempty(avant.nb2),
			nb1=str2num(avant.nb1);
			nb2=str2num(avant.nb2);
			op=avant.op;
			switch op,
			case '/'
				res=nb1/nb2;
			case '*'
				res=nb1*nb2;
			case '-'
				res=nb1-nb2;
			case '+'
				res=nb1+nb2;
			otherwise
				res=0;
			end
			obj=findobj('tag','solution');
			set(obj,'string',num2str(res))
			obj=findobj('tag','trouve');
			avant=get(obj,'string');
			if (res>0) & (res <16),
				avant=str2num(avant);
				if ~ismember(res,avant),
					apres=[avant res];
					apres=sort(apres);
					set(obj,'string',num2str(apres))
				end
				a.nb1=num2str(res);
				a.op='';
				a.nb2='';
				set(gcf,'userdata',a)
			else
				a.nb1=num2str(res);
				a.op='';
				a.nb2='';
				set(gcf,'userdata',a)
			end
		
		elseif ~isempty(avant.nb1)|isempty(avant.op),
			nb1=str2num(avant.nb1);
			res=nb1;
			obj=findobj('tag','solution');
			set(obj,'string',num2str(res))
			obj=findobj('tag','trouve');
			avant=get(obj,'string');
			if (res>0) & (res <16),
				avant=str2num(avant);
				if ~ismember(res,avant),
					apres=[avant res];
					apres=sort(apres);
					set(obj,'string',num2str(apres))
				end
				a.nb1=num2str(res);
				a.op='';
				a.nb2='';
				set(gcf,'userdata',a)
			else
				a.nb1=num2str(res);
				a.op='';
				a.nb2='';
				set(gcf,'userdata',a)
			end
		
		end
	
	case 'virgule'
		obj=findobj('tag','solution');
		avant=get(obj,'string');
		if ~ismember('.',avant)
			next=[avant '.'];
			set(obj,'string',next);
			avant=get(gcf,'userdata');
			apres=avant;
			if isempty(avant.nb1),
				apres.nb1=nb;
				apres.nb2='';
				apres.op='';
			elseif isempty(avant.op),
				apres.nb1=next;
			else,
				apres.nb2=next;
			end
			set(gcf,'userdata',apres);
		end
	
	case 'chiffre'
		nb=get(gco,'string');
		obj=findobj('tag','solution');
		avant=get(obj,'string');
		if (avant=='0')&(nb=='0')
			next='0';
			set(obj,'string',next);
		else
			if avant=='0'
				next=nb;
			else
				next=[avant nb];
			end
			set(obj,'string',next);
			avant=get(gcf,'userdata');
			apres=avant;
			if isempty(avant.nb1),
				apres.nb1=nb;
				apres.nb2='';
				apres.op='';
			elseif isempty(avant.op),
				apres.nb1=next;
			else,
				apres.nb2=next;
			end
			set(gcf,'userdata',apres);
		end
	
	case 'plusmoins'
		obj=findobj('tag','solution');
		avant=str2num(get(obj,'string'));
		apres=-avant;
		set(obj,'string',num2str(apres))
		a=get(gcf,'userdata');
		if ~isempty(a.nb2),
			inter=str2num(a.nb2);
			a.nb2=num2str(-inter);
			set(gcf,'userdata',a)
		elseif ~isempty(a.nb1),
			inter=str2num(a.nb1);
			a.nb1=num2str(-inter);
			set(gcf,'userdata',a)
		end
	
	case 'operation'
		ch=get(gco,'string');
		apres=get(gcf,'userdata');
		apres.op=ch;
		apres.nb2='';
		set(gcf,'userdata',apres);
		obj=findobj('tag','solution');
		set(obj,'string','0')
		
	case 'nouveau'
		[unused,ind]=sort(rand(1,9));
		ind=ind(1:4);
		for i=1:9,
			obj=findobj('tag',num2str(i));
			if ismember(i,ind),
				set(obj,'enable','on')
				set(obj,'foregroundcolor','b')
			else,
				set(obj,'enable','off')
				set(obj,'foregroundcolor','k')
			end
		end
		[unused,ind]=sort(rand(1,4));
		ind=ind(1:2);
		op='/*-+';
		for i=1:4,
			obj=findobj('tag',op(i));
			if ismember(i,ind),
				set(obj,'enable','on')
				set(obj,'foregroundcolor','b')
			else,
				set(obj,'enable','off')
				set(obj,'foregroundcolor','k')
			end
		end
		obj=findobj('tag','+/-');
		if rand<0.33,
			set(obj,'enable','on')
			set(obj,'foregroundcolor','b')
		else,
			set(obj,'enable','off')
			set(obj,'foregroundcolor','k')
		end
		obj=findobj('tag','.');
		if rand<0.33,
			set(obj,'enable','on')
			set(obj,'foregroundcolor','b')
		else,
			set(obj,'enable','off')
			set(obj,'foregroundcolor','k')
		end
		obj=findobj('tag','trouve');
		set(obj,'string','')
		calculette('efface')
		
	case 'efface'
		obj=findobj('tag','solution');
		set(obj,'string','0');
		a.nb1='0';
		a.nb2='';
		a.op='';
		set(gcf,'userdata',a)
	end
end
