这程序怎么了?为什么显示不出来

caowy112 2008-04-03 08:33:31
public class MyButton extends JButton{
MyButton()
{
JFrame e=new JFrame();
e.setSize(200,200);
JButton d=new JButton("fdfd");
e.getContentPane().add(d);
e.setVisible(true);
}
public void paintComponent(Graphics g){
int x1[]={25,40,10,25};
int y1[]={110,140,140,110};
super.paintComponent(g);
g.fillPolygon(x1, y1, 3);
g.drawLine(10, 10, 10, 10);
}
public static void main(String []args)
{
new MyButton();
}

}
...全文
43 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
guofei_gf 2008-04-03
  • 打赏
  • 举报
回复
那是肯定的了,你的paintComponent()是MyButton的,又不是JButton的,你在程序中也没有添加MyButton,自然不会使用paintComponent()了
这样试试吧:
public class MyButton extends JButton{
MyButton(String s)
{
super(s);
}
public void paintComponent(Graphics g){
int x1[]={25,40,10,25};
int y1[]={110,140,140,110};
super.paintComponent(g);
g.fillPolygon(x1, y1, 3);
g.drawLine(10, 10, 10, 10);
}
public static void main(String []args)
{
JFrame e=new JFrame();
e.setSize(200,200);
MyButton d=new MyButton("fdfd");
e.getContentPane().add(d);
e.setVisible(true);
}

}
365810247 2008-04-03
  • 打赏
  • 举报
回复
你把
super.paintComponent(g);
放在
g.drawLine(10, 10, 10, 10);
后面.

62,623

社区成员

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

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