import java.awt.* import javax.swing.* fun factorial(n: Long): Long = if (n == 0L) 1L else n * factorial(n - 1L) fun main() { SwingUtilities.invokeLater { val panel = JPanel() panel.setPreferredSize(Dimension(300, 50)) val input = JTextField("0", 8) val output = JLabel("1") input.addActionListener { _ -> val n = input.getText().toLong() output.setText("${factorial(n)}") } panel.add(input) panel.add(JLabel(" の階乗は ")) panel.add(output) panel.add(JLabel(" です")) val frame = JFrame("Hello") frame.add(panel) frame.pack() frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE) frame.setVisible(true) } }