Example #1
0
    /**
     * Sets the pressed state of the toggle button.
     */
    /*public*/ void setPressed(boolean b) {
        if ((isPressed() == b) || !isEnabled()) {
            return;
        }

        if (b == false && isArmed()) {
            setSelected(!this.isSelected());
        }

        if (b) {
            stateMask |= PRESSED;
        } else {
            stateMask &= ~PRESSED;
        }

        fireStateChanged();

        if(!isPressed() && isArmed()) {
            int modifiers = 0;
            AWTEvent currentEvent = EventQueue.getCurrentEvent();
            if (currentEvent instanceof InputEvent) {
                modifiers = ((InputEvent)currentEvent).getModifiers();
            } else if (currentEvent instanceof ActionEvent) {
                modifiers = ((ActionEvent)currentEvent).getModifiers();
            }
            fireActionPerformed(
                new ActionEvent(this, ActionEvent.ACTION_PERFORMED,
                                getActionCommand(),
                                EventQueue.getMostRecentEventTime(),
                                modifiers));
        }

    }
Example #2
0
int main(void)
{
    GWindow window = newGWindow(320, 240);
    GButton button = newGButton("button");
    setActionCommand( button, "check" );
    addToRegion(window, button, "SOUTH");
    
    while( true )
    {
        GActionEvent event = waitForEvent( ACTION_EVENT );
        
        if( getEventType(event) == WINDOW_CLOSED )
        {

            break;
        }
        else if( strcmp( getActionCommand(event) , "click") == 0 )
        {
            printf("button was clicked\n");
        }
    }
    
    closeGWindow(window);
    return 0;
}
Example #3
0
int main(void)
{
    // instantiate window
    GWindow window = newGWindow(320, 240);

    // instantiate button
    GButton button = newGButton("Button");
    setActionCommand(button, "click");

    // add button to southern region of window
    addToRegion(window, button, "SOUTH");

    // listen for events
    while (true)
    {
        // wait for event
        GActionEvent event = waitForEvent(ACTION_EVENT);

        // if window was closed
        if (getEventType(event) == WINDOW_CLOSED)
        {
            break;
        }

        // if action command is "click"
        if (strcmp(getActionCommand(event), "click") == 0)
        {
            printf("button was clicked\n");
        }
    }

    // that's all folks
    closeGWindow(window);
    return 0;
}
Example #4
0
int main(void)
{
    // instantiate window
    GWindow window = newGWindow(320, 240);

    // instantiate slider
    addToRegion(window, newGLabel("0"), "SOUTH");
    GSlider slider = newGSlider(0, 100, 50);
    setActionCommand(slider, "slide");
    addToRegion(window, slider, "SOUTH");
    addToRegion(window, newGLabel("100"), "SOUTH");

    // listen for events
    while (true)
    {
        // wait for event
        GActionEvent event = waitForEvent(ACTION_EVENT);

        // if window was closed
        if (getEventType(event) == WINDOW_CLOSED)
        {
            break;
        }

        // if action command is "slide"
        if (strcmp(getActionCommand(event), "slide") == 0)
        {
            printf("slider was slid to %i\n", getValue(slider));
        }
    }

    // that's all folks
    closeGWindow(window);
    return 0;
}
Example #5
0
int main(void)
{
    // instantiate window
    GWindow window = newGWindow(320, 240);
    
    GCheckBox checkBox = newGCheckBox("I agree");
    setActionCommand(checkBox, "check");
    addToRegion(window, checkBox, "SOUTH");
    
    while (true)
    {
        GActionEvent event = waitForEvent(ACTION_EVENT);
        
        if (getEventType(event) == WINDOW_CLOSED)
        {
            break;
        }
        
        if (strcmp(getActionCommand(event), "check") == 0)
        {
            if (isSelected(checkBox))
            {
                printf("Checkbox was checked\n");
            }
            else
            {
                printf("Checkbox was unchecked\n");
            }
        }
    }
    
    closeGWindow(window);
    return 0;
}
Example #6
0
o/**
 * slider.c
 *
 * David J. Malan
 * [email protected]
 *
 * Demonstrates a slider.
 */

// standard libraries
#include <stdio.h>
#include <string.h>

// Stanford Portable Library
#include <spl/gevents.h>
#include <spl/ginteractors.h>
#include <spl/gwindow.h>

int main(void)
{
    // instantiate window
    GWindow window = newGWindow(320, 240);

    // instantiate slider
    addToRegion(window, newGLabel("0"), "SOUTH");
    GSlider slider = newGSlider(0, 100, 50);
    setActionCommand(slider, "slide");
    addToRegion(window, slider, "SOUTH");
    addToRegion(window, newGLabel("100"), "SOUTH");

    // listen for events
    while (true)
    {
        // wait for event
        GActionEvent event = waitForEvent(ACTION_EVENT);

        // if window was closed
        if (getEventType(event) == WINDOW_CLOSED)
        {
            break;
        }

        // if action command is "slide"
        if (strcmp(getActionCommand(event), "slide") == 0)
        {
            printf("slider was slid to %i\n", getValue(slider));
        }
    }

    // that's all folks
    closeGWindow(window);
    return 0;
}