简体   繁体   English

Java Gui(Swing)关于简单Animation的问题

[英]Java Gui(Swing) question about Simple Animation

i have a class that extends JFrame.我有一个扩展 JFrame 的 class。 and i need that some rectangle move on my screen, what the best way to do it?我需要在我的屏幕上移动一些矩形,最好的方法是什么?

  1. According to the docs JComponent#paintComponent , the method firm is protected and not public根据文档JComponent#paintComponent ,方法公司是protected的而不是public

    protected void paintComponent(Graphics g)

    Write @Override on top of that method so that your compiler can show you warnings in case you're writing something wrong.在该方法之上编写@Override ,以便您的编译器可以在您编写错误的情况下向您显示警告。

  2. Never, ever!永远不能! start a Timer inside paintComponent , it will get called several times, just by moving your mouse in the app it will get called and you have no control over it, so you will run into issues due to that.paintComponent中启动一个Timer ,它会被调用多次,只需在应用程序中移动鼠标,它就会被调用,而你无法控制它,因此你会遇到问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM