simplyjava1_04.ppt

  1. 1、本文档共22页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
simplyjava1_04

教程 4 – 完整的库存清单应用程序 介绍程序设计概念 教学目标 内容概述: 如何使应用程序执行操作以响应对JButton的点击操作. 正确使用乘法运算符. 使用Integer.parseInt把String转换为int. 使用String.valueOf把数字转换为字符串. 4.1 完整的库存清单程序 4.1 完整的库存清单程序 (Cont.) 4.1 完整的库存清单程序 (Cont.) 4.2 Java代码规则 4.2 Java代码规则 (Cont.) Java Code 类 (Case sensitive) Class declaration Class keyword Class name Identifier Left brace Body Right brace Inherits Extends 方法 Blocks 关键字(reserved words) 4.3 事件处理 (Cont.) 4.3 事件处理 (Cont.) 4.3 事件处理 (Cont.) 注释 Indicated by two forward slash characters (//) Full-line comments End-of-line comments 表达式 以分号(;)结束 Example: totalResultJTextField.setText( “100” ); 方法 Called Return value Arguments Dot separator 4.3 事件处理 (Cont.) Multiplication operator 操作数 Left operand Right operand 二元运算符 4.3 事件处理 (Cont.) 4.3 事件处理 (Cont.) 4.4 计算并显示结果 Multiline statement Java ignores extra spaces, tabs and newlines (blank lines) White space Integer.parseInt Converts a String to an int so that you can perform calculations getText Returns a String containing the text property of a component 4.4 计算并显示结果 (Cont.) 4.4 计算并显示结果 (Cont.) Inventory.java (1 of 6) 1 // Tutorial 4: Inventory.java 2 // Calculates the number of items in a shipment based on the number 3 // of cartons received and the number of items per carton. 4 import java.awt.*; 5 import java.awt.event.*; 6 import javax.swing.*; 7 8 public class Inventory extends JFrame 9 { 10 // JLabel and JTextField for cartons per shipment 11 private JLabel cartonsJLabel; 12 private JTextField cartonsJTextField; 13 14 // JLabel and JTextField for items per carton 15 private JLabel itemsJLabel; 16 private JTextField itemsJTextField; 17 18 // JLabel and JTextField for total items per shipment 19 private JLabel totalJLabel; 20 private JTextField totalResultJTextField; 21 22 // JButton to initiate calculation of total items per shipment 23 private JButton calculateJButton; 24 Inventory.

文档评论(0)

mv2323 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档