好文档 - 专业文书写作范文服务资料分享网站

《面向对象程序设计(Java)》机试题库(含答案)

天下 分享 时间: 加入收藏 我要投稿 点赞

}

}

else if(mouseFlag= =2)

{ g.clearRect(0,0,getWidth(),getHeight()); }

public void init() { } }

8. import java.applet.*; import java.awt.*; import java.awt.event.*;

public class MouseDrawRect extends Applet implements MouseMotionListener {

int xstart=-1,ystart=-1; int xend,yend;

TextField showPosition; public void init()

服装制版视频淘宝才智在线

addMouseListener(new MouseAdapter() { });

public void mouseClicked(MouseEvent e) { if(e.getClickCount() ==1) mouseFlag = 1;

else if (e.getClickCount() ==2) mouseFlag = 2; xPos = e.getX() yPos = e.getY(); repaint(); }

{ showPosition = new TextField(20); add(showPosition);

addMouseMotionListener(this); addMouseListener(new MouseAdapter() {

public void mousePressed(MouseEvent event)

{ xstart = event.getX(); ystart = event.getY(); } } ); }

public void paint(Graphics g) { if(xstart!=-1 && ystart!=-1)

{ g.drawRect(xstart,ystart,xend-xstart,yend-ystart); showPosition.setText(\ } }

public void mouseDragged(MouseEvent e) { xend = e.getX(); yend = e.getY(); repaint(); }

public void mouseMoved(MouseEvent e){} } 9.

import javax.swing.*; import java.awt.*;

class SpeakPhone extends JFrame

服装制版视频淘宝才智在线

{

JPanel p1 = new JPanel();

p1.setLayout(new GridLayout(2,1)); Label lab =new Label(\ lab.setFont(f1); p1.add(lab); p1.add(speak);

JPanel p2 = new JPanel();

p2.setLayout(new GridLayout(3,4)); for(int i=0;i<12;i++) { }

JPanel p3 = new JPanel();

p3.setLayout(new GridLayout(1,2));

numbers[i]=new JButton(numberString[i]); numbers[i].setFont(f1); p2.add(numbers[i]);

JTextArea speak;

JButton numbers[] = new JButton[12];

String numberString[] = {\JButton enter,cancel;

Font f1 = new Font(\

SpeakPhone(){

setSize(200,400);

Container con = getContentPane(); speak = new JTextArea(4,6);

服装制版视频淘宝才智在线

}

enter = new JButton(\确定\cancel = new JButton(\取消\

}

p3.add(enter); p3.add(cancel);

con.add(p1,BorderLayout.NORTH); con.add(p2,BorderLayout.CENTER); con.add(p3,BorderLayout.SOUTH);

setVisible(true);

public static void main(String args[]) { }

SpeakPhone mainFrm = new SpeakPhone();

10. import java.awt.*; class MyPanel1 extends Panel {

Checkbox box1,box2,box3; CheckboxGroup sex; MyPanel1(){

sex = new CheckboxGroup(); box1 = new Checkbox(\男\ box2 = new Checkbox(\女\ setLayout(new GridLayout(3,1));

服装制版视频淘宝才智在线

}

add(new Label(\性别\ add(box1); add(box2); }

class MyPanel2 extends Panel { }

class MyPanel3 extends Panel {

Checkbox box1,box2,box3; MyPanel3(){

box1 = new Checkbox(\读书\ box2 = new Checkbox(\电脑\ box3 = new Checkbox(\电影\ setLayout(new GridLayout(4,1)); add(new Label(\爱好\ add(box1); add(box2); add(box3); List list; MyPanel2(){

list = new List(4,false); list.add(\学生\ list.add(\教师\ list.add(\高工\

setLayout(new GridLayout(4,1)); add(new Label(\职业\ add(list); }

服装制版视频淘宝才智在线

《面向对象程序设计(Java)》机试题库(含答案)

}}elseif(mouseFlag==2){g.clearRect(0,0,getWidth(),getHeight());}publicvoidinit(){
推荐度:
点击下载文档文档为doc格式
0nscb5qgp64qfr01784a35m4y31ezc0153b
领取福利

微信扫码领取福利

微信扫码分享