JAVA期末考试整理资料.docx

上传人:b****2 文档编号:1991383 上传时间:2023-05-02 格式:DOCX 页数:41 大小:20.67KB
下载 相关 举报
JAVA期末考试整理资料.docx_第1页
第1页 / 共41页
JAVA期末考试整理资料.docx_第2页
第2页 / 共41页
JAVA期末考试整理资料.docx_第3页
第3页 / 共41页
JAVA期末考试整理资料.docx_第4页
第4页 / 共41页
JAVA期末考试整理资料.docx_第5页
第5页 / 共41页
JAVA期末考试整理资料.docx_第6页
第6页 / 共41页
JAVA期末考试整理资料.docx_第7页
第7页 / 共41页
JAVA期末考试整理资料.docx_第8页
第8页 / 共41页
JAVA期末考试整理资料.docx_第9页
第9页 / 共41页
JAVA期末考试整理资料.docx_第10页
第10页 / 共41页
JAVA期末考试整理资料.docx_第11页
第11页 / 共41页
JAVA期末考试整理资料.docx_第12页
第12页 / 共41页
JAVA期末考试整理资料.docx_第13页
第13页 / 共41页
JAVA期末考试整理资料.docx_第14页
第14页 / 共41页
JAVA期末考试整理资料.docx_第15页
第15页 / 共41页
JAVA期末考试整理资料.docx_第16页
第16页 / 共41页
JAVA期末考试整理资料.docx_第17页
第17页 / 共41页
JAVA期末考试整理资料.docx_第18页
第18页 / 共41页
JAVA期末考试整理资料.docx_第19页
第19页 / 共41页
JAVA期末考试整理资料.docx_第20页
第20页 / 共41页
亲,该文档总共41页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

JAVA期末考试整理资料.docx

《JAVA期末考试整理资料.docx》由会员分享,可在线阅读,更多相关《JAVA期末考试整理资料.docx(41页珍藏版)》请在冰点文库上搜索。

JAVA期末考试整理资料.docx

JAVA期末考试整理资料

JAVA期末整理资料

1、

  importjava.awt.*;

  importjava.awt.event.*;

  importjavax.swing.*;

  publicclassTestextendsJFrame{

  intx1,y1,x2,y2;publicTest(){

  setVisible(true);

  setSize(300,300);

  addWindowListener(newWindowAdapter(){

  publicvoidwindowClosing(WindowEvente){

  System.exit(0);}});

  addMouseListener(

  newMouseAdapter(){

  publicvoidmousePressed(MouseEvente){

  x1=e.getX();

  y1=e.getY();}});

  addMouseMotionListener(newMouseMotionAdapter(){

  publicvoidmouseDragged(MouseEvente){

  x2=e.getX();

  y2=e.getY();

  repaint();}});

  }

  publicvoidpaint(Graphicsg)

  {

  g.drawLine(x1,y1,x2,y2);

  x1=x2;

  y1=y2;

  }

  publicstaticvoidmain(Stringargs[])

  {

  newTest();

  }

  }

2、classTransport

{

intspeed,load;

publicTransport(){};

publicTransport(intspeed,intload)

{

this.speed=speed;

this.load=load;

}

publicstaticvoidmain(String[]args)

{

}

}

classvehicleextendsTransport

{

intwheels,weight;

publicvehicle(){};

publicvehicle(intspeed,intload,intwheels,intweight)

{

super(speed,load);

this.wheels=wheels;

this.weight=weight;

}

}

classAirplaneextendsTransport

{

intengintype,enginnumber;

publicAirplane(){};

publicAirplane(intspeed,intload,intengintype,intenginnumber)

{

super(speed,load);

this.engintype=engintype;

this.enginnumber=enginnumber;

}

}

3、classTestRead{

publicstaticvoidmain(String[]args){

intx=0;

try{

x=System.in.read();

}catch(Exceptione){}

while(x!

='q'){

System.out.println((char)x);

try{

x=System.in.read();

}catch(Exceptione){}

}

}

}

4、classAA

{

publicvoidexchange(inta,int[]array)

{

a=50;

array[1]=30;

}

}

classtestAA

{

publicstaticvoidmain(String[]args)

{

intaa=3;

int[]array={1,2,3};

AAa=newAA();

a.exchange(aa,array);

System.out.println(aa);

System.out.println(array[1]);

}

}

5、publicclassPerson{

publicStringname;

publicintage;

publicStringaddr;

Person(){}

publicPerson(Stringname,intage){

this.name=name;

this.age=age;

}

publicPerson(Stringname,intage,Stringaddr){

this(name,age);

this.addr=addr;

}

publicvoidgetInfo(){

System.out.println(name);

System.out.println(age);

}

}

classStudentextendsPerson{

publicintgrade;

publicstudent(){}

publicStudent(Stringname,intage,intgrade){

super(name,age);

this.grade=grade;

}

publicvoidgetInfo(){

super.getInfo();

System.out.println(grade);

}

publicstaticvoidmain(Srting[]args){

Students=newStudent("student",16,2);

s.getInfo();

}

}

6、interfaceStudentManageInterface

{

doublemoney=0;

voidsetFee(doublemoney);

doublegetFee();

}

interfaceTeacherManageInterface

{

doubletmoney=0;

voidsetPay(doubletmoney);

doublegetPay();

}

classGraduateimplementsStudentManageInterface,TeacherManageInterface

{

Stringname,sex;

intage;

doublefee,pay;

publicGraduate(){};

publicGraduate(Stringname,Stringsex,intage,doublefee,doublepay)

{

setPay(pay);

setFee(fee);

}

publicvoidsetPay(doublepay){

this.pay=pay;

}

publicdoublegetPay(){

returnpay;

}

publicvoidsetFee(doublefee){

this.fee=fee;

}

publicdoublegetFee(){

returnfee;

}

}

publicclassQuestion7{

publicstaticvoidmain(String[]agrs)

{

Graduateg1=newGraduate("zhangsan","男",17,12,1500);

if(g1.getFee()*12-g1.getPay()<2000)

{

System.out.println("providealoan");

}

}

}

7、packagetest1;

importjava.awt.*;

importjava.awt.event.*;

publicclassIntegrationimplementsTextListener,ActionListener{

Framef;

TextFieldtfDividend,tfDivisor;

Labellb;

ButtonbtCount,btClean;

publicstaticvoidmain(String[]args){

newIntegration();

}

publicIntegration(){

f=newFrame("Integration");

f.setLayout(newGridLayout(4,1));

tfDividend=newTextField();

tfDividend.addTextListener(this);//textValueChanged(TextEvente)

tfDivisor=newTextField();

tfDivisor.addTextListener(this);

lb=newLabel();

btCount=newButton("除");

btCount.setActionCommand("btCount");

btCount.setBackground(Color.blue);

btCount.addActionListener(this);//actionPerformed(ActionListenere)

btClean=newButton("清除");

btClean.setActionCommand("btClean");

btClean.setForeground(Color.red);

btClean.addActionListener(this);

Panelp=newPanel(newGridLayout(1,2));

p.add(btCount);

p.add(btClean);

f.add(tfDividend);

f.add(tfDivisor);

f.add(lb);

//f.add(btCount);

//f.add(btClean);

f.add(p);

//f.addWindowListener(this);

f.addWindowListener(

newWindowAdapter(){

publicvoidwindowClosing(WindowEvente){

System.exit(0);

}

}

);

f.pack();

f.setVisible(true);

}

publicvoidtextValueChanged(TextEvente){

lb.setText(tfDividend.getText());

}

publicvoidactionPerformed(ActionEvente){

Stringcmd=e.getActionCommand();

if(cmd.equals("btCount"))

lb.setText(Double.parseDouble(tfDividend.getText())+"/"+Double.parseDouble(tfDivisor.getText())+"="+divide(Double.parseDouble(tfDividend.getText()),Double.parseDouble(tfDivisor.getText())));

elseif(cmd.equals("btClean")){

tfDividend.setText("");

tfDivisor.setText("");

lb.setText("");

}

}

publicdoubledivide(doublex,doubley){

returnx/y;

}

}

8、packagetest1;

importjava.awt.*;

importjava.awt.event.*;

publicclassIntegrationimplementsTextListener,ActionListener{

Framef;

TextFieldtfDividend,tfDivisor;

Labellb;

ButtonbtCount,btClean;

publicstaticvoidmain(String[]args){

newIntegration();

}

publicIntegration(){

f=newFrame("Integration");

f.setLayout(newGridLayout(4,1));

tfDividend=newTextField();

tfDividend.addTextListener(this);//textValueChanged(TextEvente)

tfDivisor=newTextField();

tfDivisor.addTextListener(this);

lb=newLabel();

btCount=newButton("除");

btCount.setActionCommand("btCount");

btCount.setBackground(Color.blue);

btCount.addActionListener(this);//actionPerformed(ActionListenere)

btClean=newButton("清除");

btClean.setActionCommand("btClean");

btClean.setForeground(Color.red);

btClean.addActionListener(this);

Panelp=newPanel(newGridLayout(1,2));

p.add(btCount);

p.add(btClean);

f.add(tfDividend);

f.add(tfDivisor);

f.add(lb);

//f.add(btCount);

//f.add(btClean);

f.add(p);

//f.addWindowListener(this);

f.addWindowListener(

newWindowAdapter(){

publicvoidwindowClosing(WindowEvente){

System.exit(0);

}

}

);

f.pack();

f.setVisible(true);

}

publicvoidtextValueChanged(TextEvente){

lb.setText(tfDividend.getText());

}

publicvoidactionPerformed(ActionEvente){

Stringcmd=e.getActionCommand();

if(cmd.equals("btCount"))

lb.setText(Double.parseDouble(tfDividend.getText())+"/"+Double.parseDouble(tfDivisor.getText())+"="+divide(Double.parseDouble(tfDividend.getText()),Double.parseDouble(tfDivisor.getText())));

elseif(cmd.equals("btClean")){

tfDividend.setText("");

tfDivisor.setText("");

lb.setText("");

}

}

publicdoubledivide(doublex,doubley){

returnx/y;

}

}

9、importjava.awt.*;

importjava.awt.event.*;

publicclassFBLimplementsActionListener{

Framef;

Buttonb1,b2;

Labellb;

publicFBL(){

f=newFrame("FBL");

f.setLayout(newGridLayout(3,1));

b1=newButton("b1");

b2=newButton("b2");

b1.addActionListener(this);

b2.addActionListener(this);

lb=newLabel();

f.add(b1);

f.add(b2);

f.add(lb);

f.addWindowListener(newWindowAdapter(){

publicvoidwindowClosing(WindowEvente){

System.exit(0);

}

});

f.pack();

f.setVisible(true);

}

publicvoidactionPerformed(ActionEvente){

Buttonb=(Button)e.getSource();

lb.setText(b.getLabel());

}

publicstaticvoidmain(String[]args){

newFBL();

}

}

10、importjava.io.*;

publicclassFileRuntimeTest

{

publicstaticvoidmain(String[]args)

{

Filef=newFile(args[1]);

if(f.exists())

try{

Processp=null;

p=Runtime.getRuntime().exec(args);

Thread.sleep(5000);

p.destroy();

}catch(Exceptione){

e.printStackTrace();

}

else

try

{

f.createNewFile();

}

catch(Exceptione)

{

System.out.println(e.getMessage());

}

}

}

11、importjava.awt.*;

importjava.awt.event.*;

importjava.io.*;

publicclassMyNotepadextendsWindowAdapterimplementsActionListener{

Framef;

Buttonbtn;

TextAreata;

Stringfilename;

publicstaticvoidmain(String[]args){

newMyNotepad(args[0]);

}

publicMyNotepad(Stringfilename){

this.filename=filename;

f=newFrame(filename);

f.addWindowListener(this);

btn=newButton("save");

btn.addActionListener(this);

ta=newTextArea(10,40);

f.add(ta,BorderLayout.CENTER);

f.add(btn,BorderLayout.SOUTH);

f.pack();

f.setVisible(true);

}

publicvoidactionPerformed(ActionEvente){

try{

FileWriterfout=newFileWriter(filename,false);

fout.write(ta.getText());

fout.close();

}

catch(IOExceptionioe){

System.err.println(ioe);

}

}

publicvoidwindowClosing(WindowEvente){

System.exit(0);

}

}

12、importjava.awt.*;

importjava.awt.event.*;

importjava.io.*;

publicclassMyNotepadextendsWindowAdapterimplementsActionListener{

Framef;

Buttonbtn;

TextAreata;

Stringfilename;

publicstaticvoidmain(String[]args){

newMyNotepad(args[0]);

}

publicMyNotepad(Stringfilename){

this.filename=filename;

f=newFrame(filename);

f.addWindowListener(this);

btn=n

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 农林牧渔 > 水产渔业

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2