如何在java中更改抽绳颜色? [英] How do I change drawstring color in java ?

查看:83
本文介绍了如何在java中更改抽绳颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不更改矩形颜色的情况下更改文字颜色?



  private   static   class  RectDraw  extends  JPanel 
{
protected void paintComponent(Graphics g){
super .paintComponent(g);
g.drawRect( 20 5 330 25 );
g.setColor(Color.GRAY);
g.fillRect( 20 5 330 25 );
g.drawString( movie Sceen 50 10 );
}





我的尝试:



我画了一个灰色的矩形。现在我想在矩形内添加一个蓝色的电影屏幕文本。我怎样才能做到这一点?谢谢。

解决方案

如评论中所述,第二次调用 setColor 解决了这个问题:

 g.fillRect( 20  5 ,< span class =code-digit> 330 , 25 ); 
g.setColor(Color.BLUE);
g.drawString( movie Sceen 50 10 );



对于那些没有做Java! :)


How can I change the text color without changing the rectangle color ?

private static class RectDraw extends JPanel
	{
		protected void paintComponent(Graphics g) {
	        super.paintComponent(g);  
	         g.drawRect(20,5,330,25);  
	         g.setColor(Color.GRAY);  
	         g.fillRect(20,5,330,25); 
	         g.drawString("movie Sceen", 50, 10);
	        }



What I have tried:

I have drawn a rectangle with gray color. Now I would like to add a "movie screen" text which is blue color inside the rectangle. How can I achieve this ? Thanks.

解决方案

As mentioned in the comments, a second call to setColor solves the issue:

g.fillRect(20,5,330,25);
g.setColor(Color.BLUE);
g.drawString("movie Sceen", 50, 10);


Not a bad guess for someone who doesn't "do" Java! :)


这篇关于如何在java中更改抽绳颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆