展开全部
根据条件变色,在覆写public void paint(Graphics g)里面,设置条件语句选择执行,我这里有个字体闪烁语句是这样的,你看有用不
class StartPanel extends JPanel implements Runnable
{
int count = 0;
public void paint(Graphics g)
{
super.paint(g);
g.fillRect(0,0,800,700);
if(count%2==0)
{
g.setColor(Color.YELLOW);
}
else
{
g.setColor(Color.RED);
}
Font myFont = new Font("Lithos Pro Regular",Font.BOLD,120);
g.setFont(myFont);
g.drawString("WELCOME",125,300);
g.setColor(Color.WHITE);
Font myFont1 = new Font("Stencil Std",Font.BOLD,80);
g.setFont(myFont1);
g.drawString("WELCOME",50,450);
}
@Override
public void run()
{
// TODO Auto-generated method stub
while(true)
{
try
{
Thread.sleep(500);
}
catch (Exception e)
{
// TODO: handle exception
e.printStackTrace();
}
count++;
this.repaint();
}
}
}
class StartPanel extends JPanel implements Runnable
{
int count = 0;
public void paint(Graphics g)
{
super.paint(g);
g.fillRect(0,0,800,700);
if(count%2==0)
{
g.setColor(Color.YELLOW);
}
else
{
g.setColor(Color.RED);
}
Font myFont = new Font("Lithos Pro Regular",Font.BOLD,120);
g.setFont(myFont);
g.drawString("WELCOME",125,300);
g.setColor(Color.WHITE);
Font myFont1 = new Font("Stencil Std",Font.BOLD,80);
g.setFont(myFont1);
g.drawString("WELCOME",50,450);
}
@Override
public void run()
{
// TODO Auto-generated method stub
while(true)
{
try
{
Thread.sleep(500);
}
catch (Exception e)
{
// TODO: handle exception
e.printStackTrace();
}
count++;
this.repaint();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询