Java语言程序设计教程 书本知识点汇总(10)

2021-02-21 17:47

Java本科专业教程

container.add(inputField1); // set up label and inputField2; register listener container.add(new JLabel("Enter denominator and press Enter ", SwingConstants.RIGHT)); inputField2 = new JTextField(); container.add(inputField2); inputField2.addActionListener(this); // set up label and outputField container.add(new JLabel("RESULT ", SwingConstants.RIGHT)); outputField = new JTextField(); container.add(outputField); setSize(425, 100); setVisible(true); } // end DivideByZeroTest constructor // process GUI events public void actionPerformed(ActionEvent event) { outputField.setText(""); // clear outputField // read two numbers and calculate quotient try { } // process improperly formatted input catch (NumberFormatException numberFormatException) { } // process attempts to divide by zero catch (ArithmeticException arithmeticException) { } JOptionPane.showMessageDialog(this, arithmeticException.toString(), "Arithmetic Exception", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(this, "You must enter two integers", "Invalid Number Format", JOptionPane.ERROR_MESSAGE); number1 = Integer.parseInt(inputField1.getText()); number2 = Integer.parseInt(inputField2.getText()); result = quotient(number1, number2); outputField.setText(String.valueOf(result)); } // end method actionPerformed // demonstrates throwing an exception when a divide-by-zero occurs public int quotient(int numerator, int denominator) } public static void main(String args[]) { } DivideByZeroTest application = new DivideByZeroTest(); application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); throws ArithmeticException { return numerator / denominator;

} // end class DivideByZeroTest


Java语言程序设计教程 书本知识点汇总(10).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2011级毕业论文之选题和开题

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: