gui matlab help

tmh88tmh88 Pittsburgh / Athens, OH
edited May 2007 in Science & Tech
Hey, I'm messing around gui for a digital clock that I'm making in matlab and I'm stuck. I have drop down file with 'Exit' in it. I'm obviously trying to make it so when you select exit, the figure closes, but I can't figure it out. Any suggestions to get the exit button working?

heres what I have so far. The first block of code is the working one just so you can see what it looks like. To exit you have to use ctl+C. The second code block is what I think it should be, but doesn't work.
HFIG = figure('Name', 'Digital Clock', 'Numbertitle', 'off', 'Position', [400 300 350 100], ...
    'Menubar', 'none', 'Resize', 'on');
 filemenu = uimenu('Label', 'File');
uimenu(filemenu, 'Label', 'Exit', 'Callback', [mfilename, '(''EXIT'')']);

th = text(0.5,0.5,'xxx') ; % retrieve handle
set(gca,'visible','off') ;
set(th,'visible','on','horizontalalignment','center')
while(1),
  c1 = datestr(clock,13) ;
  set(th,'string',c1);% set the string
  pause(.1) ; % break with ctrl-C
  end  


and heres the code for what I think it should be. Doesnt work though :(
if narg < 1
HFIG = figure('Name', 'Digital Clock', 'Numbertitle', 'off', 'Position', [400 300 350 100], ...
    'Menubar', 'none', 'Resize', 'on');
 filemenu = uimenu('Label', 'File');
uimenu(filemenu, 'Label', 'Exit', 'Callback', [mfilename, '(''EXIT'')']);

th = text(0.5,0.5,'xxx') ; % retrieve handle
set(gca,'visible','off') ;
set(th,'visible','on','horizontalalignment','center')
while(1),
  c1 = datestr(clock,13) ;
  set(th,'string',c1);% set the string
  pause(.1) ; % break with ctrl-C
  
else
  switch cmd
          case 'EXIT'
          close(HFIG);
  end
end

Comments

  • tmh88tmh88 Pittsburgh / Athens, OH
    edited May 2007
    bump, sorry. I'm still stuck and I hate to start on programs and then not be able to fnish them.
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited May 2007
    Chat with me on AIM. I have questions...
  • tmh88tmh88 Pittsburgh / Athens, OH
    edited May 2007
    thanks a lot for the help shwaip

    heres the updated code that works now. Also made the font larger.
    done = 0;
    HFIG = figure('Name', 'Digital Clock', 'Numbertitle', 'off', 'Position', [400 300 350 100], ...
        'Menubar', 'none', 'Resize', 'on');
     filemenu = uimenu('Label', 'File');
    uimenu(filemenu, 'Label', 'Exit', 'Callback', 'done=1;');
    
    th = text(0.5,0.5,'xxx','FontSize', 35) ; % retrieve handle
    set(gca,'visible','off') ;
    set(th,'visible','on','horizontalalignment','center')
    while(~done),
        c1 = datestr(clock,13) ;
        set(th,'string',c1);% set the string
        pause(.1) ; % break with ctrl-C
    end
    close(HFIG);
    
  • tmh88tmh88 Pittsburgh / Athens, OH
    edited May 2007
    Alright I have everything how I want it, except for one thing.... I added buttons that show the hour of the other time zones. When you press them, the number appears on the screen. Anyway I want to be able to have a reset button, which starts the program over and clears those numbers. Anyone have some advice for it. Heres the code that I have
    % This program is of a clock that shows the current time in other zones of
    % the US. The large main numbers is the current time in the Easter timezone. When you press
    % the other buttons for the zones(pacific,western,central), it shows the
    % hour of that time(not the minutes). This program also has a date feature. 
    
    clear1 = 0;
    done = 0;
    about = 0;
    thedate = 0;
    pacific = 0;
    mountain = 0;
    central = 0;
    HFIG = figure('Name', 'Digital Clock', 'Numbertitle', 'off', 'Position', [450 300 400 100], ...
        'Menubar', 'none', 'Resize', 'on');
     filemenu = uimenu('Label', 'File');
     aboutmenu = uimenu('Label', 'About');
    uimenu(filemenu, 'Label', 'Exit', 'Callback', 'done = 1;');
    uimenu(filemenu, 'Label', 'Clear', 'Callback', 'clear1 =1;');
    uimenu(aboutmenu, 'Label', 'About', 'Callback', 'about = 1;');
    uicontrol(HFIG, 'Style', 'PushButton', 'Position', [10 10 75 25], ...
       'String', 'Date', 'Callback', 'thedate = 1');
    uicontrol(HFIG, 'Style', 'Pushbutton', 'Position', [85 10 75 25], ...
       'String', 'Done', 'Callback', 'done = 1;');
    uicontrol(HFIG, 'Style', 'Pushbutton', 'Position', [160 10 75 25],...
       'string', 'Central Time','Callback', 'central = 1;');
    uicontrol(HFIG, 'Style', 'Pushbutton', 'Position', [235 10 75 25],...
       'string', 'Mountain Time','Callback','mountain = 1;');
    uicontrol(HFIG, 'Style', 'Pushbutton', 'Position', [310 10 75 25],...
        'string', 'pacific','Callback','pacific = 1;');
    th = text(0.5,0.5,'xxx','FontSize', 35) ; % retrieve handle
    set(gca,'visible','off') ;
    set(th,'visible','on','horizontalalignment','center')
    
    while(~done),
        c1 = datestr(clock,14) ;
        set(th,'string',c1);% set the string
        pause(.1) ; % break with ctrl-
        
        if(thedate),
            msgbox( DATE , 'Date');
            thedate=0;                
    
        else if(central),
            a = str2num(datestr(now,'HH'))
            b = a-2+1
            if b>12
                b = b-12
            end
            tg= text(.5,.9,'xxx','Fontsize',10')
            set(tg,'string',b);   
            central = 0;
            
        else if(mountain),
            c = str2num(datestr(now,'HH'))
            d = c-3+1
            if d>12
                d = d-12
            end
            tg= text(.7,.9,'xxx','Fontsize',10')
            set(tg,'string',d); 
            mountain = 0;
       
            else if(pacific),
            e = str2num(datestr(now,'HH'))
            f = e-4+1
            if f>12
                f = f-12
            end
            tg= text(.9,.9,'xxx','Fontsize',10')
            set(tg,'string',f);
            pacific = 0;
      
                  
            else  if(about),
            load gong 
            wavplay(y)
            msgbox( 'This program displays the current time in the eastern zone. It also shows the hour of the the 3 other time zones when you press the according buttons. This was writting by Trevor Holloway and Charles Silcott for EE 103', 'About message box');
            about = 0;
            
            if (clear1);
                
                clear1 = 0;
        end
        end
        end
        end
        end
        end
    end
    close(HFIG);
    
Sign In or Register to comment.