




已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
class People protected double weight,height; public void speakHello() System.out.println(yayawawa); public void averageHeight() height=173; System.out.println(average height:+height); public void averageWeight() weight=70; System.out.println(average weight:+weight); class ChinaPeople extends People public void speakHello() System.out.println(你好,吃饭了吗?); public void averageHeight() height=173.0; System.out.println(中国人的average height:+height); public void averageWeight() weight=67.34; System.out.println(中国人的average weight:+weight); public void chinaGongfu() System.out.println(坐如钟,站如松,睡如弓); class AmericanPeople extends People public void speakHello() System.out.println(How do you do); public void averageHeight() height=188.0; System.out.println(American average height:+height); public void averageWeight() weight=80.23; System.out.println(American average weight:+weight); public void americanBoxing() System.out.println(直拳,钩拳); class BeijingPeople extends ChinaPeople public void speakHello() System.out.println(您好); public void aversageHeight() height=167.0; System.out.println(北京人的average height:+height); public void averageWeight() weight=68.5; System.out.println(北京人的average weight:+weight); public void beijingOpera() System.out.println(京剧术语); public class Example public static void main(String args) ChinaPeople chinaPeople=new ChinaPeople(); AmericanPeople americaPeople=new AmericanPeople(); BeijingPeople beijingPeople=new BeijingPeople(); chinaPeople.speakHello(); americanPeople.speakHello(); beijingPeople.speakHello(); americanPeople.averageHeight(); beijingPeople.averageHeight(); chinaPeople.averageWeight(); americanPeople.averageWeight(); beijingPeople.averageWeight(); chinaPeople.chinaGongfu(); americaPeople.americanBoxing(); beijingPeople.beijingOpera(); beijingPeople.chinaGongfu(); import java.awt.*;import java.awt.event.*;public class ComputerFrame extends Frame implements ActionListener TextField textOne,textTwo,textResult; Button getProblem,giveAnwser; Label operatorLabel,message; Teacher teacher; ComputerFrame(String s) super(s); teacher=new Teacher(); setLayout(new FlowLayout(); textOne=new TextField(10); textTwo=new TextField(10); textResult=new TextField(10); operatorLabel=new Label(+); message=new Label(你还没有回答呢); getProblem=new Button(获取题目); giveAnwser=new Button(确认答案); add(getProblem); add(textOne); add(operatorLabel); add(textTwo); add(new Label(=); add(textResult); add(giveAnwser); add(message); textResult.requestFocus(); textOne.setEditable(false); textTwo.setEditable(false); getProblem.addActionListener(this); giveAnwser.addActionListener(this); textResult.addActionListener(this); setBounds(100,100,450,100); setVisible(true); validate(); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0); ); public void actionPerformed(ActionEvent e) if(e.getSource()=getProblem) int number1=teacher.giveNumberOne(100); int number2=teacher.giveNumberTwo(100); String operator=teacher.giveOperator(); textOne.setText(+number1); textTwo.setText(+number2); operatorLabel.setText(operator); message.setText(请回答); textResult.setText(null); if(e.getSource()=giveAnwser) String answer=textResult.getText(); try int result=Integer.parseInt(answer); if(teacher.getRight(result)=true) message.setText(你回答正确); else message.setText(你回答错误); catch(NumberFormatException ex) message.setText(请输入数字字符); textResult.requestFocus(); validate(); public class Teacher int numberOne,numberTwo; String operator= ; boolean right; public int giveNumberOne(int n) numberOne=(int)(Math.random()*n)+1; return numberOne; public int giveNumberTwo(int n) numberTwo=(int)(Math.random()*n)+1; return numberTwo; public String giveOperator() double d=Math.random(); if(d=0.5) operator=+; else operator=-; return operator; public boolean getRight(int answer) if(operator.equals(+) if(answer=numberOne+numberTwo) right=true; else right=false; else if(operator.equals(-) if(answer=numberOne-numberTwo) right=true; else right=false; return right; public class MainClass public static void main(String args) ComputerFrame frame; frame=new ComputerFrame(算术测试); WordThread.javaimport java.awt.*;public class WordThread extends Thread char word; int k=19968; Label com; WordThread(Label com) =com; public void run() k=19968; while(true) word=(char)k; com.setText(+word); try sleep(6000); catch(InterruptedException e) k+; if(k=29968) k=19968; ThreadFrame.javaimport java.awt.*;import java.awt.event.*;public class ThreadFrame extends Frame implements ActionListener Label wordLabel; Button button; TextField inputText,scoreText; WordThread giveWord; int score=0; ThreadFrame() wordLabel=new Label( ,Label.CENTER); wordLabel.setFont(new Font(,Font.BOLD,72); button=new Button(开始); inputText=new TextField(3); scoreText=new TextField(5); scoreText.setEditable(false); giveWord=new WordThread(wordLabel); button.addActionListener(this); inputText.addActionListener(this); add(button,BorderLayout.NORTH); add(wordLabel,BorderLayout.CENTER); Panel southP=new Panel(); southP.add(new Label(输入标签所显示的汉字后回车:); southP.add(inputText); southP.add(scoreText); add(southP,BorderLayout.SOUTH); setBounds(100,100,350,180); setVisible(true); validate(); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0); ); public void actionPerformed(ActionEvent e) if(e.getSource()=button) if(!(giveWord.isAlive() /giveWord调用方法isAlive() giveWord=new WordThread(wordLabel); try giveWord.start(); catch(Exception exe) else if(e.getSource()=inputText) if(inputText.getText().equals(wordLabel.getText() score+; scoreText.setText(得分:+score); inputText.setText(null); WordThread.javapublic class ThreadWordMainClass public static void main(String args) new ThreadFrame(); ReadZipFile.javaimport java.io.*;import java.util.zip.*;public class ReadZipFile public static void main(String args) File f=new File(book.zip); File dir=new File(Book); byte b=new byte100; dir.mkdir(); try ZipInputStream in=new ZipInputStream(new FileInputStream(f); ZipEntry zipEntry=null; while(zipEntry=in.getNextEntry()!=null) File file=new File(dir,zipEntry.getName(); FileOutputStream out=new FileOutputStream(file); int n=-1; System.out.println(file.getAbsolutePath()+的内容:); while(n=in.read(b,0,100)!=-1) String str=new String(b,0,n); System.out.println(str); out.write(b,0,n); out.close(); in.close(); catch(IOException ee) System.out.println(ee); ReadFile.javaimport java.awt.*;import java.awt.event.*;import .*;import java.io.*;public class ReadURLSource public static void main(String args) new NetWin(); class NetWin extends Frame implements ActionListener,Runnable Button button; URL url; TextField text; TextArea area; byte b=new byte118; Thread thread; NetWin() text=new TextField(20); area=new TextArea(12,12); button=new Button(确定); button.addActionListener(this); thread=new Thread(this); Panel p=new Panel(); p.add(new Label(输入网址:); p.add(text); p.add(button); add(area,BorderLayout.CENTER); add(p,BorderLayout.NORTH); setBounds(60,60,360,300); setVisible(true); validate(); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0); ); public void actionPerformed(ActionEvent e) if(!(thread.isAlive() thread=new Thread(this); try thread.start(); catch(Exception ee) text.setText(我正在读取+url); public void run() try int n=-1; area.setText(null); String name=text.getText().trim(); url=new URL(name); String hostName= url.getHost(); int urlPortNumber= url.getPort(); String fileName= url.getFile(); InputStream in= url.openStream(); area.append(n主机:+hostName+端口:+urlPortNumber+包含的文件名字:+fileName); area.append(n文件的内容如下:); while(n=in.read(b)!=-1) String s=new Strin
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 北海市2025中共北海市铁山港区委统战部招聘编外人员2人(广西)笔试历年参考题库附带答案详解
- 包头市2025内蒙古包头市农牧科学技术研究所人才引进13人笔试历年参考题库附带答案详解
- 2025福建晟峵新能源发展有限公司招聘6人笔试参考题库附带答案详解
- 2025浙江钱江生物化学股份有限公司招聘12人(嘉兴市)笔试参考题库附带答案详解
- 2025年青藏铁路集团有限公司招聘(184人)笔试参考题库附带答案详解
- 2025年福建省晋江市兆壹建设发展有限公司招聘11人笔试参考题库附带答案详解
- 2025年度湖南兴湘资本管理有限公司招聘6人笔试参考题库附带答案详解
- 2025年国网冀北电力有限公司高校毕业生第二批招聘考试笔试参考题库附带答案详解
- 2025年亳州市公共交通集团有限公司招聘11人笔试参考题库附带答案详解
- 2025山东聊城市冠县国企控股公司招聘16人笔试参考题库附带答案详解
- 殡葬业务科管理制度
- JG/T 404-2013空气过滤器用滤料
- 大米委托加工合同范本
- 学校物品捐赠协议书
- 2025-2030国内地热能行业市场发展现状及竞争格局与投资发展前景研究报告
- 《财务报表分析课件》
- 《科研经费的使用与管理》课件
- 超市售后服务管理制度
- 贵州省考试院2025年4月高三年级适应性考试数学试题及答案
- 钢筋修复方案
- 7.1.1 两条直线相交(教学设计)-(人教版2024)
评论
0/150
提交评论