当前位置:  技术问答>java相关

500分大放送!

    来源: 互联网  发布时间:2015-10-12

    本文导语:  import java.awt.*; import java.applet.*; import java.util.*; class MyButton extends Canvas {     AutoEvent parent;     Color color;     String label;     MyButton(AutoEvent parent,Color color,String label) { this.label=label; this.parent=parent; this....

import java.awt.*;
import java.applet.*;
import java.util.*;

class MyButton extends Canvas {
    AutoEvent parent;
    Color color;
    String label;
    MyButton(AutoEvent parent,Color color,String label) {
this.label=label;
this.parent=parent;
this.color=color;
    }
   public void paint(Graphics g) {
g.setColor(color);
int rnd=30;
g.fillRoundRect(0,0,size().width,size().height,rnd,rnd);
FontMetrics fm=g.getFontMetrics();
int width=fm.stringWidth(label);
int height=fm.getHeight();
int ascent=fm.getAscent();
int leading=fm.getLeading();

     int horizMargin = (size().width - width)/2;
     int verMargin = (size().height - height)/2;
     g.setColor(Color.white);
     g.drawString(label, horizMargin, verMargin + ascent + leading);
   }
待续!

|
〉1、size()是怎么来的?
   是继承自Canvas的方法,返回Canvas的大小

〉2、FontMetrics fm=g.getFontMetrics();
〉FontMetrics  是什么类?fm=g.getFontMetrics() 得到了什么属性?
    字体资源,用来获取字体的信息,计算字符的长宽等。

〉3、g.fillRoundRect(0,0,size().width,size().height,rnd,rnd);
〉这个方法是干什么用的,第一个到第六个变量的作用是什么?
     画一个园角矩形,参数分别为(左上角X,左上角Y , 宽度, 高度,园角水平半径, 园角垂直半径)

〉4、b1 = new MyButton(this, Color.blue, "test1")中的this起什么作用?
〉它代表的是什么?
      指的是当前的类的实例,就是AutoEvent类的实例

  
〉5、顺便把这句解释一下!
〉add(new Label(event[i], Label.CENTER));
    把新建一个Label加到当前控件上。Label的文字是居中对齐的。  
  
〉6、Canvas、Dialog、Frame类是作什么的。
   Canvas是一个画板,可以用于绘制图形。
   Dialog是对话框。
   Frame是窗体,可以最大化,最小化的那个。


〉谢谢,哪位大侠让小弟明白了,500分立刻奉送!
完了!

|
>1、size()是怎么来的?
size()是Component的方法,从1.1开始废除

>2、FontMetrics fm=g.getFontMetrics();
>FontMetrics  是什么类?fm=g.getFontMetrics() 得到了什么属性?
java.awt.FontMetrics封装了和字体相关的一些信息,在屏幕上绘制的时候会用到这些信息。详细的可以参考java doc。

>3、g.fillRoundRect(0,0,size().width,size().height,rnd,rnd);
>这个方法是干什么用的,第一个到第六个变量的作用是什么?

fillRoundRect
public abstract void fillRoundRect(int x,
                                   int y,
                                   int width,
                                   int height,
                                   int arcWidth,
                                   int arcHeight)
Fills the specified rounded corner rectangle with the current color. The left and right edges of the rectangle are at x and x + width - 1, respectively. The top and bottom edges of the rectangle are at y and y + height - 1. 

Parameters:
x - the x coordinate of the rectangle to be filled.
y - the y coordinate of the rectangle to be filled.
width - the width of the rectangle to be filled.
height - the height of the rectangle to be filled.
arcWidth - the horizontal diameter of the arc at the four corners.
arcHeight - the vertical diameter of the arc at the four corners.

>4、b1 = new MyButton(this, Color.blue, "test1")中的this起什么作用?
>它代表的是什么?
this是AutoEvent类的一个实例,也就是这个applet。


>5、顺便把这句解释一下!
>add(new Label(event[i], Label.CENTER));
这些就是你看到的applet上左边的东西,除了最后一个蓝色的button。


>6、Canvas、Dialog、Frame类是作什么的。
Canvas就是一个画布,你可以在上面画任何东西。它也是一个容器,你可以把像lable,button这样的component放在里面。Dialog一般用于从用户那里得到一些输入信息或者告诉用户一些信息。Dialog可以使modal(模态),此时只有dialog是激活的;Dialog也可以是modeless(非模态),此时可以切换到其他的窗口。Frame一般用作程序的主窗口。


    
 
 

您可能感兴趣的文章:

 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • 动画[火影忍者]第571话[柱间细胞]预告及播放地址(2月20日周四晚放送)
  • ****200分大放送!(肯定给)解决applet与二进制数组问题****
  • 千分放送!请有AIX下dbx调试Oracle proc程序经验的高手解决问题
  • 请尽快结贴结贴吧!100分放送!
  • 大放送,来者有分!!
  • ~!·#¥%过节了,都说说怎么过的?(200分放送)……—*()
  • CSS顶级技巧大放送,div+css布局必知
  • 100分周末大放送——Java面试一般会出什么样的题目,请高人指点!
  • 喜得千金,今日好分大放送!
  • JSP的奇怪问题?100分放送!!!!!!!!!!!!!!!!!!
  • UNIX下有关通信的系统函数的调用,如何快速入门??跳楼大放送——————100分!!!


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3