整专业资料
微信QQ群
考生网QQ群

群号:517231281

扫码加群
点击二维码加群

考生网微信公众号

微信号:zikaosw

课程试听
最新资讯

手机端访问

1、直接输入www.zikaosw.cn
2、扫描左侧二维码

登录 | 注册
登录/注册后,可享受
  • 课程免费试听
  • 试做在线题库
  • 学习提升指导
  • [主观题] 【程序分析题】阅读下列程序,请回答以下问题:
    (1)该程序中的类 MyPanel 的成员变量 twoClick 的作用是什么,该成员变量的值是如何改变的?
    (2)程序运行时,用户在界面的不同位置,用鼠标点击两次,界面中会出现什么? import java.awt.*;import javax.swing.*;import java.awt.event.*; class MyPanel extends JPanel implements MouseListener{ int leftx,lefty,rightx,righty;
    boolean twoClick;
    MyPanel() { twoClick=false;addMouseListener(this);
    }
    public void mousePressed(MouseEvent e){ if(!twoClick){ leftx=e.getX();lefty=e.getY();
    }else{ rightx=e.getX();righty=e.getY();repaint();
    }
    twoClick=!twoClick:
    }
    public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseReleased(MouseEvent e){} public void paintComponent(Graphics g){
    g.clearRect(0,0,this.getWidth(),this.getHeight());
    g.fillRect(1efix,lefty,Math.abs(rightx-leftx),
    Math.abs(righty-lefty)); }
    }
    class MyWin extends JFrame{
    MyPanel p=new MyPanel();
    MyWin(){ getContentPane().add(p);
    setSize(400,400);setLocation(100,100);setVisible(true);
    }
    }
    public class Test35 extends JFrame{ public static void main(String[]args){new MyWin();}
    }

     纠错    

  • 助考班推荐

您可能感兴趣的试题

Copyright © 2010 - 2023 湖南求实创新教育科技有限公司 All Right Reserved.

温馨提示:如您需要的资料本网暂时没有,请于工作日08:00-18:00,点击这里,联系客服及时补充资料。