public boolean keyDown(Event evt, int key) {
TextField t = (TextField)parent.h.get("keyDown");
t.setText(evt.toString());
return true;
}
public boolean keyUp(Event evt, int key) {
TextField t = (TextField)parent.h.get("keyUp");
t.setText(evt.toString());
return true;
}
public boolean lostFocus(Event evt, Object w) {
TextField t = (TextField)parent.h.get("lostFocus");
t.setText(evt.toString());
return true;
}
public boolean gotFocus(Event evt, Object w) {
TextField t = (TextField)parent.h.get("gotFocus");
t.setText(evt.toString());
return true;
}
public boolean mouseDown(Event evt,int x,int y) {
TextField t = (TextField)parent.h.get("mouseDown");
t.setText(evt.toString());
return true;
}
TextField t = (TextField)parent.h.get("keyDown");
t.setText(evt.toString());
return true;
}
public boolean keyUp(Event evt, int key) {
TextField t = (TextField)parent.h.get("keyUp");
t.setText(evt.toString());
return true;
}
public boolean lostFocus(Event evt, Object w) {
TextField t = (TextField)parent.h.get("lostFocus");
t.setText(evt.toString());
return true;
}
public boolean gotFocus(Event evt, Object w) {
TextField t = (TextField)parent.h.get("gotFocus");
t.setText(evt.toString());
return true;
}
public boolean mouseDown(Event evt,int x,int y) {
TextField t = (TextField)parent.h.get("mouseDown");
t.setText(evt.toString());
return true;
}
解决方案 »
- 关于swt的应用 如果谁搞过一定是高人
- java日期转化
- java常用包包含在哪些jar文件中
- 初学Java的困惑?
- 困扰1个小时的一行语句
- 两个JPanel用同一个布局对象的郁闷 !
- 提示这种错误“Exception in thread "main" java.lang.NoClassDefFoundError: first"
- ———我是个菜菜鸟:Hello World 例子也不过,请问为啥!————
- 关于 File.renameTo。。。。。。。
- htmlconverter为什么只有第一次能转换成功?知道的指点一下。
- finalize()相关问题,请高手指点迷津。
- 高分请教? 大家在JAVA中怎么做拓扑图?
TextField t = (TextField)parent.h.get("mouseDrag");
t.setText(evt.toString());
return true;
}
public boolean mouseEnter(Event evt,int x,int y) {
TextField t = (TextField)parent.h.get("mouseEnter");
t.setText(evt.toString());
return true;
}
public boolean mouseExit(Event evt,int x,int y) {
TextField t = (TextField)parent.h.get("mouseExit");
t.setText(evt.toString());
return true;
}
public boolean mouseMove(Event evt,int x,int y) {
TextField t = (TextField)parent.h.get("mouseMove");
t.setText(evt.toString());
return true;
}
public boolean mouseUp(Event evt,int x,int y) {
TextField t = (TextField)parent.h.get("mouseUp");
t.setText(evt.toString());
return true;
}
}
待续!
Hashtable h = new Hashtable();
String[] event = {
"keyDown", "keyUp", "lostFocus",
"gotFocus", "mouseDown", "mouseUp",
"mouseMove", "mouseDrag", "mouseEnter",
"mouseExit"
};
MyButton
b1 = new MyButton(this, Color.blue, "test1"),
b2 = new MyButton(this, Color.red, "test2");
public void init() {
setLayout(new GridLayout(event.length+1,2));
for(int i = 0; i < event.length; i++) {
TextField t = new TextField();
t.setEditable(false);
add(new Label(event[i], Label.CENTER));
add(t);
h.put(event[i], t);
}
add(b1);
add(b2);
}
}
//<applet code=AutoEvent.class width=300 height=200></applet>
待续!
1、size()是怎么来的?
2、FontMetrics fm=g.getFontMetrics();
FontMetrics 是什么类?fm=g.getFontMetrics() 得到了什么属性?
3、g.fillRoundRect(0,0,size().width,size().height,rnd,rnd);
这个方法是干什么用的,第一个到第六个变量的作用是什么?
4、b1 = new MyButton(this, Color.blue, "test1")中的this起什么作用?
它代表的是什么?
5、顺便把这句解释一下!
add(new Label(event[i], Label.CENTER));
6、Canvas、Dialog、Frame类是作什么的。
谢谢,哪位大侠让小弟明白了,500分立刻奉送!
完了!
是继承自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分立刻奉送!
完了!
替代它的是getSize();
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一般用作程序的主窗口。
Note: AutoEvent.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
这是怎么回事?覆盖了一个API有什么影响吗?
import java.applet.*;public class IKnow extends Applet {
public void paint(Graphics g) {
String label;
Color color;
g.setColor(color);
int rnd=30;
g.fillRoundRect(0,0,getSize().width,getSize().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=(getSize().width-width)/2;
int verMargin=(getSize().height-height)/2;
g.setColor(Color.white);
g.drawString(label,horizMargin,verMargin+ascent+leading);
}
}
//<applet code=IKnow.class width=300 height=200></applet>帮忙看看为什么这段编译不过,说color、label没有初始化,而我上面的就可以呢?
String label="It's a label";
Color color = Color.red;
这位小哥,怎么说也得先把这100分给结了吧?:)