jj logo
Take a quick tour of JJ
Teacher Registration
Student Registration
Industry Registration
Guest Registration
Some Humor
Friends
Quotes


Name
Password
School


..
Class ButtonReplyPattern

-- If using buttons and text areas instead of 
--  Input and Output(ln) commands
-- import JJGui instead of JJIO
Import JJGui  

-- Your class can have any name except your loginID
Class ButtonReplyPattern

--Name: ?? --replace the ?? with your loginId

-- 6 buttons and 1 text area are placed into 2 panels
Boxes b1,b2,b3,b4,b5,b6  ofClass JJButton are private
Box   ta                 ofClass JJTextArea is private
Box   gp                 ofClass JJGridPanel is private
Box   bp                 ofClass JJBorderPanel is private

-- A Constructor is used to initialize class-level boxes
Constructor ButtonReplyPattern(none) is public
 New b1 ofClass JJButton     with ("red")
 New b2 ofClass JJButton     with ("orange")
 New b3 ofClass JJButton     with ("yellow")
 New b4 ofClass JJButton     with ("green")
 New b5 ofClass JJButton     with ("blue")
 New b6 ofClass JJButton     with ("purple")
 --Requesting 3 lines and 10 columns for the text area
 New ta ofClass JJTextArea   with ("guess a color",3,10) 
 -- A grid of 2 down and 3 across to place buttons, text areas and other panels
 New gp ofClass JJGridPanel with (2,3) 
 -- Instead of a grid, a frame with a north, east, south, west and center
 New bp ofClass JJBorderPanel 
EndConstructor ButtonReplyPattern

 Routine ActsAsMain(none) is public
   Start -- tells JJ that this is the "main"

   Call gp.add with (b1)
   Call gp.add with (b2)
   Call gp.add with (b3)
   Call gp.add with (b4)
   Call gp.add with (b5)
   Call gp.add with (b6) -- 6 buttons added to the grid panel
   Call bp.add with ("South", ta) -- SOUTH area takes what it needs
   Call bp.add with ("Center", gp) -- CENTER area takes whatever is left
   Call bp.jjShowAsMainPanel -- specify this panel is the main one
 EndRoutine ActsAsMain

-- All names that start with "jj" or "JJ" are special names in JJ.
-- jjHandleButtonPress is a routine that is passed the JJButton
--  that was pressed.
-- jjHandleButtonPress is called whenever a button is pressed.
-- You must have one routine named jjHandleButtonPress if importing JJGui.
Routine jjHandleButtonPress(b) is public
 Slot b ofClass JJButton

 -- check which button was pressed, and issue a response
 If (b == b1) then
    Call ta.setText with ("Guess again")
 ElseIf (b == b2) then
    Call ta.setText with ("Guess yet again")
 ElseIf (b == b3) then
    Call ta.setText with ("Guess once again")
 ElseIf (b == b4) then
    Call ta.setText with ("Guess again until you get it")
 ElseIf (b == b5) then
    Call ta.setText with ("Guess again one last time")
 ElseIf (b == b6) then
    Call ta.setText with ("You win")
 EndIf
EndRoutine jjHandleButtonPress

EndClass ButtonReplyPattern
Return to
    JJ
home page
..