swing_paradise 0.1.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of swing_paradise might be problematic. Click here for more details.

Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +1557 -0
  3. data/doc/README.gen +1510 -0
  4. data/lib/swing_paradise/autoinclude.rb +3 -0
  5. data/lib/swing_paradise/awt/README.md +1 -0
  6. data/lib/swing_paradise/awt/color.rb +45 -0
  7. data/lib/swing_paradise/base_module/base_module.rb +993 -0
  8. data/lib/swing_paradise/classes +1 -0
  9. data/lib/swing_paradise/examples/001_quit_button_example.rb +55 -0
  10. data/lib/swing_paradise/examples/002_text_area_example.rb +55 -0
  11. data/lib/swing_paradise/examples/003_combo_box_example.rb +57 -0
  12. data/lib/swing_paradise/examples/004_jpanel_left_bound_example.rb +41 -0
  13. data/lib/swing_paradise/examples/005_box_layout_example.rb +39 -0
  14. data/lib/swing_paradise/examples/006_frame_example.rb +33 -0
  15. data/lib/swing_paradise/examples/007_textarea_responding_to_enter_key_example.rb +28 -0
  16. data/lib/swing_paradise/examples/008_scrolled_window_example.rb +41 -0
  17. data/lib/swing_paradise/examples/009_font_size_example.rb +39 -0
  18. data/lib/swing_paradise/examples/010_counter_example.rb +183 -0
  19. data/lib/swing_paradise/examples/011_button_with_image_example.rb +58 -0
  20. data/lib/swing_paradise/examples/012_quit_on_escape_key_being_pressed.rb +37 -0
  21. data/lib/swing_paradise/examples/013_simple_box_example.rb +38 -0
  22. data/lib/swing_paradise/examples/014_mouse_events_example.rb +41 -0
  23. data/lib/swing_paradise/examples/015_menu_example.rb +77 -0
  24. data/lib/swing_paradise/examples/016_file_chooser_example.rb +96 -0
  25. data/lib/swing_paradise/examples/017_buttons_example.rb +56 -0
  26. data/lib/swing_paradise/examples/018_colour_chooser_example.rb +51 -0
  27. data/lib/swing_paradise/examples/019_jeditorpane_example.rb +61 -0
  28. data/lib/swing_paradise/examples/020_table_example.rb +77 -0
  29. data/lib/swing_paradise/examples/021_jsplitpane_example.rb +66 -0
  30. data/lib/swing_paradise/examples/022_drawing_oval_example.rb +51 -0
  31. data/lib/swing_paradise/examples/023_show_message_dialog_example.rb +57 -0
  32. data/lib/swing_paradise/java_classes/border_factory/border_factory.rb +19 -0
  33. data/lib/swing_paradise/java_classes/box/box.rb +72 -0
  34. data/lib/swing_paradise/java_classes/button +1 -0
  35. data/lib/swing_paradise/java_classes/checkbox +1 -0
  36. data/lib/swing_paradise/java_classes/combobox +1 -0
  37. data/lib/swing_paradise/java_classes/default_table_model/default_table_model.rb +18 -0
  38. data/lib/swing_paradise/java_classes/frame +1 -0
  39. data/lib/swing_paradise/java_classes/jbutton/jbutton.rb +199 -0
  40. data/lib/swing_paradise/java_classes/jcheckbox/jcheckbox.rb +28 -0
  41. data/lib/swing_paradise/java_classes/jcombobox/jcombobox.rb +31 -0
  42. data/lib/swing_paradise/java_classes/jcomponent/jcomponent.rb +253 -0
  43. data/lib/swing_paradise/java_classes/jeditorpane/jeditorpane.rb +23 -0
  44. data/lib/swing_paradise/java_classes/jfilechooser/jfilechooser.rb +22 -0
  45. data/lib/swing_paradise/java_classes/jframe/jframe.rb +319 -0
  46. data/lib/swing_paradise/java_classes/jlabel/jlabel.rb +171 -0
  47. data/lib/swing_paradise/java_classes/jmenu/jmenu.rb +13 -0
  48. data/lib/swing_paradise/java_classes/jmenubar/jmenubar.rb +13 -0
  49. data/lib/swing_paradise/java_classes/jpanel/jpanel.rb +115 -0
  50. data/lib/swing_paradise/java_classes/jscrollpane/jscrollpane.rb +84 -0
  51. data/lib/swing_paradise/java_classes/jspinner/jspinner.rb +17 -0
  52. data/lib/swing_paradise/java_classes/jtextarea/jtextarea.rb +120 -0
  53. data/lib/swing_paradise/java_classes/jtextfield/jtextfield.rb +314 -0
  54. data/lib/swing_paradise/java_classes/label +1 -0
  55. data/lib/swing_paradise/java_classes/panel +1 -0
  56. data/lib/swing_paradise/java_classes/spinner +1 -0
  57. data/lib/swing_paradise/java_classes/textarea +1 -0
  58. data/lib/swing_paradise/misc/misc.rb +57 -0
  59. data/lib/swing_paradise/prototype/prototype.rb +79 -0
  60. data/lib/swing_paradise/requires/require_the_project.rb +15 -0
  61. data/lib/swing_paradise/toplevel_methods/misc.rb +293 -0
  62. data/lib/swing_paradise/version/version.rb +17 -0
  63. data/lib/swing_paradise/widget_collection/README.md +2 -0
  64. data/lib/swing_paradise/widget_collection/text_viewer.rb +160 -0
  65. data/lib/swing_paradise.rb +1 -0
  66. data/swing_paradise.gemspec +42 -0
  67. metadata +120 -0
@@ -0,0 +1 @@
1
+ java_classes
@@ -0,0 +1,55 @@
1
+ include Java
2
+
3
+ java_import javax.swing.JButton
4
+ java_import javax.swing.JFrame
5
+ java_import javax.swing.JLabel
6
+ java_import javax.swing.JPanel
7
+ java_import javax.swing.JTextArea
8
+ java_import javax.swing.JScrollBar
9
+ java_import javax.swing.JTextField
10
+ java_import javax.swing.JSpinner
11
+ java_import javax.swing.SpinnerNumberModel
12
+ java_import java.lang.System
13
+ java_import java.awt.Font
14
+
15
+ module SwingParadise
16
+
17
+ class QuitButtonExample < JFrame
18
+
19
+ require 'swing_paradise'
20
+ include SwingParadise
21
+
22
+ # ========================================================================= #
23
+ # === initialize
24
+ # ========================================================================= #
25
+ def initialize(
26
+ run_already = true
27
+ )
28
+ run if run_already
29
+ end
30
+
31
+ # ========================================================================= #
32
+ # === run
33
+ # ========================================================================= #
34
+ def run
35
+ frame = frame('A quit button example')
36
+ panel = JPanel.new # This is an instance of Java::JavaxSwing::JPanel.
37
+ panel.set_font(Font.new 'Sans serif', Font::PLAIN, 85)
38
+ frame.getContentPane.add(panel)
39
+ panel.setLayout(nil)
40
+ panel.hint = 'A quit button example'
41
+ _ = quit_button
42
+ _.set_bounds(10, 20, 200, 40)
43
+ panel << _
44
+ frame.set_font(Font.new 'Sans serif', Font::PLAIN, 85)
45
+ frame.exit_on_close
46
+ frame.set_size(500, 400)
47
+ frame.setLocationRelativeTo(nil)
48
+ frame.show_all
49
+ end
50
+
51
+ end; end
52
+
53
+ if __FILE__ == $PROGRAM_NAME
54
+ SwingParadise::QuitButtonExample.new
55
+ end
@@ -0,0 +1,55 @@
1
+ include Java
2
+
3
+ java_import javax.swing.JButton
4
+ java_import javax.swing.JFrame
5
+ java_import javax.swing.JLabel
6
+ java_import javax.swing.JPanel
7
+ java_import javax.swing.JTextArea
8
+ java_import javax.swing.JScrollBar
9
+ java_import javax.swing.JTextField
10
+ java_import javax.swing.JSpinner
11
+ java_import javax.swing.SpinnerNumberModel
12
+ java_import java.lang.System
13
+ java_import java.awt.Font
14
+
15
+ module SwingParadise
16
+
17
+ class TextAreaExample < JFrame
18
+
19
+ require 'swing_paradise'
20
+ include SwingParadise
21
+
22
+ # ========================================================================= #
23
+ # === initialize
24
+ # ========================================================================= #
25
+ def initialize(
26
+ run_already = true
27
+ )
28
+ run if run_already
29
+ end
30
+
31
+ # ========================================================================= #
32
+ # === run
33
+ # ========================================================================= #
34
+ def run
35
+ frame = frame('A text area example')
36
+ panel = jpanel # This is an instance of Java::JavaxSwing::JPanel.
37
+ panel.set_font(Font.new('Calibri', Font::PLAIN, 30))
38
+ frame.getContentPane.add(panel)
39
+ panel.setLayout(nil)
40
+ panel.hint = 'A text area example'
41
+ _ = text_view
42
+ _.set_font(Font.new 'Sans serif', Font::PLAIN, 32)
43
+ _.set_bounds(10, 20, 500, 400) # Last two are width and height.
44
+ panel << _
45
+ frame.exit_on_close
46
+ frame.set_size(500, 400)
47
+ frame.setLocationRelativeTo(nil)
48
+ frame.show_all
49
+ end
50
+
51
+ end; end
52
+
53
+ if __FILE__ == $PROGRAM_NAME
54
+ SwingParadise::TextAreaExample.new
55
+ end
@@ -0,0 +1,57 @@
1
+ include Java
2
+
3
+ java_import javax.swing.JFrame
4
+
5
+ module SwingParadise
6
+
7
+ class ComboBoxExample < JFrame # === SwingParadise::ComboBoxExample
8
+
9
+ require 'swing_paradise/base_module/base_module.rb'
10
+ include SwingParadise::BaseModule
11
+
12
+ # ========================================================================= #
13
+ # === initialize
14
+ # ========================================================================= #
15
+ def initialize(
16
+ run_already = true
17
+ )
18
+ run if run_already
19
+ end
20
+
21
+ # ========================================================================= #
22
+ # === run
23
+ # ========================================================================= #
24
+ def run
25
+ frame = frame('A combo-box example')
26
+ panel = jpanel # This is an instance of Java::JavaxSwing::JPanel.
27
+ panel.set_font(Font.new('Calibri', Font::PLAIN, 30))
28
+ frame.getContentPane.add(panel)
29
+ panel.setLayout(nil)
30
+ panel.hint = 'A text area example'
31
+ array = %w( apple bird cat dog eagle ferret )
32
+ combo_box = JComboBox.new
33
+ array.each {|this_item|
34
+ combo_box.addItem(this_item)
35
+ }
36
+ combo_box.setSelectedIndex(2)
37
+ combo_box.set_font(Font.new 'Sans serif', Font::PLAIN, 32)
38
+ combo_box.set_bounds(10, 20, 400, 80) # Last two are width and height.
39
+ combo_box.add_action_listener { |event|
40
+ case event.get_action_command
41
+ when /comboBoxChanged/
42
+ current_selection = combo_box.selected_item.to_s
43
+ e 'The selected item is: '+current_selection
44
+ end
45
+ }
46
+ panel << combo_box
47
+ frame.exit_on_close
48
+ frame.set_size(500, 400)
49
+ frame.setLocationRelativeTo(nil)
50
+ frame.show_all
51
+ end
52
+
53
+ end; end
54
+
55
+ if __FILE__ == $PROGRAM_NAME
56
+ SwingParadise::ComboBoxExample.new
57
+ end
@@ -0,0 +1,41 @@
1
+ require 'java'
2
+
3
+ include Java
4
+
5
+ java_import java.awt.BorderLayout
6
+ java_import java.awt.FlowLayout
7
+ java_import java.awt.Frame
8
+ java_import javax.swing.JButton
9
+ java_import javax.swing.JPanel
10
+ java_import java.lang.System
11
+
12
+ class JPanelLeftBoundExample < Frame
13
+
14
+ require 'swing_paradise/base_module/base_module.rb'
15
+ include SwingParadise::BaseModule
16
+
17
+ # ========================================================================= #
18
+ # === initialize
19
+ # ========================================================================= #
20
+ def initialize
21
+ super('JPanelLeftBoundExample Example')
22
+ set_size(480, 180)
23
+ panel = create_panel { :left }
24
+ panel.set_font(Font.new('Calibri', Font::PLAIN, 42))
25
+ panel.hint = 'A jpanel left-bound example'
26
+
27
+ b1 = button('1')
28
+ b1.on_clicked {
29
+ e 'I WAS CLICKED'
30
+ }
31
+ b2 = button('2')
32
+ b3 = button('3')
33
+ panel.batch_add(b1, b2, b3)
34
+ add(panel, BorderLayout::NORTH)
35
+ end
36
+
37
+ end
38
+
39
+ if __FILE__ == $PROGRAM_NAME
40
+ JPanelLeftBoundExample.new.visible = true
41
+ end
@@ -0,0 +1,39 @@
1
+ require 'java'
2
+
3
+ java_import java.awt.Frame
4
+
5
+ class BoxLayoutExample < Frame
6
+
7
+ require 'swing_paradise/base_module/base_module.rb'
8
+ include SwingParadise::BaseModule
9
+
10
+ # ========================================================================= #
11
+ # === initialize
12
+ # ========================================================================= #
13
+ def initialize
14
+ super('BoxLayoutExample Example')
15
+ set_size(480, 180)
16
+ panel = new_boxlayout(:new_panel)
17
+ # panel.set_font(Font.new('Calibri', Font::PLAIN, 42))
18
+ panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10))
19
+
20
+ # The top label
21
+ _ = text('Login')
22
+ _.center
23
+ entry1 = text_field(10)
24
+ entry1.setAlignmentX(Component::CENTER_ALIGNMENT)
25
+ entry2 = password_field(10)
26
+ entry2.setAlignmentX(Component::CENTER_ALIGNMENT)
27
+ # The login button
28
+ login_button = button('login')
29
+ login_button.setAlignmentX(Component::CENTER_ALIGNMENT)
30
+
31
+ panel.batch_add(_, entry1, entry2, login_button)
32
+ add(panel, BorderLayout::NORTH)
33
+ end
34
+
35
+ end
36
+
37
+ if __FILE__ == $PROGRAM_NAME
38
+ BoxLayoutExample.new.is_visible
39
+ end
@@ -0,0 +1,33 @@
1
+ require 'java'
2
+
3
+ java_import java.awt.Frame
4
+
5
+ class FrameExample < Frame
6
+
7
+ require 'swing_paradise/base_module/base_module.rb'
8
+ include SwingParadise::BaseModule
9
+
10
+ # ========================================================================= #
11
+ # === initialize
12
+ # ========================================================================= #
13
+ def initialize
14
+ super('FrameExample Example')
15
+ set_size(480, 180)
16
+ panel = JPanel.new(GridLayout.new(7, 1, 5, 5))
17
+ panel.set_font(Font.new('Calibri', Font::PLAIN, 62))
18
+ panel.setBorder(
19
+ BorderFactory.uniform_border(20)
20
+ )
21
+ _ = BorderFactory.createTitledBorder(" Frame")
22
+ panel.setBorder(_)
23
+ _ = bold_text('Examples')
24
+ _.set_font(Font.new('Calibri', Font::PLAIN, 40))
25
+ panel.add(_, JLabel::CENTER)
26
+ add(panel, BorderLayout::NORTH)
27
+ end
28
+
29
+ end
30
+
31
+ if __FILE__ == $PROGRAM_NAME
32
+ FrameExample.new.is_visible
33
+ end
@@ -0,0 +1,28 @@
1
+ java_import java.awt.event.ActionEvent
2
+ java_import java.awt.event.ActionListener
3
+ java_import java.awt.event.WindowAdapter
4
+ java_import java.awt.event.WindowEvent
5
+
6
+ java_import javax.swing.JFrame
7
+ java_import javax.swing.JTextField
8
+
9
+ class TextareaRespondingToEnterKeyExample < JFrame
10
+
11
+ alias e puts
12
+
13
+ # === initialize
14
+ def initialize
15
+ super('This example shows how to respond to an enter-event.')
16
+ setSize(1000, 400)
17
+ text = JTextField.new('Press the <Return> key here', 50)
18
+ text.addActionListener {|event|
19
+ e 'The enter key was pressed.'
20
+ # _ = event.get_action_command
21
+ }
22
+ setDefaultCloseOperation(JFrame::EXIT_ON_CLOSE)
23
+ add(text, 'Center')
24
+ end
25
+
26
+ end
27
+
28
+ TextareaRespondingToEnterKeyExample.new.setVisible(true)
@@ -0,0 +1,41 @@
1
+ java_import java.awt.FlowLayout
2
+ java_import java.awt.event.ActionEvent
3
+ java_import java.awt.event.ActionListener
4
+ java_import java.awt.event.WindowAdapter
5
+ java_import java.awt.event.WindowEvent
6
+
7
+ java_import javax.swing.JFrame
8
+ java_import javax.swing.JTextField
9
+ java_import javax.swing.JScrollPane
10
+ java_import javax.swing.JTextArea
11
+
12
+ class ScrolledWindowExample < JFrame
13
+
14
+ require 'swing_paradise/base_module/base_module.rb'
15
+ include SwingParadise::BaseModule
16
+
17
+ require 'swing_paradise/java_classes/jscrollpane/jscrollpane.rb'
18
+
19
+ alias e puts
20
+
21
+ # ========================================================================= #
22
+ # === initialize
23
+ # ========================================================================= #
24
+ def initialize
25
+ super('Scrolled Window Example')
26
+ setSize(1200, 800)
27
+ getContentPane.setLayout(FlowLayout.new)
28
+ textarea = jtextarea(35, 30)
29
+ textarea.set_text("Test\n"*120)
30
+ scrolled_window = JScrollPane.new(textarea)
31
+ scrolled_window.horizontal_always
32
+ scrolled_window.vertical_always
33
+ scrolled_window.is_visible
34
+ add(scrolled_window)
35
+ is_visible
36
+ default_close
37
+ end
38
+
39
+ end
40
+
41
+ ScrolledWindowExample.new
@@ -0,0 +1,39 @@
1
+ include Java
2
+
3
+ java_import javax.swing.JButton
4
+ java_import javax.swing.JFrame
5
+ java_import javax.swing.JLabel
6
+ java_import javax.swing.JPanel
7
+ java_import javax.swing.JTextArea
8
+ java_import javax.swing.JScrollBar
9
+ java_import javax.swing.JTextField
10
+ java_import javax.swing.JSpinner
11
+ java_import javax.swing.SpinnerNumberModel
12
+ java_import java.lang.System
13
+ java_import java.awt.Font
14
+
15
+ class FontSizeExample
16
+
17
+ # ========================================================================= #
18
+ # === initialize
19
+ # ========================================================================= #
20
+ def initialize
21
+ frame = JFrame.new("Label Example")
22
+ label = JLabel.new('First Label')
23
+ label.setBounds(50, 50, 350, 150)
24
+ label.setFont(Font.new('Verdana', Font::PLAIN, 80))
25
+ # button1 = JButton.new('A test button')
26
+ # button1.setBounds(150, 450, 350, 150)
27
+ # button1.setFont(Font.new('Verdana', Font::PLAIN, 40))
28
+ frame.add(label)
29
+ # frame.add(button1)
30
+ frame.setSize(840, 540)
31
+ # frame.setLayout(nil)
32
+ frame.setVisible(true)
33
+ end
34
+
35
+ end
36
+
37
+ if __FILE__ == $PROGRAM_NAME
38
+ FontSizeExample.new
39
+ end
@@ -0,0 +1,183 @@
1
+ require 'java'
2
+
3
+ java_import java.awt.Frame
4
+
5
+ class CounterModel # === CounterModel
6
+
7
+ # ========================================================================= #
8
+ # === initialize
9
+ # ========================================================================= #
10
+ def initialize
11
+ @value = 0
12
+ end
13
+
14
+ # ========================================================================= #
15
+ # === value?
16
+ # ========================================================================= #
17
+ def value?
18
+ @value
19
+ end; alias getValue value? # === getValue
20
+
21
+ # ========================================================================= #
22
+ # === increment
23
+ # ========================================================================= #
24
+ def increment(by_n = 1)
25
+ @value += by_n
26
+ end
27
+
28
+ # ========================================================================= #
29
+ # === decrement
30
+ # ========================================================================= #
31
+ def decrement(by_n = 1)
32
+ @value -= by_n
33
+ end
34
+
35
+ # ========================================================================= #
36
+ # === reset_the_value
37
+ # ========================================================================= #
38
+ def reset_the_value
39
+ @value = 0
40
+ end
41
+
42
+ end
43
+
44
+ class SimpleFrame < JFrame
45
+
46
+ require 'swing_paradise/base_module/base_module.rb'
47
+ include SwingParadise::BaseModule
48
+
49
+ def initialize
50
+ setSize(200,200)
51
+ setLocation(200,200)
52
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
53
+ end
54
+
55
+ # Makes the frame visible.
56
+ def showIt(title)
57
+ if title
58
+ setTitle(title)
59
+ end
60
+ setVisible(true)
61
+ end
62
+
63
+ # Makes the frame visible and sets the title text
64
+ # and the position of the window.
65
+ def showIt(title, x, y)
66
+ setTitle(title)
67
+ setLocation(x,y)
68
+ setVisible(true)
69
+ end
70
+
71
+ # ========================================================================= #
72
+ # Makes the frame invisible.
73
+ # ========================================================================= #
74
+ def hideIt
75
+ setVisible(false)
76
+ end
77
+
78
+ end
79
+
80
+ # =========================================================================== #
81
+ # === CounterFrame
82
+ # =========================================================================== #
83
+ class CounterFrame < SimpleFrame
84
+
85
+ # ========================================================================= #
86
+ # === initialize
87
+ # ========================================================================= #
88
+ def initialize
89
+ counterPanel = CounterPanel.new
90
+ getContentPane.add(counterPanel, BorderLayout::CENTER)
91
+ end
92
+
93
+ end
94
+
95
+ # =========================================================================== #
96
+ # === CounterDriver
97
+ # =========================================================================== #
98
+ class CounterDriver
99
+ def initialize
100
+ cfr = new CounterFrame()
101
+ cfr.showIt("Counter")
102
+ end
103
+ end
104
+
105
+ class CounterListener
106
+ def initialize(i = ARGV)
107
+ @countPane = i
108
+ end
109
+ # === actionPerformed
110
+ def actionPerformed(event)
111
+ puts 'HUH'
112
+ pp event.class
113
+ actionCommand = event.getActionCommand
114
+ if actionCommand == "Up"
115
+ @countPane.increment
116
+ elsif actionCommand == "Down"
117
+ @countPane.decrement
118
+ else
119
+ puts "ERROR: Unexpected ActionCommand"
120
+ end
121
+ end
122
+
123
+ end
124
+
125
+ class CounterPanel < JPanel
126
+
127
+ def initialize
128
+ @counter = CounterModel.new
129
+ bordLay = BorderLayout.new
130
+ setLayout(bordLay)
131
+ upButton = JButton.new("Up")
132
+ downButton = JButton.new("Down")
133
+ @valueLabel = JLabel.new(""+counter.getValue(),SwingConstants::CENTER)
134
+ add(upButton,BorderLayout::WEST)
135
+ add(downButton,BorderLayout::EAST)
136
+ add(@valueLabel,BorderLayout::CENTER)
137
+ # The next three lines will later be used to incorporate
138
+ # the listener.
139
+ # CounterListener countList = new CounterListener(this);
140
+ # upButton.addActionListener(countList);
141
+ # downButton.addActionListener(countList);
142
+ end
143
+
144
+ def increment
145
+ @counter.increment
146
+ @valueLabel.setText(""+counter.getValue)
147
+ end
148
+
149
+ def decrement
150
+ @counter.decrement
151
+ @valueLabel.setText(""+counter.getValue())
152
+ end
153
+
154
+ end
155
+
156
+ class CounterExample < Frame # === CounterExample
157
+
158
+ require 'swing_paradise/base_module/base_module.rb'
159
+ include SwingParadise::BaseModule
160
+
161
+ # ========================================================================= #
162
+ # === initialize
163
+ # ========================================================================= #
164
+ def initialize
165
+ super('CounterExample Example')
166
+ set_size(480, 180)
167
+ panel = create_panel(GridLayout.new(7, 1, 5, 5))
168
+ panel.set_font(Font.new('Calibri', Font::PLAIN, 62))
169
+ panel.uniform_border(20)
170
+ _ = BorderFactory.createTitledBorder(" Frame")
171
+ panel.setBorder(_)
172
+ _ = bold_text('Examples')
173
+ _.set_font(Font.new('Calibri', Font::PLAIN, 40))
174
+ panel.add(_, JLabel::CENTER)
175
+ add(panel, BorderLayout::NORTH)
176
+ is_visible
177
+ end
178
+
179
+ end
180
+
181
+ if __FILE__ == $PROGRAM_NAME
182
+ CounterExample.new
183
+ end
@@ -0,0 +1,58 @@
1
+ # =========================================================================== #
2
+ # This example works without using SwingParadise. You can modify
3
+ # the path of the image below.
4
+ # =========================================================================== #
5
+ include Java
6
+
7
+ java_import javax.swing.JFrame
8
+
9
+ class ButtonWithImageExample < JFrame
10
+
11
+ require 'swing_paradise/base_module/base_module.rb'
12
+ include SwingParadise::BaseModule
13
+
14
+ # ========================================================================= #
15
+ # === PATH_TO_THE_IMAGE_FILE
16
+ #
17
+ # This may have to be changed to another image.
18
+ # ========================================================================= #
19
+ PATH_TO_THE_IMAGE_FILE = '/home/x/data/images/NJOY/Susanne_01.jpg'
20
+
21
+ # ========================================================================= #
22
+ # === initialize
23
+ # ========================================================================= #
24
+ def initialize(
25
+ run_already = true
26
+ )
27
+ super('Icon Frame')
28
+ reset
29
+ setDefaultCloseOperation(JFrame::EXIT_ON_CLOSE)
30
+ panel = create_panel
31
+ # ======================================================================= #
32
+ # Next create the image:
33
+ # ======================================================================= #
34
+ button = button_with_image(PATH_TO_THE_IMAGE_FILE, "An example of showing an image")
35
+ panel.add(button)
36
+ add(panel)
37
+ run if run_already
38
+ end
39
+
40
+ # ========================================================================= #
41
+ # === reset (reset tag)
42
+ # ========================================================================= #
43
+ def reset
44
+ end
45
+
46
+ # ========================================================================= #
47
+ # === run
48
+ # ========================================================================= #
49
+ def run
50
+ pack()
51
+ setVisible(true)
52
+ end
53
+
54
+ end
55
+
56
+ if __FILE__ == $PROGRAM_NAME
57
+ ButtonWithImageExample.new
58
+ end
@@ -0,0 +1,37 @@
1
+ # =========================================================================== #
2
+ # 012_quit_on_escape_key_being_pressed.rb
3
+ # =========================================================================== #
4
+ module SwingParadise
5
+
6
+ require 'swing_paradise/base_module/base_module.rb'
7
+
8
+ class QuitOnEscapeKeyBeingPressed < JFrame # === SwingParadise::QuitOnEscapeKeyBeingPressed
9
+
10
+ include SwingParadise::BaseModule
11
+
12
+ # ========================================================================= #
13
+ # === initialize
14
+ # ========================================================================= #
15
+ def initialize(
16
+ run_already = true
17
+ )
18
+ run if run_already
19
+ end
20
+
21
+ # ========================================================================= #
22
+ # === run
23
+ # ========================================================================= #
24
+ def run
25
+ frame = frame('Showcasing how to quit on escape-key being pressed')
26
+ frame.allow_the_escape_key_to_exit
27
+ frame.exit_on_close
28
+ frame.set_size(500, 400)
29
+ frame.setLocationRelativeTo(nil)
30
+ frame.show_all
31
+ end
32
+
33
+ end; end
34
+
35
+ if __FILE__ == $PROGRAM_NAME
36
+ SwingParadise::QuitOnEscapeKeyBeingPressed.new
37
+ end