How do I get a value returned as opposed to println which I can not read, in the following script? I am using Groovy inside Filemaker so need an explicit return 'answer' i.e. the password or a TRUE, and I do not seem to understand how to make the code wait till it finally gets to the point where the correct password is entered.
import groovy.swing.SwingBuilder
import java.awt.event.ActionListener
import java.awt.event.ActionEvent
import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE
count = 2
def answer
SwingBuilder.build{
frame( id:'root', title:'Enter your PASSWORD', location:[100,100], show:true, pack:true, defaultCloseOperation:DISPOSE_ON_CLOSE){
//lookAndFeel 'nimbus'
flowLayout()
label('Password')
passwordField(id:'pass', columns:12)
button('click', actionPerformed:{
ActionEvent e->
if (pass.text == 'password'){
optionPane().showMessageDialog( root, 'OK')
//RETURN something at this point only when I get here
dispose()
} else if (count == 1) {
optionPane().showMessageDialog(root, 'INCORRECT PASSWORD\nPROCEDURE HALTED', 'PASSWORD', 2)
dispose()
} else {
count--
message = count ==1 ?'try':'tries'
optionPane().showMessageDialog(root, "${count} ${message} left", 'NOT VALID', 0)
}// end if
pass.text=''
}// end action
)// end button
}
}