headius (owner)

Revisions

gist: 208911 Download_button fork
public
Public Clone URL: git://gist.github.com/208911.git
Embed All Files: show embed
1. Duby source #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
2. Bytecode output #
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Compiled from "swing.duby"
public class swing extends java.lang.Object{
public static void main(java.lang.String[]);
  Code:
   0: new #9; //class javax/swing/JFrame
   3: dup
   4: ldc #11; //String Welcome to Duby
   6: invokespecial #15; //Method javax/swing/JFrame."<init>":(Ljava/lang/String;)V
   9: astore_1
   10: aload_1
   11: sipush 300
   14: sipush 300
   17: invokevirtual #19; //Method javax/swing/JFrame.setSize:(II)V
   20: aload_1
   21: iconst_1
   22: invokevirtual #23; //Method javax/swing/JFrame.setVisible:(Z)V
   25: new #25; //class javax/swing/JButton
   28: dup
   29: ldc #27; //String Press me
   31: invokespecial #28; //Method javax/swing/JButton."<init>":(Ljava/lang/String;)V
   34: astore_2
   35: aload_1
   36: aload_2
   37: invokevirtual #32; //Method javax/swing/JFrame.add:(Ljava/awt/Component;)Ljava/awt/Component;
   40: pop
   41: aload_1
   42: invokevirtual #36; //Method javax/swing/JFrame.show:()V
   45: aload_2
   46: new #38; //class AL
   49: dup
   50: invokespecial #40; //Method AL."<init>":()V
   53: invokevirtual #44; //Method javax/swing/JButton.addActionListener:(Ljava/awt/event/ActionListener;)V
   56: return
 
public swing();
  Code:
   0: aload_0
   1: invokespecial #51; //Method java/lang/Object."<init>":()V
   4: return
 
}
 
Compiled from "swing.duby"
public class AL extends java.lang.Object implements java.awt.event.ActionListener{
public AL();
  Code:
   0: aload_0
   1: invokespecial #11; //Method java/lang/Object."<init>":()V
   4: return
 
public void actionPerformed(java.awt.event.ActionEvent);
  Code:
   0: aload_1
   1: invokevirtual #21; //Method java/awt/event/ActionEvent.getSource:()Ljava/lang/Object;
   4: checkcast #23; //class javax/swing/JButton
   7: ldc #25; //String Duby Rocks!
   9: invokevirtual #29; //Method javax/swing/JButton.setText:(Ljava/lang/String;)V
   12: return
 
}
 
3. (J)Ruby equivalent #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import javax.swing.JFrame
import javax.swing.JButton
import java.awt.event.ActionListener
 
frame = JFrame.new "Welcome to Duby"
frame.set_size 300, 300
frame.visible = true
 
button = JButton.new "Press me"
frame.add button
frame.show
 
class AL; include ActionListener
  def actionPerformed(event)
    event.source.text = "Duby Rocks!"
  end
end
 
button.add_action_listener AL.new