icon

dalookzhu 2010-07-14 01:01:14
请问为什么我没有图标显示,是不是要调用paintIcon()的方法,如果是,怎么调用
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Swing_test extends JFrame{
public Swing_test(){
this.setSize(300,150);
this.setLocation(300,200);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
class MyIcon implements Icon{
private int width;
private int heigth;
public int getIconHeight(){
return this.heigth;
}
public int getIconWidth(){
return this.width;
}
public MyIcon(int width, int height){
this.width = width;
this.heigth = heigth;
}
public void paintIcon(Component arg0, Graphics arg1, int x, int y){
arg1.fillOval(x, y, width, heigth);
}
}
MyIcon a = new MyIcon(15,15);
JLabel label = new JLabel("测试", a, JLabel.CENTER);
label.setVisible(true);
this.add(label);
this.setVisible(true);
}
public static void main(String[] ar){
new Swing_test();
}
}
...全文
139 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
dalookzhu 2010-07-14
  • 打赏
  • 举报
回复
谢谢 ,看到了
dalookzhu 2010-07-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 closewbq 的回复:]
Java code

public MyIcon(int width, int height){
this.width = width;
this.heigth = height;
}

构造函数写错了。
[/Quote]
哪里写错了
closewbq 2010-07-14
  • 打赏
  • 举报
回复

public MyIcon(int width, int height){
this.width = width;
this.heigth = height;
}
构造函数写错了。

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧