求助,为什么覆写的paintComponent没调用?

EaVanCN 2014-05-20 03:46:45
public class LiveTest extends JFrame implements ActionListener{

JButton jb = new JButton("TEST");

public LiveTest(){

this.setTitle("测试程序");
this.setSize(346, 458);
this.setLayout(new FlowLayout(FlowLayout.LEFT));
this.add(jb);
jb.addActionListener(this);
this.setLocation(200,120);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}
public void paintComponent(Graphics g) {
super.paintComponents(g);
g.setColor(new Color(0, 255, 255));
g.fillRect(230, 230, 230, 230);
}


public static void main(String[] args) {
// TODO Auto-generated method stub
new LiveTest();

}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (e.getSource() == jb) {
repaint();
}
}

}
...全文
217 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
EaVanCN 2014-05-20
  • 打赏
  • 举报
回复
引用 4 楼 vnvlyp 的回复:
JFrame没有paintComponent方法,所以你没有override 只有JPanel等轻量级JComponent才有paintComponent
谢谢你
vnvlyp 2014-05-20
  • 打赏
  • 举报
回复
JFrame没有paintComponent方法,所以你没有override 只有JPanel等轻量级JComponent才有paintComponent
EaVanCN 2014-05-20
  • 打赏
  • 举报
回复
引用 2 楼 u012724379 的回复:
repaint();
什么意思?
-江沐风- 2014-05-20
  • 打赏
  • 举报
回复
repaint();
ymm0514 2014-05-20
  • 打赏
  • 举报
回复
描述的不清楚,你应该把你调用的代码给弄出来

62,614

社区成员

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

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