全国计算机等级考试二级Java语言程序设计上机操作三解析.docx

上传人:b****2 文档编号:1215232 上传时间:2022-10-19 格式:DOCX 页数:7 大小:15.96KB
下载 相关 举报
全国计算机等级考试二级Java语言程序设计上机操作三解析.docx_第1页
第1页 / 共7页
全国计算机等级考试二级Java语言程序设计上机操作三解析.docx_第2页
第2页 / 共7页
全国计算机等级考试二级Java语言程序设计上机操作三解析.docx_第3页
第3页 / 共7页
全国计算机等级考试二级Java语言程序设计上机操作三解析.docx_第4页
第4页 / 共7页
全国计算机等级考试二级Java语言程序设计上机操作三解析.docx_第5页
第5页 / 共7页
点击查看更多>>
下载资源
资源描述

全国计算机等级考试二级Java语言程序设计上机操作三解析.docx

《全国计算机等级考试二级Java语言程序设计上机操作三解析.docx》由会员分享,可在线阅读,更多相关《全国计算机等级考试二级Java语言程序设计上机操作三解析.docx(7页珍藏版)》请在冰豆网上搜索。

全国计算机等级考试二级Java语言程序设计上机操作三解析.docx

全国计算机等级考试二级Java语言程序设计上机操作三解析

一、基本操作题

本题的功能是统计成绩不及格的人数,分数有89,90,56,90,89,45。

23,45,60,59,61。

publicclassjaval{

publicstaticvoidmain(String[]args(

int3score={56。

90。

89,23,45,61,60,59};

inthum=0;

;

inti=0:

while({

if(

sum++:

i++;

System.out.println(”<60:

”+sum;

第1处:

intsum=0

第2处:

i

第3处:

score[i]<60或score[i]<=59

【解析】第1处是定义变量,前面的intnum=0只是迷惑考生的;第2处为循环条件;第3处判断是否及格。

二、简单应用题

本题中,窗口的背景色为系统桌面的颜色,在窗口中分

别画空心和实心的黑色矩形、深灰色圆角矩形和浅灰色椭

圆形,并且画白色粗体的“欢迎学习Java!

”字符串。

importjava.awt.*;

importjavax.swin9.*;

publicclassjava2

{

publicstaticvoidmain(String[]args

{

FillFrameframe=newFillFrame(;

frame.setDefaultCloseOperation(JFrame.EXIT_

ON_CLOSE;

frame.show(;

}

}

classFillFrameextendsJFrame

{

publicFillFrame(

{

setTitle("java2":

setSize(WIDTH,HEIGHT;

FillPanelpanel=newFillPanel(;

panel.setBackground(SystemColor.desktop;

ContainercontentPane=getContentPane(;

contentPane.add(panel;

}

publicstaticfinalintWIDTH=400;

publicstaticfinalintHEIGHT=250;

}

classFitlPanelextendsJPanel

{

publicvoidpaintComponent(Graphicsg

{

;

g.setColor(newColor(10,10,10;

g.drawRect(10,10,100,30;

g.setColor(newColor(100,100,lOO;

g.drawRoundRect(150,10,100,30,15,15;

g.setColor(newColor(150,150,150;

g.drawOval(280,10,80,30;

g.setColor(newColor(10,10,10;

g.fillRect(10,ll0,100,30;

g.setColor(newColor(100,100,100;

g.fillRoundRect(150,110,100,30,15,15;

g.setColor(newColor(150,150,150;

g.fillOval(280,110,80,30;

g.setColor(Color.white;

Fontf=newFont("宋体”,,20;

g.setFont(f;

g.drawstring("欢迎学习Java!

",l50,200;

}

}

第1处:

super.paintComponent(g

第2处:

Font.Bold

【解析】第1处使用父类方法应使用super来引用;第2处为设置粗体。

三、综合应用题

本题的功能是对图形进行操作,包括旋转、移位、放大和剪切。

窗口中有4个单选按钮

和一个图形面板,图形面板中有一个矩形和该矩形移位操作后的图形,任选其中一个单选按钮,则图形面板中将显示该操作后的图形。

importjava.awt.*;

importjava.awt.event.*;

importjava.awt.geom.*;

importjava.util.*;

importjavax.swing.*;

publicclassjava3

{

publicstaticvoidmain(String[]args

{

JFrameframe=newTransformTestFrame(;

frame.setDefaultCloseOperation(JFrame.EXIT_

0N_CLoSE;

frame.show(;

}

}

classTransformTestextendsJFrame

{

publicTransformTestFrame(

{

setTitle("java3";

setSize(WIDTH,HEIGHT;

ContainercontentPane=getContentPane(;

canvas=newTransformPanel(;

contentPane.add(canvas,BorderLayout.CEN-

TER;

JPanelbuttonPanel=newJPanel(:

ButtonGroupgroup=newButtonGroup(;

JRadioButtonrotateButton

=newJRadioButton("旋转",true;

buttonPanel.add(rotateButton;

group.add(rotateButton;

rotateButton.addActionListener(new

ActionListener(

{

publicvoidactionPerformed(ActionEventevent

{

canvas.setRotate(;

}

};

JRadioButtontrans|ateButton

=newJRadioButton("移位",false;

buttonPanel.add(translateButton;

group.add(translateButton;

translateButton.addActionListener(newActionLiatener(

publicvoidactionPerformed(ActionEventevent{

canvas.setTranslate(;

}

};

JRadioButtonscaleButton

=newJRadioButton("放大",false;

buttonPanel.add(scaleButton:

group.add(scaleButton;

scaleButton.addActionListener(newActionListener(

{

publicvoidactionPerformed(ActionEventevent{

canvas.setScale(;

}

};

JRadioButtonshearButton

=newJRadioButton("剪切",false;

buttonPanel.add(shearButton:

group.add(shearButton;

shearButton.addActionListener(newActionListener(

{

publicvoidactionPerformed(ActionEventevent{

canvas.setShear(;

}

};

contentPane.add(buttonPanel,BorderLayout.NORTH:

}

privateTransformPanelcanvas;

privatestaticfinalintWIDTH=300;

privatestaticfinalintHEIGHT=300;

}

classTransformPanelextendJPanel

{

publicTransformPanel(

{

square=newRectangle2D.Double(-50,-50,

100,100;

t=newAffineTransform(;

setRotate(;

}

publicvoidpaintComponent(

{

super.paintComponent(g;

Graphics2Dg2=(Graphies2Dg;

g2.translate(getWidth(/2,getHeight(/2:

g2.setPaint(Color.gray;

g2.draw(square;

g2.transform(t;

g2.setPaint(Color.black;

g2.draw(square;

}

publicvoidsetRotate(

{

t.setToRotation(Math.toRadians(30;

repaint(;

}

publicvoidsetTranslate(

{

t.setToTranslation(20,15;

repaint(;

}

publicvoidsetScale(

{

t.setToScale(2.0,1.5:

repaint(;

}

publicvoidsetShear(

{

t.setToShear(-0.2,O;

repaint(;

}

privateRectangle2Dsquare;

privateAffineTransformt;

}

第1处:

classTransformTestFrameextendsJFrame

第2处:

classTransformPanelextendsJFrame

第3处:

publicvoidpaintComponent(Graphicsg

【解析】第1处类中公有对象名称应与类名一致;第2处为继承的父类不正确;第3处从下面的super.paintComponent(g;可判断出应有参数Graphicsg。

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

当前位置:首页 > 幼儿教育 > 幼儿读物

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1