CS1335 Java and Processing
  • CS 1335 Computer Science 1
  • Getting Started
    • Processing IDE
    • Java vs Javascript
    • Review: Processing, Functions
    • HSB Color Mode
      • HSB Color Wheel
        • Example Code
      • HSB Color Palette Tool
    • Recursion
      • Recursion Call-Stack
      • Example Code
        • Example Code Feb 5 S20
        • Feb 12 Code
  • Project 1
    • Subjective Modeling of Emotions
    • Emotions represented using color, form, space
      • Kandinsky Color - Emotion
      • Emotional Intelligence
    • Project 1: PShapes
      • Example Code
      • Inspiration
    • PShape with Cutout - Inner Contour
    • VertexShape - Recursion
    • Project 1: Recursive Drawing
    • Project 1: Programmatic Variations in Color
      • Recursion with rotate, scale
      • Plan Region Size, Color
    • Map Function
    • Transforms for Mirroring
    • Project1-Steps
  • Grid Based Designs
    • Computational Design
      • Generative Design
    • Artist: Victor Vasarely
    • Grid Pattern Design
    • 1D - Array of PShapes for Grid Layout
      • Truchet Tiling
      • Example Code
    • PShapes in Grid Regions
    • Grid Region Logic
    • Pattern Preview - Transforms: Translate & Scale
  • Project 2
    • Project 2 - 2D Arrays for Gradient Logic
      • 2D Array Grid with Labels
    • Grid Patterns using 2D Array Indexes: i, j
      • Example Class Code
    • lerpColor( ) and map( ) Functions
    • Demo Lerp Colors
    • 2D Arrays with lerpColor
    • Create PShape 2D Array
    • Function: Populate2DArray( )
    • Function: DisplayShapeMatrix()
    • Transforms for Position, Rotation, Scale of ShapeMatrix Elements
    • Project 2 - Steps
    • Animation for ShapeMatrix
      • Animation w/Noise
  • Object Oriented Programming
    • Introduction to Objects
    • OOP vs Data-Flow
    • Button States
    • Buttons as Objects
      • Button Class
    • Create Object Instances
    • Button Types
    • Modeling Buttons: States and Events
    • OOP - Inheritance
    • OOP - Polymorphism
    • Child-Class: PImageButton
    • PShape - SVG Objects
    • Menu of Buttons
    • ButtonGroup - Final Version
    • Slider Controller
    • UML Class Diagram
  • Project 3
    • Project 3 - Logic, Steps
    • Example Code S20
      • Code Wed Apr 1
      • Code Wed Apr 8 v1
      • Code Wed Apr 8 v2
      • Code Mon Apr 13
      • Code Wed Apr 15
      • Code Mon Apr 20
      • Code Wed Apr 22
      • Code Mon Apr 27
      • Code Wed Apr 29
    • Project 3 - Class Definitions
      • Button
      • PImageButton
      • ButtonGroup
      • Pattern
        • PShapes - SVG, Vertex Shapes
        • Setting Colors For Patterns
        • Pattern - With Child-PShapes
      • Slider
      • Particles
  • Java Syntax
    • Java Syntax
      • Typed-Variables
      • Float - Integer Conversion Errors
      • Modulus
      • Functions
      • Object Reference Data Types
      • Arrays
        • Class Example Code
      • Switch-Case Statement
      • Ternary Operator
      • Class
      • Learning Science
    • UML Class Diagram
    • Glossary
  • Resources and References
    • Resources
    • Random Inspiration
      • Ulm School
      • Heart-Mind, Mind, Body
      • Statistical Uncertainty
Powered by GitBook
On this page
  • Examples of Button-Types
  • Light-Switch - Default Behavior
  • Door Bell - reset( ) Method
  • Radio Buttons - ButtonGroup

Was this helpful?

  1. Object Oriented Programming

Button Types

Based on the simple button state example in the previous section, now we'll look at how we can use buttons to create user-interface behaviors in a customized drawing application.

Examples of Button-Types

Light-Switch - Default Behavior

In the previous example, the button had visually distinct on and off behavior-states, and it controlled 2 different color-states of an ellipse. This 2-state behavior button (ignoring hover-states), is similar to a wall light switch, where we can look at the switch and observe that it in 1 of 2 possible physical configuration states. We modeled this system with a 2-state finite state machine, where the states of the button were on or !on.

Door Bell - reset( ) Method

A door-bell type button behaves in a more instantaneous manner. The button can be thought of as generating an impulse-signal, which is sometimes referred to as a 'bang' in data-flow systems. This pulse can be used to trigger an event, but the button's state-change behavior isn't visually obvious. This is the type of button behavior that we'll use in our drawing application to control clearing the canvas. The main difference between this button and the light switch button is that the button state is primarily used to control another object, so that the button itself doesn't display 2-state behavior. For these buttons, it's important to remember to include code to switch the button state to !on once it's done triggering the controlled event.

We'll create a reset method for the Button class, when we call reset, we'll have a button reset: selected=false, curColor = defaultColor;

Radio Buttons - ButtonGroup

Radio Buttons, like those used to select a car's radio station or used in web pages, represent another functional style of button behavior. In this case, several buttons are linked together as a group, which is controlled by a single 'activeButton' state, where the currently selected button represents the active state for the system. For our drawing application, we'll use this type of button to allow the user to select the drawing tool (either one of several patterns or the eraser).

We'll write a class: ButtonGroup to manage and coordinate behavior of a group of Button objects, the ButtonGroup will keep track of the current, selected button. When one Button is selected, it will make sure all other buttons have their select value set to false.

PreviousCreate Object InstancesNextModeling Buttons: States and Events

Last updated 5 years ago

Was this helpful?