云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > (完整word版)Java知识总结完整版,推荐文档

(完整word版)Java知识总结完整版,推荐文档

  • 62 次阅读
  • 3 次下载
  • 2025/6/4 22:28:09

add(num1);add(lblPlus);add(num2);add(btnEqual);add(num3); pack();

setVisible(true); }

private class MyMonitor implements ActionListener { public void actionPerformed(ActionEvent e) { int n1 = Integer.parseInt(num1.getText()); int n2 = Integer.parseInt(num2.getText()); num3.setText(\ } } }

Graphics类

每个Component都有一个paint(Graphics g)用于实现绘图目的,每次重画该Component时都自动调用paint方法

Graphics类中提供了许多绘图方法,如:

drawRect(int x,int y,int width,int height)

fillRoundRect(int x,int y,int width,int height,int arcWidth,int arcHeight)等

Adapter&repaint import java.awt.*;

import java.awt.event.*; import java.util.*;

public class MyMouseAdapter{

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

class MyFrame extends Frame { ArrayList points = null; MyFrame(String s) { super(s);

points = new ArrayList(); setLayout(null);

setBounds(300,300,400,300);

this.setBackground(new Color(204,204,255)); setVisible(true);

this.addMouseListener(new Monitor()); }

public void paint(Graphics g) { Iterator i = points.iterator(); while(i.hasNext()){

Point p = (Point)i.next(); g.setColor(Color.BLUE); g.fillOval(p.x,p.y,10,10); } }

public void addPoint(Point p){ points.add(p); } }

class Monitor extends MouseAdapter {

public void mousePressed(MouseEvent e) { MyFrame f = (MyFrame)e.getSource();

f.addPoint(new Point(e.getX(),e.getY())); f.repaint(); } }

鼠标事件适配器

抽象类java.awt.event.MouseAdapter实现了MouseListener接口,可以使用其子类作为MouseEvent的监听器,只要重写其相应的方法即可 对于其他的监听器,也有对应的适配器

使用适配器可以避免监听器类定义没有必要的空方法 repaint-update()-paint()

  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

add(num1);add(lblPlus);add(num2);add(btnEqual);add(num3); pack(); setVisible(true); } private class MyMonitor implements ActionListener { public void actionPerformed(ActionEvent e) { int n1 = Integer.parseInt(num1.getText()); int n2 = Integer.parseInt(num2.getText()); num3.setText(\ } } } Graphics类 每个Component都有一个paint(Graphics g)用于实现绘图目的,每次重画该C

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com