Forum: JRuby JCheckBox Checking

Cf25fbf53c67e27d95845e77e949b56f?d=identicon&s=25 Stuart Clarke (sclarke)
on 2014-01-15 13:47
Hi all,

This one has me beaten. The code follows below.

I am creating a GUI, which contains a single checkbox (more soon) and a
Go button.

All I am trying to do at this stage is:
1. Create a GUI with checkbox - DONE
2. Put a tick in the box & click go - DONE
3. After licking go, I want to test if the checkbox is selected and if
it, output "Box was ticked" - this just does not happen

Can anyone perhaps spot the stupid mistake I am making?

include Java

module Js
  import java.awt.GridLayout
  include_package "javax.swing"
  include_package "javax.swing.JFrame"
  include_package "javax.swing.JButton"
  include_package "javax.swing.JPanel"
  include_package "javax.swing.JOptionPane"
  include_package "javax.swing.JPane"
  include_package "javax.swing.JScrollPane"
  include_package "javax.swing.JCheckBox"
end

panel = Js::JPanel.new
panel.setLayout GridLayout.new 10, 2

eCheckBox = Js::JCheckBox.new
elbl = Js::JLabel.new(“Everything");

panel.add(eCheckBox);
panel.add(elbl);

goButton = Js::JButton.new("Run")
panel.add goButton

frame = Js::JFrame.new()
frame.add panel
frame.pack
frame.setTitle(“GUI Checkbox")
frame.setResizable false
frame.setLocationRelativeTo nil

goButton.addActionListener do |e|
  if EVTCheckBox.isSelected()
    puts “Box was ticked"
  end
  frame.dispose()
end

frame.setVisible true
F76f3e46a94eb011d85d14bf54425950?d=identicon&s=25 roger (Guest)
on 2014-01-15 14:40
(Received via mailing list)
It seems as if EVTCheckBox is not declared but eCheckBox is.

Regards
  Roger

Am 15.01.2014 um 13:47 schrieb Stuart Clarke <lists@ruby-forum.com>:
Cf25fbf53c67e27d95845e77e949b56f?d=identicon&s=25 Stuart Clarke (sclarke)
on 2014-01-15 14:58
Very sorry thats a typo, below is correct.

goButton.addActionListener do |x|
  if eCheckBox.isSelected()
    puts “Box was ticked"
  end
  frame.dispose()
end
Cf25fbf53c67e27d95845e77e949b56f?d=identicon&s=25 Stuart Clarke (sclarke)
on 2014-01-15 15:48
Stuart Clarke wrote in post #1133247:
> Very sorry thats a typo, below is correct.
>
> goButton.addActionListener do |x|
>   if eCheckBox.isSelected()
>     puts “Box was ticked"
>   end
>   frame.dispose()
> end

I should add - even with the fixed typo I still have no success.
Cf25fbf53c67e27d95845e77e949b56f?d=identicon&s=25 Stuart Clarke (sclarke)
on 2014-01-15 16:21
I have figured it out - its a issue with outputting to console.
C37cb1a6a19e23f067aae6ccb2d0de4b?d=identicon&s=25 Manuel Ramos Caro (Guest)
on 2014-01-15 20:58
(Received via mailing list)
Hi

I program with Jruby  and Swing for fun.

You can take a look here ...

http://sourceforge.net/projects/rmldonkey/

Making this changes and after testing your code it works fine...

Reggards

Manuel Ramos Caro


include Java

panel = javax.swing.JPanel.new
panel.setLayout java.awt.GridLayout.new 10, 2

eCheckBox = javax.swing.JCheckBox.new
elbl = javax.swing.JLabel.new("Everything");

panel.add(eCheckBox);
panel.add(elbl);

goButton = javax.swing.JButton.new("Run")
panel.add goButton

frame = javax.swing.JFrame.new
frame.add panel
frame.pack
frame.setTitle("GUI Checkbox")
frame.setResizable false
frame.setLocationRelativeTo nil

goButton.addActionListener do |e|
  if eCheckBox.isSelected()
    puts "Box was ticked"
  else
    puts "Box was not ticked"
  end
  frame.dispose()
end

frame.setVisible true


El 15/01/14 16:21, Stuart Clarke escribi??:
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.