# File swing.rb, line 188
  def initialize 
    super("Scrabble!")
    self.defaultCloseOperation = WindowConstants::EXIT_ON_CLOSE

    @fields = Array.new(Board::SIZE) {|i| [] * Board::SIZE}

    @status_label = JLabel.new "Lade Wörterbuch .."
    @rack_label = JLabel.new
    @points_label = JLabel.new("0 Punkte")

    @next_button = JButton.new
    @next_button.text = "Go!"
    @next_button.enabled = false
    @next_button.addActionListener ActionCallback.new(lambda { ScrabbleRunner.new(self).start})

    @reset_button = JButton.new
    @reset_button.text = "Reset"
    @reset_button.enabled = false
    @reset_button.addActionListener ActionCallback.new(lambda { reset() })

    board = JPanel.new
    board.layout = GridLayout.new(Board::SIZE, Board::SIZE)
    for_x_y(Board::SIZE) do |x, y|
      label = JLabel.new(" ")
      label.horizontalAlignment = SwingConstants::CENTER
      label.border = SoftBevelBorder.new(BevelBorder::RAISED)
      board.add label
      @fields[x][y] = label
    end

    top = JPanel.new
    top.layout = BoxLayout.new(top, BoxLayout::LINE_AXIS)
    top.add rigid(5)
    top.add @rack_label
    top.add Box.createHorizontalGlue
    top.add @points_label
    top.add rigid(5)

    contentPane.layout = BoxLayout.new(contentPane, BoxLayout::PAGE_AXIS)
    contentPane.add rigid(5)
    contentPane.add top
    contentPane.add rigid(5)
    contentPane.add board

    bottom = JPanel.new
    bottom.layout = BoxLayout.new(bottom, BoxLayout::LINE_AXIS)
    bottom.add rigid(5)
    bottom.add @next_button
    bottom.add rigid(5)
    bottom.add @reset_button
    bottom.add Box.createHorizontalGlue
    bottom.add @status_label
    bottom.add rigid(5)

    contentPane.add rigid(10)
    contentPane.add bottom
    contentPane.add rigid(5)

    reset
    pack
    setSize(400, 450)
    setVisible(true)

    begin
      create_dictionary "de_DE.dic"
    rescue Errno::ENOENT
      @status_label.text = "Lade Wörterbuch herunter .."
      begin
        create_dictionary "http://misto.ch/scrabble/de_DE.dic"
      rescue
        @status_label.text = "Konnte Wörterbuch nicht herunterladen"
        fc = JFileChooser.new
        result = fc.show_dialog(self, "Öffne Wörterbuch")
        if result == JFileChooser::APPROVE_OPTION
           create_dictionary fc.selected_file.absolute_path
        else
          @status_label.text = "Wörterbuch nicht gefunden"
          return
        end
        if @dic.size < 5
          @status_label.text = "Wörterbuch ungültig"
          return
        end
      end
    end

    @status_label.text = "Bereit"
    enable_buttons true
  end