异常处理
Posted 暗影蔽日
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了异常处理相关的知识,希望对你有一定的参考价值。
//NumberFormatTest.java import java.awt.*; import java.awt.event.*; public class NumberFormatTest extends Frame implements ActionListener { private TextField tf; private Button btn; private List list; public static void main(String[] args) { NumberFormatTest test = new NumberFormatTest(); test.setSize(300,200); test.setVisible(true); } public NumberFormatTest() { Panel panel = new Panel(); tf = new TextField(5); btn = new Button("确定"); btn.addActionListener(this); list = new List(); panel.add(new Label("inter a number:")); panel.add(tf); add(panel,BorderLayout.NORTH); add(btn,BorderLayout.SOUTH); add(list,BorderLayout.CENTER); } public void actionPerformed(ActionEvent e) { int num; try { num = Integer.parseInt(tf.getText()); list.removeAll(); list.add(Integer.toString(num)); } catch(NumberFormatException exc) { tf.setText(""); } } }
以上是关于异常处理的主要内容,如果未能解决你的问题,请参考以下文章
java.util.MissingResourceException: Can't find bundle for base name init, locale zh_CN问题的处理(代码片段