Simple windowed application: Difference between revisions
Content added Content deleted
No edit summary |
Walterpachl (talk | contribs) (→{{header|ooRexx}}: significantly shortened) |
||
Line 1,154: | Line 1,154: | ||
=={{header|ooRexx}}== |
=={{header|ooRexx}}== |
||
<lang oorexx>/* REXX *************************************************************************************** |
|||
<lang oorexx>#!/usr/bin/rexx |
|||
* 18.06.2014 Walter Pachl shortened from Rony Flatscher's bsf4oorexx (see sourceforge) samples |
|||
/* |
|||
* Look there for ShowCount.rxj |
|||
* bsf4oorexx lets the ooRexx program use Java classes |
|||
**********************************************************************************************/ |
|||
Invoke: "rexx Showcount.rxj" |
|||
or |
|||
"rexxj Showcount.rxj" (Windows) |
|||
or |
|||
"rexxj.sh Showcount.rxj" (Unix) |
|||
Purpose: create a little resizable window with a push button to count and reveal |
|||
the number of times the button was pressed |
|||
Needs: Apache's "Bean Scripting Framework" (BSF), part of the BSF4ooRexx distribution |
|||
Date: 2001-04-30 Rony Flatscher presented this at the 12th International Rexx Symposium |
|||
Changed: 2005-12-28, added Apache license |
|||
2008-08-23, ---rgf, if using BSF.CLS, then do not use BSF() directly (or |
|||
remove the first three chars from its result string) |
|||
2009-07-03, ---Walter Pachl add help and improve a little bit |
|||
2010-05-16, rgf, - adapting example to take full advantage of BSF4ooRexx |
|||
- replacing bsf.addEventListener[WithEventObject] with a Rexx event handler |
|||
2012-06-09, rgf, - inhibit callbacks from Java after Rexx ends (if Rexx loaded Java) |
|||
2014-06-17 Walter Pachl copied from bsf4oorexx samples to rosettacode.org |
|||
*/ |
|||
If arg(1)='?' Then Do |
|||
Parse Source source |
|||
Say source |
|||
Say 'This program displays a window with a button at its bottom' |
|||
Say 'In the middle of this window you will be told' |
|||
Say ' how often you have pressed this very button.' |
|||
Exit |
|||
End |
|||
hi=BsfInvokedBy() |
|||
Select |
|||
When hi=1 then say "This Rexx program was invoked by Java!" |
|||
When hi=2 then say "This Rexx program was invoked by Rexx, JVM loaded by Rexx!" |
|||
Otherwise Do; say "No JVM present, we got troubles ..." |
|||
Exit |
|||
End |
|||
End |
|||
-- Create a userData directory |
|||
userData=.directory~new -- a directory which will be passed to Rexx with the event |
userData=.directory~new -- a directory which will be passed to Rexx with the event |
||
Line 1,207: | Line 1,166: | ||
rexxCloseEH =.RexxCloseAppEventHandler~new -- Rexx event handler |
rexxCloseEH =.RexxCloseAppEventHandler~new -- Rexx event handler |
||
-- Create Java RexxProxy for the Rexx event handler |
-- Create Java RexxProxy for the Rexx event handler |
||
rpCloseEH=BsfCreateRexxProxy(rexxCloseEH, |
rpCloseEH=BsfCreateRexxProxy(rexxCloseEH,,"java.awt.event.WindowListener" ) |
||
win~addWindowListener(rpCloseEH) -- add RexxProxy event handler |
win~addWindowListener(rpCloseEH) -- add RexxProxy event handler |
||
-- create a Java push button |
-- create a Java push button |
||
but=.bsf~new("java.awt.Button", |
but=.bsf~new("java.awt.Button","Press me!") |
||
-- Create a RexxProxy for the button Rexx event handler |
-- Create a RexxProxy for the button Rexx event handler |
||
rp=BsfCreateRexxProxy(.RexxShowCountEventHandler~new, |
rp=BsfCreateRexxProxy(.RexxShowCountEventHandler~new,userData,"java.awt.event.ActionListener") |
||
but~addActionListener(rp) -- add RexxProxy event handler |
but~addActionListener(rp) -- add RexxProxy event handler |
||
-- create a Java label, |
lab=.bsf~new("java.awt.Label") -- create a Java label,set it to show the text centered |
||
⚫ | |||
lab=.bsf~new("java.awt.Label") |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
win ~~add("Center", |
win ~~add("Center",lab) ~~add("South",but) -- add the label and the button to the frame |
||
win ~~pack -- now calculate all widget dimensions |
win ~~pack -- now calculate all widget dimensions |
||
call enlargeWidth win,but, |
call enlargeWidth win,but,120 -- enlarge the width of the frame and the button |
||
win ~~setVisible(.true) ~~toFront -- make frame visible and move it to the front |
win ~~setVisible(.true) ~~toFront -- make frame visible and move it to the front |
||
userData~i=0 -- set counter to 0 |
userData~i=0 -- set counter to 0 |
||
rexxCloseEH~waitForExit -- wait until we are allowed to end the program |
rexxCloseEH~waitForExit -- wait until we are allowed to end the program |
||
-- if Java was loaded by Rexx, |
-- if Java was loaded by Rexx,then terminate Java's RexxEngine to inhibit callbacks from Java |
||
call BSF.terminateRexxEngine |
call BSF.terminateRexxEngine |
||
::requires BSF.CLS -- get Java support |
::requires BSF.CLS -- get Java support |
||
Line 1,240: | Line 1,197: | ||
/* enlarge the width of the frame and of the button without using a layout manager */ |
/* enlarge the width of the frame and of the button without using a layout manager */ |
||
::routine enlargeWidth |
::routine enlargeWidth |
||
use arg win, |
use arg win,but,addToWidth |
||
⚫ | |||
⚫ | |||
say "---" |
|||
⚫ | |||
say "win_size (standard):" win~getSize~toString |
|||
say "but_size (standard):" but~getSize~toString |
|||
⚫ | |||
⚫ | |||
⚫ | |||
say "win_size (enlarged):" win~getSize~toString |
|||
say "but_size (enlarged):" but~getSize~toString |
|||
say "---" |
|||
/* ------------------------------------------------------------------------ */ |
/* ------------------------------------------------------------------------ */ |
||
/* Rexx event handler to set "close app" indicator */ |
/* Rexx event handler to set "close app" indicator */ |
||
::class RexxCloseAppEventHandler |
::class RexxCloseAppEventHandler |
||
::method init -- constructor |
::method init -- constructor |
||
expose closeApp |
expose closeApp |
||
closeApp = .false -- if set to .true, then it is safe to close the app |
closeApp = .false -- if set to .true, then it is safe to close the app |
||
::attribute closeApp -- indicates whether app should be closed |
::attribute closeApp -- indicates whether app should be closed |
||
::method unknown -- intercept unhandled events, |
::method unknown -- intercept unhandled events,do nothing |
||
::method windowClosing -- event method (from WindowListener) |
::method windowClosing -- event method (from WindowListener) |
||
expose closeApp |
expose closeApp |
||
closeApp=.true -- indicate that the app should close |
closeApp=.true -- indicate that the app should close |
||
::method waitForExit -- method blocks until attribute is set to .true |
::method waitForExit -- method blocks until attribute is set to .true |
||
expose closeApp |
expose closeApp |
||
guard on when closeApp=.true |
guard on when closeApp=.true |
||
/* ------------------------------------------------------------------------ */ |
/* ------------------------------------------------------------------------ */ |
||
Line 1,279: | Line 1,225: | ||
::class RexxShowCountEventHandler |
::class RexxShowCountEventHandler |
||
::method actionPerformed |
::method actionPerformed |
||
use arg eventObject, |
use arg eventObject,slotDir |
||
call showCount slotDir~userData |
call showCount slotDir~userData |
||
/* ------------------------------------------------------------------------ */ |
/* ------------------------------------------------------------------------ */ |
||
::routine ShowCount -- |
::routine ShowCount -- increment counter and show text |
||
use arg userData |
use arg userData |
||
⚫ | |||
Select -- construct text part |
|||
⚫ | |||
⚫ | |||
⚫ | |||
Select |
|||
When i= |
When userData~i=3 Then how_often='three times' |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
End |
End |
||
userData~label~setText("Button was pressed" |
userData~label~setText("Button was pressed" how_often) -- display text</lang> |
||
Output: |
|||
<pre>rexx ShowCount.rxj |
|||
This Rexx program was invoked by Rexx, JVM loaded by Rexx! |
|||
--- |
|||
win_size (standard): java.awt.Dimension[width=180,height=91] |
|||
but_size (standard): java.awt.Dimension[width=162,height=23] |
|||
win_size (enlarged): java.awt.Dimension[width=270,height=91] |
|||
but_size (enlarged): java.awt.Dimension[width=252,height=23] |
|||
---</pre> |
|||
=={{header|Oz}}== |
=={{header|Oz}}== |