一起答
主观

本题的功能是对图形进行操作,包括旋转、移位、放大和剪切。窗口中有4个单选按钮和一个图形面板,图形面板中有一个矩形和该矩形移位操作后的图形,任选其中一个单选按钮,则图形面板中将显示该操作后的图形。

import java.awt.*;

import java.awt.event.*;

import java.awt.geom.*;

import java.util.*;

import javax.swing.*;

public class java3

{

public static void main(String[]args)

{

JFrame. frame=new TransformTestFrame;

frame.setDefaultCloseOperation(JFrame.EXIT_

0N_CLoSE);

frame.show; 

}

}

class TransformTest extends JFrame

public TransformTestFrame

{

setTitle("java3");

setSize(WIDTH,HEIGHT);

Container contentPane=getContentPane;

canvas=new TransformPanel;

contentPane.add(canvas,BorderLayout.CEN-

TER);

JPanel buttonPanel=new JPanel:

ButtonGroup group=new ButtonGroup;

JRadioButton rotateButton

=new JRadioButton("旋转",true);

buttonPanel.add(rotateButton);

group.add(rotateButton);

rotateButton.addActionListener(new

ActionListener

{

public void actionPerformed(ActionEvent event)

{

canvas.setRotate;

}

});

JRadioButton trans|ateButton

=new JRadioButton("移位",false);

buttonPanel.add(translateButton);

group.add(translateButton);

translateButton.addActionListener(new

ActionLiatener

public void actionPerformed(ActionEvent event)

{

canvas.setTranslate;

}

});

JRadioButton scaleButton

=new JRadioButton("放大",false);

buttonPanel.add(scaleButton):

group.add(scaleButton);

scaleButton.addActionListener(new

ActionListener

public void actionPerformed(ActionEvent event)

{

canvas.setScale;

}

});

JRadioButton shearButton

=new JRadioButton("剪切",false);

buttonPanel.add(shearButton):

group.add(shearButton);

shearButton.addActionListener(new

ActionListener

{

public void actionPerformed(ActionEvent event)

{

canvas.setShear;

}

});

contentPane.add(buttonPanel,BorderLayout.

NORTH):

}

private TransformPanel canvas;

private static final int WIDTH=300;

private static final int HEIGHT=300;

}

class TransformPanel extend JPanel

{

public TransformPanel

{

square=new Rectangle2D.Double(-50,-50,

100,100);

t = new AffineTransform;

setRotate;

}

public void paintComponent

{

super.paintComponent(g);

Graphics2D g2=(Graphies2D)g;

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

g2.setPaint(Color.gray);

g2.draw(square);

g2.transform(t); 

g2.setPaint(Color.black);

g2.draw(square);

}

public void setRotate

{

t.setToRotation(Math.toRadians(30));

repaint;

public void setTranslate

{

t.setToTranslation(20,1 5);

repaint;

public void setScale

{

t.setToScale(2.0,1.5):

repaint;

}

public void setShear

{

t.setToShear(-0.2,O);

repaint;

}

private Rectangle2D square;

private AffineTransform. t;

}

试题出自试卷《2014年全国计算机等级考试二级JAVA上机模拟试卷(5)》
参考答案
查看试卷详情
相关试题
  1. 下面的程序中,有两个文本框,Input和Output,用户在Input文本框中输入字符串后回车,字符串会在Output文本框中出现。

    import java.awt.*;

    import java.awt.event.*;

    public class java2 extends Frame{

    public static void main(String args[]){

    java2 f=new java2("java2");

    Panel pan=new Panel;

    f.init;

    }

    pubhc java2(String str){

    super(str);

    }

    public void init{

    addWindowListener(new WindowAdapter{

    public void windowClosing(WindowEvent e){

    System.exit(O);

    }

    }};

    setSize(200,200);

    setLayout(new FlowlLayout);

    final TextField tfl=new TextField(20):

    final TextField tf2=new TextField(20);

    final Label hi—new Label("Input:");

    final Label la2一new Label("Output:");

    tfl.addActionListener(       {

    public void actionPerformed(ActionEvent e){

    tf2.setTex(    );

    }

    });

    add(la1);

    add(tfl);

    add(la2);

    add(tf2);

    setVisible(true);

    }

    }

  2. 本题的功能是对图形进行操作,包括旋转、移位、放大和剪切。窗口中有4个单选按钮和一个图形面板,图形面板中有一个矩形和该矩形移位操作后的图形,任选其中一个单选按钮,则图形面板中将显示该操作后的图形。

    import java.awt.*;

    import java.awt.event.*;

    import java.awt.geom.*;

    import java.util.*;

    import javax.swing.*;

    public class java3

    {

    public static void main(String[]args)

    {

    JFrame. frame=new TransformTestFrame;

    frame.setDefaultCloseOperation(JFrame.EXIT_

    0N_CLoSE);

    frame.show; 

    }

    }

    class TransformTest extends JFrame

    public TransformTestFrame

    {

    setTitle("java3");

    setSize(WIDTH,HEIGHT);

    Container contentPane=getContentPane;

    canvas=new TransformPanel;

    contentPane.add(canvas,BorderLayout.CEN-

    TER);

    JPanel buttonPanel=new JPanel:

    ButtonGroup group=new ButtonGroup;

    JRadioButton rotateButton

    =new JRadioButton("旋转",true);

    buttonPanel.add(rotateButton);

    group.add(rotateButton);

    rotateButton.addActionListener(new

    ActionListener

    {

    public void actionPerformed(ActionEvent event)

    {

    canvas.setRotate;

    }

    });

    JRadioButton trans|ateButton

    =new JRadioButton("移位",false);

    buttonPanel.add(translateButton);

    group.add(translateButton);

    translateButton.addActionListener(new

    ActionLiatener

    public void actionPerformed(ActionEvent event)

    {

    canvas.setTranslate;

    }

    });

    JRadioButton scaleButton

    =new JRadioButton("放大",false);

    buttonPanel.add(scaleButton):

    group.add(scaleButton);

    scaleButton.addActionListener(new

    ActionListener

    public void actionPerformed(ActionEvent event)

    {

    canvas.setScale;

    }

    });

    JRadioButton shearButton

    =new JRadioButton("剪切",false);

    buttonPanel.add(shearButton):

    group.add(shearButton);

    shearButton.addActionListener(new

    ActionListener

    {

    public void actionPerformed(ActionEvent event)

    {

    canvas.setShear;

    }

    });

    contentPane.add(buttonPanel,BorderLayout.

    NORTH):

    }

    private TransformPanel canvas;

    private static final int WIDTH=300;

    private static final int HEIGHT=300;

    }

    class TransformPanel extend JPanel

    {

    public TransformPanel

    {

    square=new Rectangle2D.Double(-50,-50,

    100,100);

    t = new AffineTransform;

    setRotate;

    }

    public void paintComponent

    {

    super.paintComponent(g);

    Graphics2D g2=(Graphies2D)g;

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

    g2.setPaint(Color.gray);

    g2.draw(square);

    g2.transform(t); 

    g2.setPaint(Color.black);

    g2.draw(square);

    }

    public void setRotate

    {

    t.setToRotation(Math.toRadians(30));

    repaint;

    public void setTranslate

    {

    t.setToTranslation(20,1 5);

    repaint;

    public void setScale

    {

    t.setToScale(2.0,1.5):

    repaint;

    }

    public void setShear

    {

    t.setToShear(-0.2,O);

    repaint;

    }

    private Rectangle2D square;

    private AffineTransform. t;

    }

  3. 本题的功能是计算二维数组各个元素的和。程序中定义了二维数组arr,arr有3行4列共l2个元素,程序中采用for循环语句的嵌套来计算数组中各个元素的和,并将结果保存在sum变量中,最后打印输出结果。

    public class javal{

    public static void main(String[] args){

    int arr[][]={{l,2,3,4},{5,6,7,8},{9,10,11,12}};

    int sum=0;

    int i=0,j=0;

    for(i=0;       )

    for(       )

           

    System.OUt.println("sum="+sum);

    }

    }

  4. 在程序的下画线处应填入的选项是(  )。

    public class Test        {:

    public static void main(String args[]){

    Test t=new Test;

    Thread tt=new Thread(t);

    tt.start;

    }

    public void run{

    for(int i=0;i<5;i++){

    System.out.println("i="+i);

    }

    }

    • A.implements Runnable
    • B.extends Thread
    • C.implements Thread
    • D.extends Runnable
  5. 执行下面程序段后,2值为(  )。

    int x=1,y=2,z=3;

    z=z/(float)(x/y):

    • A.编译无法通过 
    • B.6
    • C.3
    • D.2
  6. 当一个Applet被加载,后续对Applet生命周期方法的调用中,可能存在的次序是(  )。

    • A.start,stop,destroy
    • B.init,start,stop,start,stop,destroy
    • C.start,init,stop,destroy
    • D.init,start,destroy
  7. 用鼠标点击菜单项(Menultem)产生的事件是(  )。

    • 正确
    • 错误
  8. 用鼠标单击菜单项(Menultem)产生的事件是(  )。

    • A.MenuEvent 
    • B.ActionEvent
    • C.KeyEvent
    • D.MouseEvent
  9. 下列叙述中正确的是(  )。

    • A.一个算法的空间复杂度大,则其时间复杂度必定大
    • B.一个算法的空间复杂度大,则其时间复杂度必定小
    • C.一个算法的时间复杂度大,则其空间复杂度必定小
    • D.上述3种说法都不对
  10. 有三个关系R,S和T如下:

    其中关系T由关系R和S通过某种操作得到,该操作为(  )。

    • A.选择 
    • B.投影
    • C.交 
    • D.并