Fillrect颜色怎么设置(Java编写一个Applent程序,使用fillRect方法输出不同的颜色)

2024-01-12 22:50:03 :84

fillrect颜色怎么设置(Java编写一个Applent程序,使用fillRect方法输出不同的颜色)

大家好,如果您还对fillrect颜色怎么设置不太了解,没有关系,今天就由本站为大家分享fillrect颜色怎么设置的知识,包括Java编写一个Applent程序,使用fillRect方法输出不同的颜色的问题都会给大家分析到,还望可以解决大家的问题,下面我们就开始吧!

本文目录

Java编写一个Applent程序,使用fillRect方法输出不同的颜色

你刚才那题不用关闭的. 追问就可以了.我是刚才那个回答的. import java.applet.Applet;import java.awt.Button;import java.awt.Color;import java.awt.Graphics;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.Random;public class ColorApplet extends Applet { Button bt1; Color color = new Color(0,0,0); Random ran = new Random(); public void init() { bt1 = new Button("随机改变颜色"); bt1.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e) { if(e.getSource()==bt1){ color = new Color((int)(ran.nextFloat()*255),(int)(ran.nextFloat()*255),(int)(ran.nextFloat()*255)); repaint(); } } } ); add(bt1); } public void paint(Graphics g){ g.setColor(color); g.fillRect(60, 50, 50, 50); }}

如何设置pagecontrol上标签的颜色

试试这样吧procedure TForm1.PageControl1DrawTab(Control: TCustomTabControl; TabIndex: Integer; const Rect: TRect; Active: Boolean);var TmpRect: TRect;begin with PageControl1.Canvas do begin Brush.Color := clBlack; Font.Color := clWhite; FillRect(Rect); TmpRect := Rect; OffsetRect(TmpRect, 0, 3); DrawText(Handle, PChar(PageControl1.Pages.Caption), -1, TmpRect, DT_CENTER or DT_VCENTER); end;end;

MFC 如何指定一个矩形并填充颜色

    CRect rt(200,200,500,600);    pDC-》FillSolidRect(&rt,RGB(255,0,0));//红色填充

C语言图形编程怎么把图形填充成喜欢的颜色

不清楚........... HDC dc = GetDC(g_hWnd); HBRUSH brush=CreateSolidBrush(RGB(0, 255, 0)); HBRUSH oldbrush=(HBRUSH)SelectObject(dc, brush); RECT rect; rect.left = 10; rect.right = 50; rect.top = 10; rect.bottom = 50; FillRect(dc,▭ , brush); Ellipse(dc, 60, 60, 100, 100); SelectObject(dc, oldbrush); Ellipse(dc, 120, 120, 150, 150);

java设定背景颜色

本来是在drawcomponent这个里边使用setBackground,你想啊drawcomponent是继承JComponent的所以它是一个容器,所以它同样有setBackground这个方法来设置它的背景颜色

但是因为你在设置它本身为一个画布,因为你用了paintComponent(Graphics g)

这个方法,所以setBackground这个方法即使你用了也看不到很大的效果。但是有一种取代的方法就是在paintComponent(Graphics g)方法中首先就用Graphics 所含有的方法g.setColor(Color.black);来设置背景颜色再用g.fillRect(0, 0, this.getWidth(), this.getHeight());来填满整个容器,这就达到了设置背景目的。然后你再g.setColor(其他颜色);来绘制其它图形.

具体代码:(在你以上的代码上修改了点)

public void paintComponent(Graphics g)

{

Graphics2D g2=(Graphics2D)g;

g.setColor(Color.black);//这里设置背景颜色

g.fillRect(0, 0, this.getWidth(), this.getHeight());//这里填充背景颜色

double x=100;

double y=100;

double w=200;

double h=150;

Rectangle2D rect=new Rectangle2D.Double(x,y,w,h);

g2.setPaint(Color.white);//这里是你设置其他笔触颜色

g2.draw(rect);

Ellipse2D ellipse=new Ellipse2D.Double();

ellipse.setFrame(rect);

g2.draw(ellipse);

Point2D p1=new Point2D.Double(x-40,y-30);

Point2D p2=new Point2D.Double(x+w+40,y+h+30);

g2.draw(new Line2D.Double(p1,p2));

double centerx=rect.getCenterX();

double centery=rect.getCenterY();

double radius=150;

Ellipse2D circle=new Ellipse2D.Double();

circle.setFrameFromCenter(centerx,centery,centerx+125,centery+125);

g2.draw(circle);

}

测试结果图

请问VC++的MFC中怎样实现图形的颜色填充啊

CClientDC dc(this);//申明一个CDC对象CBrush m_brush;//申明一个格式刷对象m_brush.CreateSolidBrush(RGB(255,0,0));//设置颜色dc.FillRect(CRect(10,10,30,30),&m_brush);

Delphi中checklistbox怎样设置每行字体背景颜色

每行背景设置不同颜色checklistbox;listbox;//-------------------------------------------------procedureTForm1.CheckListBox1DrawItem(Control:TWinControl;Index:Integer;Rect:TRect;State:TOwnerDrawState);beginwithCheckListBox1dobegincase(IndexMod5)of//设置画布的刷子填充色0:Canvas.Brush.Color:=clRed;1:Canvas.Brush.Color:=clBlue;2:Canvas.Brush.Color:=clWhite;3:Canvas.Brush.Color:=clYellow;4:Canvas.Brush.Color:=clSkyBlue;end;Canvas.FillRect(Rect); //将当前项填充背景色Canvas.TextOut(Rect.Left,Rect.Top,Items);//重画Items的Textend;end;//----------------------------------------------------------每行字体设置不同颜色checklistbox;listbox;//----------------------------------------------------------

如果你还想了解更多这方面的信息,记得收藏关注本站。

fillrect颜色怎么设置(Java编写一个Applent程序,使用fillRect方法输出不同的颜色)

本文编辑:admin
Copyright © 2022 All Rights Reserved 威海上格软件有限公司 版权所有

鲁ICP备20007704号

Thanks for visiting my site.