如何检查文本框中的文本是否为数字?

时间:2015-11-15 21:40:35

标签: java swing textbox

所以我有以下窗口,它有一个文本框和一个按钮。

public class Menu extends JFrame {
        private static final long serialVersionUID = 1L;
        private static final int WIDTH = 225;
        private static final int HEIGHT = 270;
        private static final int SCALE = 1;  
        private JTextField txtGenerationSize;
        public Menu(String title){
            setSize(450, 358);
            setPreferredSize(new Dimension(WIDTH*SCALE, HEIGHT*SCALE));
            setMaximumSize(new Dimension(WIDTH*SCALE, HEIGHT*SCALE));
            setMinimumSize(new Dimension(WIDTH*SCALE, HEIGHT*SCALE));
            setResizable(false);
            this.pack();
            setVisible(true);
            setTitle(title);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            getContentPane().setLayout(new CardLayout(0, 0));

            JPanel MenuPanel = new JPanel();
            getContentPane().add(MenuPanel, "name_36840921662905");
            MenuPanel.setLayout(null);

            JLabel lblTitle = new JLabel("Evolve!");
            lblTitle.setFont(new Font("Arial", Font.PLAIN, 18));
            lblTitle.setBounds(76, 21, 79, 14);
            MenuPanel.add(lblTitle);

            JLabel lblGenerationSize = new JLabel("Generation Size");
            lblGenerationSize.setBounds(10, 108, 79, 14);
            MenuPanel.add(lblGenerationSize);

            txtGenerationSize = new JTextField();
            txtGenerationSize.setBounds(99, 105, 56, 20);
            MenuPanel.add(txtGenerationSize);
            txtGenerationSize.setColumns(10);

            JButton btnStart = new JButton("Start generation");
            btnStart.setBounds(10, 208, 199, 23);
            MenuPanel.add(btnStart);


        }
    }

当他们点击按钮时,我想检查他们在文本框中引入的内容是否为数字

我该怎么做?

0 个答案:

没有答案