java操作题37套

基本操作

在考生文件夹中存有文件名为Java_1.java的文件,该程序是不完整的,请在注释行“//Found”下一行语句的下划线地方填入正确内容,然后删除下划线,请勿删除注释行或改动其他已有语句内容。存盘时文件必须存放在考生文件夹下,不得改变原有文件的文件名。
本题的要求是:
完善该程序并进行调试,使程序输出结果如下: 

在这里插入图片描述

import javax.swing.*;
public class Java_1{
   public static void main( String args[] ){
      //*********Found**********
      StringBuffer buf = new __________________( "Hello, how are you?" );
      String output = "buf = " + buf.toString() +
                      "\nlength = " + buf.length() +
                      "\ncapacity = " + buf.capacity();
      buf.ensureCapacity( 75 );
      output += "\n\nNew capacity = " + buf.capacity();
      buf.setLength( 10 );
      //*********Found**********
      __________ += "\n\nNew length = " + buf.length() +
                "\nbuf = " + buf.toString();
      JOptionPane.showMessageDialog( null, output,
         "字符串缓存长度和容量的实例",
      //*********Found**********
         _______________.INFORMATION_MESSAGE );
      //*********Found**********
      System.___________________( 0 );
   }
}

   

本题着重考察考生对类的使用和JOptionPane的理解情况。
本题中的第一个空格:buf为StringBuffer类型,因此在新建对象时应该new出StringBuffer类型,因此此处空格填入StringBuffer;
本题中的第二个空格:output作为输出的字符串变量,因此要将所有输出的内容存入output,因此此处空格填入output;
本题中的第三个空格:JOptionPane.showMessageDialog最后一个参数为图标类型,类型一般为JOptionPane,因此此处空格填入JOptionPane;
本题中的第四个空格:退出虚拟机程序一般使用"System.exit(0)",因此此处空格填入exit。
本评析仅作参考。

简单应用

在考生文件夹中存有文件名为Java_2.java的文件,该程序是不完整的,请在注释行
“//Found”下一行语句的下划线地方填入正确内容,然后删除下划线,请
勿删除注释行或改动其他已有语句内容。存盘时文件必须存放在考生文件夹下,不得改变原有文件的文件名。
本题的要求是:
程序中定义了二维点的类,类中定义了包括点的平移在内的部分方法。完善程序,使其运行 时的输出结果如下:
点的当前坐标:(5,5)
平移到:(8,9)

class Point{
   public int x,y;
   public Point() { 
   }
   public Point(int x,int y){
      this.x = x;
      this.y = y;
   }
   //*********Found**********
   public Point(____________ p){
      x = p.x;
      y = p.y;
   }
   public int getX(){
      return x;
   }
   public int getY(){
      return y;
   }
   public void moveTo(int x,int y){
      this.x = x;
      this.y = y;
   }
   public void moveTo(Point p){
      x = p.x;
      y = p.y;
   }
   public String toString(){
      return "("+ x + ","+ y + ")";
   }
   public void translate(int dx,int dy){ //平移
      this.x += dx;
      //*********Found**********
      ____________;
   }
}

public class Java_2 {
   public static void main(String args[]){
      //*********Found**********
      Point p = new ____________(5,5);
      System.out.println("点的当前坐标:("+p.x + "," + p.y+")");
      p.translate(3,4);
      //*********Found**********
      System.out.println("平移到:"+____________());
   }
}

   

本题着重考察考生对类的使用的理解情况。
本题中的第一个空格:p有两个参数:x和y,程序中有这两个参数的类只有Point,因此此处空格填入Point;
本题中的第二个空格:由于是平移,因此对x和y坐标的改变应该是一致的,因此此处空格填入this.y += dy;
本题中的第三个空格:p为坐标为(5,5)的新点,需要新建对象,因此此处空格填入Point;
本题中的第四个空格:输出结果为p平移之后的坐标值,Point提供了toString()方法可以输出当前的坐标值,因此此处空格填入p.toString。
本评析仅作参考。

综合应用

在考生文件夹中存有文件名为Java_3.java的文件,该程序是不完整的,请在注释行“//Found”下一行语句的下划线地方填入正确内容,然后删除下划线,请勿删除注释行或改动其他已有语句内容。存盘时文件必须存放在考生文件夹下,不得改变原有文件的文件名。
本题的要求是:
在标题为“Button Test”的窗口中显示一个按钮,当点击该按钮时将弹出另一个标题为“An Other”窗口(如图所示)。运行结果为: 

在这里插入图片描述

import java.awt.*;
import java.awt.event.* ;
     //*********Found********
import ___________________;   

     //*********Found********
public class Java_3 ________________ ActionListener{
    public static void main(String args[ ]){
        Java_3 tb = new Java_3();
     //*********Found********
        JFrame f = new JFrame("______________");  
        f.setSize(200,100);
        f.setLayout(new FlowLayout(FlowLayout.CENTER));

        JButton b = new JButton("Press the Button!");  /JButton
     //*********Found********
        b._________________(tb); 

     //*********Found********
        ________.add(b);
        f.addWindowListener(new WindowAdapter(){
              public void windowClosing(WindowEvent e){
                 System.exit(0);
              }
        });
        f.setVisible(true) ;
    }

     //*********Found********
    public void ________________(ActionEvent e){
        JFrame fr = new JFrame("An Other");   
        fr.setBackground(Color.green);
        fr.add(new JLabel("This frame shows when "+"pressing the button in Button Test"));
        fr.addWindowListener(new WindowAdapter(){
           public void windowClosing(WindowEvent e){
              System.exit(0);
           }
        });
        fr.pack();
        fr.setVisible(true) ;
    } 
}

本题着重考察考生对程序监听的理解情况。
本题中的第一个空格:JFrame为swing组件下的类型,因此使用之前要导入swing包,因此此处空格填入javax.swing.*;
本题中的第二个空格:ActionListener为接口,要继承接口使用implements关键字,因此此处空格填入implements;
本题中的第三个空格:图中窗口的标题栏为Button Test,在创建JFrame时直接确定标题,因此此处空格填入Button Test;
本题中的第四个空格:按钮创建完成后需要添加监听,因此此处空格填入addActionListener;
本题中的第五个空格:按钮创建完成后要添加到容器中,因此此处空格填入f;
本题中的第六个空格:按钮点击后要弹出另外一个窗口,因此要对按钮的点击监听填写完整的事件,程序中事件已经完成编写,因此此处空格填入actionPerformed。
本评析仅作参考。

  • 12
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值