java.awt.color,AWT Color类
顏色類規(guī)定在默認(rèn)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.
類的構(gòu)造函數(shù)
S.N.
構(gòu)造函數(shù)與說明
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 實例
選擇使用任何編輯器創(chuàng)建以下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
如果沒有錯誤出現(xiàn),這意味著編譯成功。使用下面的命令來運行程序。
D:AWT>java com.yiibai.gui.AWTGraphicsDemo
驗證下面的輸出
¥ 我要打賞
糾錯/補充
收藏
加QQ群啦,易百教程官方技術(shù)學(xué)習(xí)群
注意:建議每個人選自己的技術(shù)方向加群,同一個QQ最多限加 3 個群。
總結(jié)
以上是生活随笔為你收集整理的java.awt.color,AWT Color类的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 图片轮播代码参考
- 下一篇: 微星x58pro支持服务器内存吗,价廉却