实现星星闪动的java代码
发布网友
发布时间:2024-10-23 12:56
我来回答
共2个回答
热心网友
时间:2024-10-30 08:28
package panel;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import javax.swing.JPanel;
import main.MainTank;
public class TipPanel extends JPanel implements Runnable{
/**
*
*/
private static final long serialVersionUID = 1L;
//偶数打印,画面板
int time=0;
public void paintComponent(Graphics g){
super.paint(g);
g.fillRect(0, 0, MainTank.getWidthOfGame(), MainTank.getHeightOfGame());//绘制提示窗口
if (time%2==0){//偶数打印,画面板,造成闪烁效果
g.setColor(Color.ORANGE);
Font font=new Font("华文楷体",Font.BOLD,30);
g.setFont(font);//选用字体
g.drawString("Ready", 140, 130);
}
}
@Override
public void run() {
while (true){
try{
Thread.sleep(250);
}catch (Exception e){
e.getMessage();
}
time++;//绘图开关
this.repaint();
}
}
}//TipPanel
类似的,修改下就行
热心网友
时间:2024-10-30 08:28
把问题描述详细点!