




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、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
2、); 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:"+we
3、ight); 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
4、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() he
5、ight=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("京劇術(shù)語"); public class Example public static void main(String args) Chin
6、aPeople chinaPeople=new ChinaPeople(); AmericanPeople americaPeople=new AmericanPeople(); BeijingPeople beijingPeople=new BeijingPeople(); chinaPeople.speakHello(); americanPeople.speakHello(); beijingPeople.speakHello(); americanPeople.averageHeight(); beijingPeople.averageHeight(); chinaPeople.ave
7、rageWeight(); 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 ActionListe
8、ner 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
9、=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); textResu
10、lt.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 windowClo
11、sing(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(""+n
12、umber2); 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(&
13、quot;你回答錯誤"); catch(NumberFormatException ex) message.setText("請輸入數(shù)字字符"); 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 number
14、One; 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(a
15、nswer=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("算術(shù)測試"); WordT
16、hread.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; ThreadFra
17、me.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
18、("",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,B
19、orderLayout.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(Win
20、dowEvent e) System.exit(0); ); public void actionPerformed(ActionEvent e) if(e.getSource()=button) if(!(giveWord.isAlive() /giveWord調(diào)用方法isAlive() giveWord=new WordThread(wordLabel); try giveWord.start(); catch(Exception exe) else if(e.getSource()=inputText) if(inputText.getText().equals(wordLabel.ge
21、tText() score+; scoreText.setText("得分:"+score); inputText.setText(null); WordThread.javapublic class ThreadWordMainClass public static void main(String args) new ThreadFrame(); ReadZipimport java.io.*;import java.util.zip.*;public class ReadZipFile public static void main(String args) File
22、("book.zip"); File("Book"); byte b=new byte100; dir.mkdir(); try ZipInputStream in=new ZipInputStream(new (f); ZipEntry zipEntry=null; while(zipEntry=in.getNextEntry()!=null) (); out=new (file); int n=-1; System.out.println()+"的內(nèi)容:"); while(n=in.read(b,0,100)!=-1) Strin
23、g 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); Readimport java.awt.*;import java.awt.event.*;impor.*;import java.io.*;public class ReadURLSource public static void main(String args) new NetWin(); class NetWin
24、 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=n
25、ew Panel(); p.add(new Label("輸入網(wǎng)址:"); 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
26、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 url
27、PortNumber= url.getPort(); String url.getFile(); InputStream in= url.openStream(); area.append("n主機:"+hostName+"端口:"+urlPortNumber+"包含的文件名字:"+); area.append("n文件的內(nèi)容如下:"); while(n=in.read(b)!=-1) String s=new String(b,0,n); area.append(s); catch(MalformedURLException e1) text.setText(""+e1); return; catch(IOException e1) text.setText(""+e1); return; import java.util.*;public class E
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 三年級上冊數(shù)學教案-7.4分數(shù)的初步認識(一)練習十一 |蘇教版
- 六年級上冊數(shù)學教案-6.1 比的認識(一)|北師大版
- 加法運算律教案2024-2025學年數(shù)學四年級上冊 西師大版
- 2025年轉(zhuǎn)讓有限公司股權(quán)合同
- 一致行動人協(xié)議(2025年版)-@-1
- 一年級上冊數(shù)學教案-總復習第1課時數(shù)與代數(shù)(1)∣北師大版
- 河南省三門峽市陜州區(qū)三年級英語下學期期中試題(人教PEP版-含答案)
- 《秋詞》歷年中考古詩欣賞試題匯編(截至2022年)
- 2025年河南省信陽市單招職業(yè)適應性測試題庫及答案1套
- 2025年湖南鐵路科技職業(yè)技術(shù)學院單招職業(yè)技能測試題庫參考答案
- 4《海燕》公開課一等獎創(chuàng)新教學設計
- 2022年全國職業(yè)院校技能大賽賽項-ZZ-2022039戲曲表演賽項基礎(chǔ)知識試題答案(70公開題)
- 中國高血壓防治指南(2024年修訂版)核心要點解讀
- T-CERS 0007-2020 110 kV及以下變電站 并聯(lián)型直流電源系統(tǒng)技術(shù)規(guī)范
- 金屬焊接和切割作業(yè)教案
- 定制公司用工合同范本
- 《遙感地質(zhì)學》全冊配套完整教學課件
- 學科帶頭人工作計劃
- 城市更新暨老舊小區(qū)改造二期項目-初步設計說明書
- 礦石買賣協(xié)議書
- 2024年岳陽職業(yè)技術(shù)學院單招職業(yè)技能測試題庫附答案
評論
0/150
提交評論