문제

I want to develop desktop application this is just a start , i am using jruby ,

my code:

def fact(n)
   if n==0
     return 1
   else
     return n*fact(n-1)
   end
end

class CloseListener 
   include java.awt.event.ActionListener
     def actionPerformed(event)
       puts "CloseListere.actionPerformed() called"
       java.lang.System.exit(0)
     end
end

def showFactInWindow(title,number)
  f = fact(n)
  frame = javax.swing.JFrame.new(title)
  frame.setLayout(java.awt.FlowLayout.new())
  button = javax.swing.JButton.new("Close")
  button.addActionListener(CloseListener.new)
  frame.contentPane.add(javax.swing.JLabel.new(number.to_s+"! = "+f.to_s))
  frame.contentPane.add(button)
  frame.defaultCloseOperation=javax.swing.WindowConstants::EXIT_ON_CLOSE
frame.pack()
  frame.visible=true
  return f
end

Execution code

jruby file_name.rb

QUESTION

how to get the gui ?

where i am wrong ?

도움이 되었습니까?

해결책

Just one line to add

showFactInWindow('fact', 89)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top