java2实用教程(第3版)第7章课后习题答案(耿祥义).docVIP

  • 8
  • 0
  • 约1.26万字
  • 约 29页
  • 2017-04-12 发布于四川
  • 举报

java2实用教程(第3版)第7章课后习题答案(耿祥义).doc

java2实用教程(第3版)第7章课后习题答案(耿祥义)

import java.awt.*; import java.awt.event.*; import java.util.*; public class T7_4 { public static void main(String [] args) { FirstWindow win = new FirstWindow(计算的窗口); } } class FirstWindow extends Frame implements TextListener{ TextArea textA1,textA2; FirstWindow(String s) { setTitle(s); setLayout(new FlowLayout()); textA1 = new TextArea(6,15); textA2 = new TextArea(6,15); add(textA1); add(textA2); textA1.addTextListener(this); setBounds(0,0,300,300); setVisible(true); validate(); } public void textValueChanged(TextEvent e) { String s = textA1.getText(); StringTokenizer fenxi = new StringTokenizer(s, \n\r); int n = fenxi.countTokens(); long sum=0; try{ for(int i = 0; in; i++) { sum += Long.parseLong(fenxi.nextToken()); } textA2.setText(总和 + String.valueOf(sum)); double avg = (double)sum/n; textA2.append(\n平均数 + String.valueOf(avg)); } catch (NumberFormatException e1) { //System.out.println(输入有误!); System.out.println(s); } } } import java.awt.*; import java.awt.event.*; public class T7_5 { public static void main(String [] args) { new MyFrame(挑单词); } } class MyFrame extends Frame implements ActionListener { TextArea ta1,ta2; Button btn; MyFrame (String s) { super(s); setLayout(new BorderLayout()); ta1 = new TextArea(5,15); ta2 = new TextArea(5,15); btn = new Button(追加); btn.addActionListener(this); add(ta1,BorderLayout.EAST); add(ta2,BorderLayout.WEST); add(btn,BorderLayout.SOUTH); setBounds(100,100,300,200); setVisible(true); } public void actionPerformed(ActionEvent e) { String s = ta1.getSelectedText(); ta2.append(s); } } //带关闭功能的窗口 import java.awt.*; import java.awt.event.*; public class T7_6 { public static void main(String [] args) { new MathWindow(计算); } } class MathWindow extends Frame implements ActionListener {//定义一个类继承于Frame 并实现了接口ActionListener Button btn_Add,btn_Sub,btn_Mul,btn_Mov;//定义四个表示运算的按钮 TextField tf1,tf2,tf3;//

文档评论(0)

1亿VIP精品文档

相关文档