- 讲师:刘萍萍 / 谢楠
- 课时:160h
- 价格 4580 元
特色双名师解密新课程高频考点,送国家电网教材讲义,助力一次通关
配套通关班送国网在线题库一套
本题的功能是对图形进行操作,包括旋转、移位、放大和剪切。窗口中有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; }
请完成下列Java程序:将整型数组中的所有奇数移到所有偶数之前,并打印结果。要求初始化一个大小为10的数组,里面按照数组下标顺序存放0~9,输出交换位置后的数组。
注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。
程序运行结果如下:
9173546280
public class ex20_2 {
private int[] a=new int[10];
public static void main(String[] args)
ex20_2 obj20_2=new ex20_2 );
obj20_2. method ();
}
public void init () {
for(int i=0;i<a.length;i++) {
a[i] =i;
}
}
public void method() {
int c,i,j;
i=0;
j=a.length-1;
init();
while(i<j){
while((a[i]%2==1)&&i<j)
i++;
while((a[j]%2==0)&&i<j)
j--
if(i<j){
c=a [i];
______________;
a[j]=c;
_______________;
}
}
for(i=0;i<a.length;i++){
System.out.print(Integer.toString(a[i]));
}
}
}
下列Application程序中,指定v为32位整数类型,求出v的绝对值并输出,请将程序补充完整。
class test19_1 {
public static void main(String args[]) {
______v=-100;
char ch=______Math.______(v);
System.out.println("ch="+ch);
}
}
A.36
B.36.5
C.37
D.true
课程专业名称 |
讲师 |
课时 |
查看课程 |
---|
课程专业名称 |
讲师 |
课时 |
查看课程 |
---|
点击加载更多评论>>