1
2
3
代码并没有将图像放大
第1题:
下列Applet在坐标 ( 20,20) 处显示一幅GIF图像,在横线处填入正确的语句。
import java. net.*;
import java. awt.*;
import java. applet.*;
public class Test extends Applet {
Image IMG;
public void init() {
URL url = getDocumentBase ();
String name="IMG.gif";
【 】
}
public void paint(Graphics g) {
g. drawImage ( IMG,20,20,this);
}
}
第2题:
下面Applet在窗口中实现一个不可编辑的TextField,并且显示“ok”。在横线处填入正确的语句。
import java.applet.Applet;
import java.awt.t;
public class Test extends Applet {
TextField tf;
public void init () {
setLayout (new GridLayout(1,0);
tf=new TextField("ok");
【 】
add(tf);
}
}
第3题:
下面是一个Applet程序,程序的功能输出一个彩色窗体。请改正程序中的错误(有下划线的语句),使程序能输出正确结果。
注意:不改动程序的结构,不得增行或删行。
程序的输出结果为:
import java.awt.*;
import java.awt.image.*;
import java.applet.Applet;
public class MemoryImage extends Applet
{
Image IMG nClick=over(this) title=放大;
public void init()
{
Dimension d=getSize();
int w=d.width,h=d.height;
int pix[ ]=new int[w*h];
int index=0;
for(int y=0;y<h;y++)
for(int x=0;x<w;x++)
{
int red=(x|y)&&0xff;
int green=(x*2|y*2)&0xff;
int blue=(x*4|y*4)&0xff;
pix[index++]=(255<<24)|(red<<16)|(green<<8)|blue;
}
IMG nClick=over(this) title=放大=createImage(new FilteredImageSource(w,h,pix, 0,w));
}
public void paint(Graphics g)
{
g.drawImage(IMG nClick=over(this) title=放大, 0,0,super);
}
}
ex36_3.html:
<html>
<head>
<title>A Simple Program</title>
</head>
<body>
<applet code=" MemoryImage.class" width=800 height=400>
</applet>
</body>
</html>
第4题:
将下面的程序补充完整。
注意:不改动程序结构,不得增行或删行。
import java.appplet.Applet;
import java.awt.Graphics;
public class ex1 extends Applet
{
public void paint(Graphics______)
{
int i=682;
gap.drawstring(Integer.______(i),20,60);
}
}
第5题:
关于下面程序段的说法,正确的是 import java.applet.*; import java.awt.*; public class Test extends Applet{ Image IMG nClick=over(this) title=放大; public void init(){ IMG nClick=over(this) title=放大=new Image(); } public void paint(Graphics g){ g.drawImage(IMG nClick=over(this) title=放大,0,0,this); } }
A.该程序段可以正常运行
B.程序中所创建的Image为空,但可以显示
C.程序中所创建的Image不为空
D.程序中所创建的Image为空,不能显示
第6题:
在以下程序中,鼠标单击小应用程序的某一点,则会在该点显示一个图标,如果双击,则会清除该图标。且在浏览器的状态栏上会显示鼠标单击位置的坐标。运行结果如下图所示。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。
注意:不改动程序的结构,不是增行或删行。
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Example3_1 extends Applet
{
int xPoint, yPoint;
int sum;
Image displayIm;
public void init()
{
displayIm = getImage("ms.jpg");
addMouseListener(new SClickMouse()) ;
sum = 2;
}
public void paint(Graphics g)
{
if(sum == 1)
g.drawImage(displayIm, xPoint, yPoint, this);
else
g.fillRect(xPoint, yPoint, 60, 60);
}
public class SClickMouse implements MouseListener
{
public void mouseClicked(MouseEvent mouse)
{
sum = mouse.getClickCount();
xPoint = mouse.getX();
yPoint = mouse.getY();
paint();
}
public void mouseEntered(MouseEvent mouse)
{
}
public void mouseExited(MouseEvent mouse)
{}
public void mousePressed(MouseEvent mouse)
{
xPoint = mouse.getX();
yPoint = mouse.getY();
showStatus("x="+xPoint+",y-"+yPoint);
}
public void mouseReleased(MouseEvent mouse)
}
}
}
}
Exampie3_1.html:
<html>
<head><title>Example3_1</title></head>
<body>
<applet code="Example3_1.class" width="400" height="500">
</applet>
</body>
</html>
第7题:
下面是一个Apple(程序,其功能是播放动画。要求根据给出的3幅图片设计1个动画。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。
注意:不改动程序的结构,不得增行或删行。
程序运行结果如下:
import java.awt.*;
import java.applet.*;
import java.awt.image.*;
/*
<applet code="ex24_3.class" width=800 height=400 >
</applet>
*/
public class ex24_3 extends Applet implements Runnable {
Image[] images=new Image[4];
Image image;
int IMG nClick=over(this) title=放大Number=3;
int currentImage=0;
Thread thisThread;
public void init(){
for (int x=0;x<IMG nClick=over(this) title=放大Number;x++){
images[x]= getImage(getCodeBase(),"IMG nClick=over(this) title=放大"+x+".gif");
}
image=images[0];
}
public void paint(Graphics g){
g.drawImage(image[0],0,0,null);
}
public void update(Graphics g){
paint(g);
}
public void start(){
thisThread = new Thread(this);
thisThread.start();
}
public void stop(){
thisThread.stop();
thisThread=null;
}
public void run(){
while(true){
currentImage++;
currentImage=IMG nClick=over(this) title=放大Number;
image=images[IMG nClick=over(this) title=放大Number];
repaint();
try{
thisThread.sleep(100);
}
catch (Exception e){}
}
}
}
ex24_3, html
<HTML>
<HEAD>
<TITLE>ex24_3</TITLE>
</HEAD>
<BODY>
<applet code="ex24_3.class" width=800 height=400 >
</applet>
</BODY>
</HTML>
第8题:
关于下面程序段的说法,正确的是 import javA.applet.*; import java.awt,*; public class Test extends Applet { Image IMG nClick=over(this) title=放大; public void init(){ IMG nClick=over(this) title=放大=new Image(); } public void paint(Graphics g){ g.drawlmage(IMG nClick=over(this) title=放大,0,0,this); } }
A.该程序段可以正常运行
B.程序中所创建的Image为空,但可以显示
C.程序中所创建的Image不为空
D.程序中所创建的Image为空,不能显示
第9题:
下列是一个Java Applet程序,输出结果是(要求只写出在Applet容器内显示的内容) import java.awt.*; import java.applet.*; public class Testuu extends Applet { float[]x={1.2f,3.4f,5.6f,7.8f}; public void paint(Graphics g) { int s=0; for(int i=0;i〈x.length;i++) s+=(int)x[i]; g.drawstring(" "+s,30,60); } }
A.15
B.16
C.16
D.17
第10题:
●试题六
【说明】
下面是一个Applet程序,其功能是在绘图区域中通过鼠标的移动来绘制直线,并且有清除绘图区域按钮,用来清除已经绘制的图像。
程序运行结果如图5所示。
图5
import javA.awt.*;
import javA.applet.*;
/*
<applet code=ex6_7.class width=800 height=400>
</applet>
*/
public class ex6_7 extends Applet{
private Button btn;
private boolean bDraw, bClear;
private int upX, upY,downX, downY;
public void init(){
setLayout(null);
bClear = false;
bDraw = false;
btn = new Button("clear");
btn.reshape(250, 150, 70, 30);
add(btn);
}
public void paint(Graphics g){
if(bClear){
g.clearRect(0, 0, getSize().width, getSize().height);
(1) ;
}
if(bDraw){
g.drawLine( (2) );
bDraw = false;
}
}
public void update(Graphics g){
(3) ;
}
public boolean mouseDown(Event event, int x, int y){
downX = x;
downY = y;
return true;
}
public boolean mouseUp(Event event, int x, int y){
upX = x;
upY = y;
(4) ;
repaint();
return true;
}
public boolean action(Event event, Object object){
if ( (5) ){
bClear = true;
repaint();
}
return true;
}
}
ex6_7.html
<HTML>
<HEAD>
<TITLE> ex6_7 </TITLE>
</HEAD>
<BODY>
<applet code=" ex6_7.class" width=800 height=400 >
</applet>
</BODY>
</HTML>
第11题:
请在下划线处填入代码,使程序能够正确运行。
import java .awt.*;
import java .applet.*;
public class SayHi extends Applet{
public void【 】(Graphics g){
g .drawString(“Hi!”20,20);
}
}
第12题:
Import java.applet.Applet; Import java.awt*; Public class ImageDemo extends Applet{ Image img; Public void init(){ Img=getImage(getCodeBase(),”11.gif”);//1 } Public void paint(Graphics g){ Int w=img.getHeight(this); Int h=img.getHeight(this); g.drawImage(img,120,60,w/2,h/2,this);//2 g. drawImage(img,150,0,w*2,h*2,this);//3 } }以上代码第()行将图像放大。
第13题:
在下面Java Applet程序的下画线处填入代码,使程序完整并能够正确运行。
import java.applet.*;
import java.awt.*;
public class HelloWorld ______ {
public void paint(Graphics g) {
g.drawString("Hello World!",25,25);
}
}
第14题:
下面是一个Applet程序,其功能是绘制三维矩形以使该矩形面凹下,并将图像放入凹下的矩形面中。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。
注意:不改动程序的结构,不得增行或删行。
源程序文件代码清单如下:
import java.awt.*;
import java.applet.*;
import java.awt.image.*;
import java.util.*;
import java.net.*;
/*
<applet code="ex01_3.class"width=800 height=400>
</applet>
*/
public class ex01_3 extends Applet
{
private Image IMG nClick=over(this) title=放大;
public void init()
{
URL url=getCodeBase();
IMG nClick=over(this) title=放大=getImage(url,"ex01_3.gif");
MediaTracker mt=new MediaTracker();
mt.addImage(IMG nClick=over(this) title=放大,1);
try
{
mt.waitForAll();
} catch(Exception e)
{
e.printStackTrace();
}
setBackground(Color.black);
}
public void paint(Graphics g)
{
int thick=3,x=10,y=10;
g.drawImage(IMG nClick=over(this) title=放大,x,y);
g.setColor(Color.lightGray);
int w = IMG nClick=over(this) title=放大.getWidth(this);
int h = IMG nClick=over(this) title=放大.getHeight(this);
for(int i=0;i<thick;i++)
g.draw3DRect(x,y,w+(a*i),true);
}
}
ex01 3.html
<HTML>
<HEAD>
<TITLE>ex01_3</TITLE>
</HEAD>
<BODY>
<applet code="ex01_3.class"width=800 height=400>
</applet>
</BODY>
</HTML>
第15题:
下面程序的输出结果是( )。 import java.awt.*; import java.applet.*; public class HelloApplet extends Applet { public void paint(Graphics g) { g.drawstring("Hello World!", 20, 20); } }
A.20,20
B.Hello World!
C.编译不能通过
D.以上都不对
第16题:
请将下面的Applet程序补充完整。
import java. awt. *;
import java. applet. *;
public class Hi【 】{
public void paint(Graphics g){
g. drawString("Hi!", 25, 25);
}
}
第17题:
下列代码的输出结果是( )。
class parent
{
void printme()
{
System.out.println("parent");
}
}
class child extends parent
{
void printme()
{
System. out.println("child");
}
void printall()
{
super, printme();
this.printme();
printme();
}
}
public class test
{
public static void main(String args[])
{
child myc=new child();
myc.printall();
}
}
A.import java.awt.*;
B.import java.applet.applet;
C.import java.io.*;
D.import java, awt.graphics;
第18题:
阅读以下说明和JAVA 2代码,将应填入(n)处的字句写在对应栏内。
[说明]
以下程序实现了在applet里移动图形文件,仔细阅读代码和相关注释,将程序补充完整。
[代码6-1]
import j ava. awt. *;
import j ava.awt.event.*;
import java.applet. Applet;
public class AppCIU extends Applet implements MouseMotionListener, MouseListener
{
Image IMG nClick=over(this) title=放大; // 声明 Image 类类型的变量 IMG nClick=over(this) title=放大
int x=70,y=60,posX=70,posY=60,dx,dy;
public void init ( )
{
IMG nClick=over(this) title=放大=getImage ( getCodeBase ( ) ,"mouse.gif" ); //载入影像
addMouseListener ( this );
addMouseMotionListener ( this );
}
public void mousePressed ( MouseEvent e )
{
dx=e.getX()-posX; //取得按下之点与基准点X方向的距离
dy=e.getY()-posY; //取得按下之点与基准点Y方向的距离
}
public void mouseDragged ( MouseEvent e )
{
(1)
(2)
if ( dx>0 && dx<120 && dy>0 && dy<60 ) //如果指针落在图形上方
{
Graphics g=getGraphics ( );
(3)
}
}
public void paint ( Graphics g )
{
(4)
(5)
(6)
}
public void mouseMoved ( MouseEvent e ) {};
public void mouseReleased ( MouseEvent e ) {};
public void mouseEntered ( MouseEvent e ) {};
public void mouseExited ( MouseEvent e ) {};
public void mouseClicked ( MouseEvent e ) {};
}
第19题:
下列Applet实现键盘事件处理,当一个键按下时,判断是否为26个英文字母,并输出该字母。选择正确的语句填入横线处。 import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class ex34 extends Applet { String str = ""; public void init() { addKeyListener (new KeyAdapter (} { ______ { char ch; ch = ke.getKeyChar(); if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) str = "字母:"+ ch; else str ">"不是字母"; repaint(); } }); requestFocus(); } public void paint(Graphics g) { g.drawString(str, 50, 50); } }
A.public void keyPress(KeyEvent ke)
B.public void keyTyped(KeyEvent ke)
C.public void keyTyped(Event ke)
D.public void keyPressing(KeyEvent ke)
第20题:
下列代码的下画线处应填入的方法名是( )。 import java.awt.*; import java.applet.*; public class Hello extends Applet{ public void (Graphics g){ 9.drawstring("How are you!",l0,10); } }
A.repaint
B.println
C.paint
D.show
第21题:
下面程序的输出结果是( )。 import java. awt.*; import java. applet.*; public class HelloApplet extends Applet { public void paint(Graphics g) { g.drawString("Hello World! ",20,20); } }
A.20,20
B.Hello World!
C.编译不能通过
D.以上都不对
第22题:
●试题七
【说明】
下面是一个Applet程序,其功能是将完整的图像显示于Applet的区块中,然后可以通过拖动鼠标让图像随着鼠标拖动的轨迹而移动。
程序运行结果如图5所示。
图5
import java.applet.*;
import java.awt.*;
/*
<applet code="ex4_7.class" width=800 height=400 >
</applet>
*/
public class ex4_7 extends Applet{
private Image iImg;
private int xPos,yPos;
public void init(){
xPos = yPos =(1);
iImg = getImage((2)"ex4_7.jpg");
}
public void paint(Graphics g){
g.drawImage(iImg,xPos,yPos,(3));
}
public boolean(4)(Event e,int x,int y){
xPos = x;
yPos = y;
(5);
return true;
}
}
ex4_7.html
<HTML>
<HEAD>
<TITLE>ex4_7</TITLE>
</HEAD>
<BODY>
<applet code="ex4_7.class" width=800 height=400 >
</applet>
</BODY>
</HTML>
●试题七
【答案】(1)0(2)getDocumentBase()
(3)this
(4)mouseDrag
(5)repaint()
【解析】本题主要考查在Applet窗口中显示图像,并结合鼠标事件处理的综合应用。解题关键是熟悉图像文件的加载过程,会跟踪鼠标拖动的事件,并将鼠标在Applet窗口中的坐标信息作为参数传递给drawImage()方法,用于在新的位置显示图像,从而实现拖动效果。本题中,getImage()方法应该有2个参数,第一个参数是getDocumentBase()方法的返回值,即图像文件的路径;drawImage()方法最后一个参数应该是this,确定是在当前运行的对象中绘制图像;应该调用repaint()方法,进行重画,而不是paint()方法。
第23题:
( 8 )在下列 Java applet 程序的横线处填入代码,使程序完整并能够正确运行。
Import java. awt. *;
Import java. applet. *;
Public class Greeting extends applet{
Public void 【 8 】 (Graphics g) {
g.drawSting( “ how are you! ” ,10,10);
}
}
第24题:
1
2
3
代码并没有将图像放大