Die Programmiersprache Ruby

Blog| Forum| Wiki  

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
62
63
64
65
66
67
68
69
70
71
72
# Test GUI
# geschrieben von User: Barcellona
# in Ruby 1.8
# mit FxRuby 1.6

#beinhaltet: Textfeld, Button, RadioButton, 
            #connect(SEL_COMMAND), connect(SEL_UPDATE)

require 'fox16'


include Fox

class GUI < FXMainWindow

  attr_writer :text, :button2, :antwort, :textfeld, :alter, :textfeld2, :radio1, :radio2, :choice

  def initialize(app)
    super(app, 'GUI', :width=>700, :height=>700)
    init_GUI(app)
  end

  def init_GUI(app)
    # die Attribute werden automatisch geupdatet!
    @text=FXVerticalFrame.new(self, :opts => LAYOUT_FILL_X)
      # LAYOUT_FILL_X füllt die ganze X Spalte (nach rechts) aus
    FXLabel.new(@text, "Alter:")  # wird hier an @text gegeben
    @textfeld=FXText.new(self, :opts => TEXT_WORDWRAP|LAYOUT_FILL_X)
     # :opts => TEXT_WORDWRAP|LAYOUT_FILL   füllt alles aus
    @textfeld.text=" "              # LAYOUT_FILL_Y würde nach unten hin ausfüllen
    @antwort = FXButton.new(self, "OK", :opts=>BUTTON_NORMAL|LAYOUT_FIX_X|LAYOUT_FIX_Y, 
      :x => 300, :y => 400)
    @antwort.connect(SEL_COMMAND){@textfeld2.text="Dein Alter ist: #{@textfeld.text} Radio: #{@choice}"}
    # hier wird der OK Button verbunden, um Auswirkung zu haben
    # LAYOUT_FIX_X|LAYOUT_FIX_Y, :x => 300, :y => 400 sind die 
    # Koordinaten (müssen aber nicht angegeben werden...)
    @textfeld2=FXText.new(self, :opts => TEXT_WORDWRAP|LAYOUT_FIX_WIDTH|LAYOUT_FIX_HEIGHT, :width => 200, 
      :height => 75)
     # :opts => TEXT_WORDWRAP|LAYOUT_FILL   würde alles ausfüllen
    @textfeld2.text=""
    # LAYOUT_FIX_WIDTH|LAYOUT_FIX_HEIGHT lassen die Größe des Textfeldes bestommen
    @button2 = FXButton.new(self, "Ciao", :opts=>BUTTON_NORMAL|LAYOUT_EXPLICIT, :x => 350, :y => 400, 
      :width => 40, :height => 40)
    @button2.connect(SEL_COMMAND){exit} # durch klick auf 'button2' wird das Programm beendet
    # BUTTON_NORMAL gibt die Knopf-Umrandung, 
    # LAYOUT_EXPLICIT lässt alle 4 Werte bestimmen!


    @choice=1 # Starteinstellung auf weiblich
    @radio1=FXRadioButton.new(self, "maennlich")
    @radio2=FXRadioButton.new(self, "weiblich")
    @radio1.connect(SEL_COMMAND) { @choice = 0}
    @radio2.connect(SEL_COMMAND) { @choice = 1 }
    @radio1.connect(SEL_UPDATE) { @radio1.checkState = (@choice == 0) }
    @radio2.connect(SEL_UPDATE) { @radio2.checkState = (@choice == 1) }
    # die Buttons müssen geupdatet werden um immer nur einen ausgewählt zu haben
  end


  def create
    super
    show(PLACEMENT_SCREEN)
  end

end

if __FILE__ == $0
    app=FXApp.new
    GUI.new(app)
    app.create
    app.run
end