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
on 2014-01-15 13:47
on 2014-01-15 14:40
It seems as if EVTCheckBox is not declared but eCheckBox is. Regards Roger Am 15.01.2014 um 13:47 schrieb Stuart Clarke <firstname.lastname@example.org>:
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
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.
on 2014-01-15 16:21
I have figured it out - its a issue with outputting to console.
on 2014-01-15 20:58
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??: