headius (owner)

Revisions

gist: 211619 Download_button fork
public
Public Clone URL: git://gist.github.com/211619.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
~/projects/jruby cat ../duby/examples/swing.duby
import javax.swing.JFrame
import javax.swing.JButton
import java.awt.event.ActionListener
 
frame = JFrame.new "Welcome to Duby"
frame.setSize 300, 300
frame.setVisible true
 
button = JButton.new "Press me"
frame.add button
frame.show
 
class AL; implements ActionListener
  def initialize; end
  def actionPerformed(event)
    JButton(event.getSource).setText "Duby Rocks!"
  end
end
 
button.addActionListener AL.new
 
Text only #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
~/projects/duby ➔ bin/dubyc -java examples/swing.duby
 
~/projects/duby ➔ cat examples/*.java
// Generated from examples/swing.duby
package examples;
public class AL extends java.lang.Object implements java.awt.event.ActionListener {
  public AL() {
  }
  public void actionPerformed(java.awt.event.ActionEvent event) {
    (javax.swing.JButton)(event.getSource()).setText("Duby Rocks!");
  }
}
// Generated from examples/swing.duby
package examples;
public class swing extends java.lang.Object {
  public static void main(java.lang.String[] argv) {
    javax.swing.JFrame frame = new javax.swing.JFrame("Welcome to Duby");
    frame.setSize(300, 300);
    frame.setVisible(true);
    javax.swing.JButton button = new javax.swing.JButton("Press me");
    frame.add(button);
    frame.show();
    button.addActionListener(new AL());
  }
}