颜色类规定在默认sRGB颜色空间或颜色的任意颜色空间中的颜色确定的颜色。

类的声明

以下是声明java.awt.Color类:

publicclassColorextendsObjectimplementsPaint,Serializable

字段域

以下是java.awt.geom.Arc2D类字段:

static Color black -- The color black.

static Color BLACK -- The color black.

static Color blue -- The color blue.

static Color BLUE -- The color blue.

static Color cyan -- The color cyan.

static Color CYAN -- The color cyan.

static Color DARK_GRAY -- The color dark gray.

static Color darkGray -- The color dark gray.

static Color gray -- The color gray.

static Color GRAY -- The color gray.

static Color green -- The color green.

static Color GREEN -- The color green.

static Color LIGHT_GRAY -- The color light gray.

static Color lightGray -- The color light gray.

static Color magenta -- The color magenta.

static Color MAGENTA -- The color magenta.

static Color orange -- The color orange.

static Color ORANGE -- The color orange.

static Color pink -- The color pink.

static Color PINK -- The color pink.

static Color red -- The color red.

static Color RED -- The color red.

static Color white -- The color white.

static Color WHITE -- The color white.

static Color yellow -- The color yellow.

static Color YELLOW -- The color yellow.

类的构造函数

S.N.

构造函数与说明

1

Color(ColorSpace cspace, float[] components, float alpha)

Creates a color in the specified ColorSpace with the color components specified in the float array and the specified alpha.

2

Color(float r, float g, float b)

Creates an opaque sRGB color with the specified red, green, and blue values in the range (0.0 - 1.0).

3

Color(float r, float g, float b, float a)

Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0.0 - 1.0).

4

Color(int rgb)

Creates an opaque sRGB color with the specified combined RGB value consisting of the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7.

5

Color(int rgba, boolean hasalpha)

Creates an sRGB color with the specified combined RGBA value consisting of the alpha component in bits 24-31, the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7.

6

Color(int r, int g, int b)

Creates an opaque sRGB color with the specified red, green, and blue values in the range (0 - 255).

7

Color(int r, int g, int b, int a)

Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0 - 255).

类方法

S.N.

方法和说明

1

Color brighter()

Creates a new Color that is a brighter version of this Color.

2

PaintContext createContext(ColorModel cm, Rectangle r, Rectangle2D r2d, AffineTransform xform, RenderingHints hints)

Creates and returns a PaintContext used to generate a solid color pattern.

3

Color darker()

Creates a new Color that is a darker version of this Color.

4

static Color decode(String nm)

Converts a String to an integer and returns the specified opaque Color.

5

boolean equals(Object obj)

Determines whether another object is equal to this Color.

6

int getAlpha()

Returns the alpha component in the range 0-255.

7

int getBlue()

Returns the blue component in the range 0-255 in the default sRGB space.

8

static Color getColor(String nm)

Finds a color in the system properties.

9

static Color getColor(String nm, Color v)

Finds a color in the system properties.

10

static Color getColor(String nm, int v)

Finds a color in the system properties.

11

float[] getColorComponents(ColorSpace cspace, float[] compArray)

Returns a float array containing only the color components of the Color in the ColorSpace specified by the cspace parameter.

12

float[] getColorComponents(float[] compArray)

Returns a float array containing only the color components of the Color, in the ColorSpace of the Color.

13

ColorSpace getColorSpace()

Returns the ColorSpace of this Color.

14

float[] getComponents(ColorSpace cspace, float[] compArray)

Returns a float array containing the color and alpha components of the Color, in the ColorSpace specified by the cspace parameter.

15

float[] getComponents(float[] compArray)

Returns a float array containing the color and alpha components of the Color, in the ColorSpace of the Color.

16

int getGreen()

Returns the green component in the range 0-255 in the default sRGB space.

17

static Color getHSBColor(float h, float s, float b)

Creates a Color object based on the specified values for the HSB color model.

18

int getRed()

Returns the red component in the range 0-255 in the default sRGB space.

19

int getRGB()

Returns the RGB value representing the color in the default sRGB ColorModel.

20

float[] getRGBColorComponents(float[] compArray)

Returns a float array containing only the color components of the Color, in the default sRGB color space.

21

float[] getRGBComponents(float[] compArray)

Returns a float array containing the color and alpha components of the Color, as represented in the default sRGB color space.

22

int getTransparency()

Returns the transparency mode for this Color.

23

int hashCode()

Computes the hash code for this Color.

24

static int HSBtoRGB(float hue, float saturation, float brightness)

Converts the components of a color, as specified by the HSB model, to an equivalent set of values for the default RGB model.

25

static float[] RGBtoHSB(int r, int g, int b, float[] hsbvals)

Converts the components of a color, as specified by the default RGB model, to an equivalent set of values for hue, saturation, and brightness that are the three components of the HSB model.

26

String toString()

Returns a string representation of this Color.

继承的方法

这个类继承的方法从以下类:

java.lang.Object

Color 实例

选择使用任何编辑器创建以下java程序D:/ > AWT > com > yiibai > gui >

AWTGraphicsDemo.java

packagecom.yiibai.gui;importjava.awt.*;importjava.awt.event.*;importjava.awt.geom.*;publicclassAWTGraphicsDemoextendsFrame{publicAWTGraphicsDemo(){super("Java AWT Examples");prepareGUI();}publicstaticvoidmain(String[]args){AWTGraphicsDemoawtGraphicsDemo=newAWTGraphicsDemo();awtGraphicsDemo.setVisible(true);}privatevoidprepareGUI(){setSize(400,400);addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEventwindowEvent){System.exit(0);}});}@Overridepublicvoidpaint(Graphicsg){Graphics2Dg2=(Graphics2D)g;FontplainFont=newFont("Serif",Font.PLAIN,24);g2.setFont(plainFont);g2.setColor(Color.red);g2.drawString("Welcome to TutorialsPoint",50,70);g2.setColor(Color.GRAY);g2.drawString("Welcome to TutorialsPoint",50,120);}}

编译程序,使用命令提示符。进入到D:/> AWT,然后键入以下命令。

D:AWT>javac comyiibaiguiAWTGraphicsDemo.java

如果没有错误出现,这意味着编译成功。使用下面的命令来运行程序。

D:AWT>java com.yiibai.gui.AWTGraphicsDemo

验证下面的输出

¥ 我要打赏

纠错/补充

收藏

加QQ群啦,易百教程官方技术学习群

注意:建议每个人选自己的技术方向加群,同一个QQ最多限加 3 个群。

java.awt.color,AWT Color类相关推荐

  1. java异常awt_java.awt.HeadlessException

    Linux下安装eclipse的有关问题 Linux上安装eclipse的问题1.之前在Windows下安装的Myeclipse,写了一个java程序,用到了swing界面2.然后我在ubuntu上安 ...

  2. Java学习记录 AWT绘图篇

    绘制图形 Canvas画布类 Class Canvas java.lang.Object java.awt.Component java.awt.Canvas 用来 绘制图形 或 捕获用户输入的事件. ...

  3. swing java awt_java中AWT和SWing的区别与联系

    AWT和Swing都是java中的包. AWT(Abstract Window Toolkit):抽象窗口工具包,早期编写图形界面应用程序的包. Swing :为解决 AWT 存在的问题而新开发的图形 ...

  4. java基础知识-对象和类

    前言: 因为要准备Java面试,所有将java基础知识点重新复习一遍,主要笔记来源于菜鸟教程和java核心技术的书籍中,也有一些博客上的资料(这些只供我个人学习使用) Java 对象和类 对象:对象是 ...

  5. java图形验证码生成工具类

    转载自   java图形验证码生成工具类 生成验证码效果       ValidateCode.java 验证码生成类 package cn.dsna.util.images; import java ...

  6. 在java程序中定义的类有两种成员_java试题 急需答案 谢谢!!!

    三.填空(每小题2分,共10分)1.在Applet中,创建一个具有10行45列的多行文本区对象ta的语句为:2.创建一个标识有"关闭"字样的标签对象gb的语句为.3.方法是一种仅有 ...

  7. 学以致用——Java源码——使用Graphics2D类draw方法绘制立方体(Drawing Cubes)

    程序功能: 使用Graphics2D类draw方法绘制立方体 运行示例: 源码: 1. 实体类 import java.awt.Graphics2D; import java.awt.Polygon; ...

  8. Java 字体颜色转换工具类 ColorUtil

    import java.awt.Color;  import jxl.format.Colour;       /**  *字体颜色转换工具类  * @author tanghui  *  */ pu ...

  9. java项目常用的工具类

    前言 在开发过程中,我们会遇到很多繁琐或者棘手的问题,但是,这些问题往往会存在一些便捷的工具类,来简化我们的开发,下面是我工作中经常使用到的工具类 常用工具类 日期工具类 import java.te ...

最新文章

  1. 一组图诠释CNN及RNN的区别
  2. 探讨mutex与semaphore
  3. 编辑器之神VIM入门
  4. sql server 生成万年历
  5. idea 线程内存_Java线程池系列之-Java线程池底层源码分析系列(一)
  6. 小波阈值图像去噪的实现步骤
  7. Android之解决ubuntu没有无线网卡和手机wifi实现adb wifi调试
  8. 求出1到某个数的所有素数
  9. Objective-C内存管理教程和原理剖析(三)
  10. 怎么从服务器传输信息,大神们socket如何连接到服务器并判断从服务器传送回来的数据 谢谢谢谢 跪求啊 急用...
  11. 计算机829大纲,829计算机基础考试大纲
  12. mysql导入mdb_mysql导入数据库.mdb
  13. 可以在电脑上在线录制视频GIF的软件,不需要下载安装
  14. [6.837]A3:OpenG应用和Phong着色模型
  15. Word中插入目录时未找到目录项
  16. 你有多久没有看星星了呢?【爬取NASA的科普网站上的所有图片】
  17. 公司HP-EVA4400存储硬盘离线数据恢复方法
  18. 蓝牙室内定位,SOC芯片NRF52832
  19. 【网页版 GitHub】操作指南(搜索、下载等)
  20. Opencv-图像ROI与ROI操作

热门文章

  1. windows系统为硬件保留的内存如何解决?
  2. [宋史学习] 雍熙北伐
  3. 马斯克:特斯拉车载AI将可以预测乘客目的地
  4. ReLuSeLu其他
  5. SLAM综述笔记-A Survey of Simultaneous Localization and Mapping with an Envision in 6G Wireless Networks
  6. Red Hat9.0 下的五笔输入法
  7. 计算机网络专业土味情话,各个大学专业的“土味情话”,撩不到你算我输!
  8. 解决H5在微信浏览器中保存联系人问题
  9. [INS-35075] 指定的 SID 已在使用.
  10. 骑行适合戴什么耳机,几款适合在骑行过程佩戴的耳机推荐