import?java.awt.BorderLayout;

創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供東昌府網(wǎng)站建設、東昌府做網(wǎng)站、東昌府網(wǎng)站設計、東昌府網(wǎng)站制作等企業(yè)網(wǎng)站建設、網(wǎng)頁設計與制作、東昌府企業(yè)網(wǎng)站模板建站服務,十余年東昌府做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡服務。
import?java.awt.FlowLayout;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?java.awt.Color;
import?javax.swing.JButton;
import?javax.swing.JFrame;
import?javax.swing.JLabel;
import?javax.swing.JPanel;
import?javax.swing.JTextField;
public?class?RGB?extends?JFrame?implements?ActionListener{
JTextField?t1,t2,t3;
JLabel?b1,b2,b3;
JButton?jb;
JPanel?jp;
public?RGB(){
??super("RGB");
??jp=new?JPanel();
??b1=new?JLabel("R");
??b2=new?JLabel("G");
??b3=new?JLabel("B");
??t1=new?JTextField(3);
??t2=new?JTextField(3);
??t3=new?JTextField(3);
??jb=new?JButton("確定");
??jb.addActionListener(this);
??jp.add(b1);
??jp.add(t1);
??jp.add(b2);
??jp.add(t2);
??jp.add(b3);
??jp.add(t3);
??jp.add(jb);
??jp.setLayout(new?FlowLayout());
??
??add(jp,BorderLayout.CENTER);
??setSize(200,200);
??
??setResizable(false);
??setDefaultCloseOperation(this.DISPOSE_ON_CLOSE);
??setVisible(true);
}
public?void?actionPerformed(ActionEvent?e){
?? if(e.getSource().getClass().getSimpleName().equals("JButton")){
?? int?r=Integer.parseInt(t1.getText());
?? int?g=Integer.parseInt(t2.getText());
?? int?b=Integer.parseInt(t3.getText());
?? if(r=0??r=255??g=0??g=255??b=0??b=255){
?? Color?c=new?Color(r,g,b);
?? jp.setBackground(c);
?? }else{
?? System.out.println("請輸入(0-255)的整數(shù)!");
?? }
?? }
}
public?static?void?main(String[]?args)?{
new?RGB();
}
}
import java.awt.*;
import java.awt.event.*;
public class adjustcolor implements AdjustmentListener, WindowListener {
Frame f=new Frame("調(diào)整顏色");
Label l1=new Label("調(diào)整滾動條,會改變初始顏色",Label.CENTER);
Label l2=new Label("此處顯示顏色值",Label.CENTER);
Label l3=new Label("紅",Label.CENTER);
Label l4=new Label("綠",Label.CENTER);
Label l5=new Label("藍",Label.CENTER);
Scrollbar scr1=new Scrollbar(Scrollbar.HORIZONTAL,0,10,0,265);
Scrollbar scr2=new Scrollbar(Scrollbar.HORIZONTAL,0,10,0,265);
Scrollbar scr3=new Scrollbar(Scrollbar.HORIZONTAL,0,10,0,265);
public adjustcolor(){
f.add(l1);
f.add(l2);
f.add(l3);
f.add(l4);
f.add(l5);
f.add(scr1);
f.add(scr2);
f.add(scr3);
f.setSize(400,350);
f.setVisible(true);
f.addWindowListener(this);
f.setResizable(false);
l1.setBackground(Color.GREEN);
scr1.setBounds(35,225,360,25);
scr2.setBounds(35,255,360,25);
scr3.setBounds(35,285,360,25);
l1.setBounds(0,0,400,200);
l2.setBounds(0,310,400,30);
l3.setBounds(0,225,30,30);
l4.setBounds(0,255,30,30);
l5.setBounds(0,285,30,30);
scr1.addAdjustmentListener(this);
scr2.addAdjustmentListener(this);
scr3.addAdjustmentListener(this);
l1.setBackground(Color.GREEN);
scr1.setBackground(Color.RED);
scr2.setBackground(Color.GREEN);
scr3.setBackground(Color.blue);
}
public void adjustmentValueChanged(AdjustmentEvent e){
int a=scr1.getValue();
int b=scr2.getValue();
int c=scr3.getValue();
l1.setBackground(new Color(a,b,c)) ;
l2.setText("紅"+" "+"綠"+" "+"藍"+" "+a+" "+b+" "+c);
l1.setText(null);
}
public static void main(String[] args){
new adjustcolor();
}
public void windowActivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowClosed(WindowEvent arg0) {
}
public void windowClosing(WindowEvent arg0) {
System.exit(0);
}
public void windowDeactivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub
}
}
這是源代碼 應該是你想要的
cal.setBackgroud(Color.red)你可以查一下Color的字段.
static Color black
黑色。
static Color BLACK
黑色。
static Color blue
藍色。
static Color BLUE
藍色。
static Color cyan
青色。
static Color CYAN
青色。
static Color DARK_GRAY
深灰色。
static Color darkGray
深灰色。
static Color gray
灰色。
static Color GRAY
灰色。
static Color green
綠色。
static Color GREEN
綠色。
static Color LIGHT_GRAY
淺灰色。
static Color lightGray
淺灰色。
static Color magenta
洋紅色。
static Color MAGENTA
洋紅色。
static Color orange
桔黃色。
static Color ORANGE
桔黃色。
static Color pink
粉紅色。
static Color PINK
粉紅色。
static Color red
紅色。
static Color RED
紅色。
static Color white
白色。
static Color WHITE
白色。
static Color yellow
黃色。
static Color YELLOW
黃色。
int rgbR;
int rgbG;
int rgbB;
int minx = 0;
int miny = 0;
try {
File file = new File("E:\\dd.png");
BufferedImage image = ImageIO.read(file);
int width = image.getWidth();//圖片寬度
int height = image.getHeight();//圖片高度
for (int i = minx; i width; i++) {
for (int j = miny; j height; j++) {
int pixel = image.getRGB(i, j); // 下面三行代碼將一個數(shù)字轉(zhuǎn)換為RGB數(shù)字
rgbR = (pixel 0xff0000) 16;
rgbG = (pixel 0xff00) 8;
rgbB = (pixel 0xff);
System.out.println("i=" + i + ",j=" + j + ":(" + rgbR + "," + rgbG + "," + rgbB + ")");
}
}
System.out.println("圖片寬度為:"+width+",高度為:"+height);
} catch (IOException e) {
System.out.println("讀取文件出錯");
e.printStackTrace();
}
構(gòu)造方法有:
Color(int rgb):用指定的組合 RGB 值創(chuàng)建一種不透明的 sRGB 顏色,此 sRGB 值的 16-23 位表示紅色分量,8-15 位表示綠色分量,0-7 位表示藍色分量。
Color(int r, int g, int b)
用指定的紅色、綠色和藍色值創(chuàng)建一種不透明的 sRGB 顏色,這三個顏色值都在 0-255 的范圍內(nèi)。
Color(int r, int g, int b, int a)
用指定的紅色、綠色、藍色和 alpha 值創(chuàng)建一種 sRGB 顏色,這些值都在 0-255 的范圍內(nèi)。
Color(float r, float g, float b, float a)
用指定的紅色、綠色、藍色和 alpha 值創(chuàng)建一種 sRGB 顏色,這些值都在 0.0 - 1.0 的范圍內(nèi)。
Color(float r, float g, float b)
用指定的紅色、綠色和藍色值創(chuàng)建一種不透明的 sRGB 顏色,這三個顏色值都在 0.0 - 1.0 的范圍內(nèi)。
                當前名稱:javargb顏色代碼 java顏色代碼對照表
                
                當前路徑:http://chinadenli.net/article24/hihdje.html
            
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供響應式網(wǎng)站、網(wǎng)站排名、電子商務、域名注冊、網(wǎng)站策劃、網(wǎng)站內(nèi)鏈
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
