try {
 
int s = Integer.parseInt(t2.getText());
} catch (NumberFormatException h) {
JOptionPane.showMessageDialog(null,
"Array can only contain integer number",
"Invaild number", JOptionPane.ERROR_MESSAGE);
}这个的异常不捕获怎么办?
只是停止工作求高手解答

解决方案 »

  1.   

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JTextField;public class Exception extends JFrame implements ActionListener{
    JTextField t2;
    JButton jb;
    public Exception(){
    JPanel jp = new JPanel();
    JLabel jl = new JLabel("hello");
    t2 = new JTextField(10);
    jb = new JButton("输出");
    jp.add(jb);
    jp.add(jl);
    jp.add(t2);
    add(jp);
    jb.addActionListener(this);
    }

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Exception e = new Exception();
    e.setSize(500,600);
    e.setDefaultCloseOperation(EXIT_ON_CLOSE);
    e.setVisible(true);
    } public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub
    try { int s = Integer.parseInt(t2.getText());
    System.out.println(s);
    } catch (NumberFormatException h) {
    JOptionPane.showMessageDialog(null,
    "Array can only contain integer number", "Invaild number",
    JOptionPane.ERROR_MESSAGE);
    }
    }}
    可以的 我试过了 上面是代码