請問如何加image 改他的顏色 |
尚未結案
|
manpaul
一般會員 發表:2 回覆:0 積分:0 註冊:2007-11-24 發送簡訊給我 |
我是想係下面加一張圖片之後 改顏面有冇有方法呀
import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.awt.Graphics; import java.lang.Math; public class Q1 extends JFrame { private JLabel ColorLabel,txt1Label,txt2Label,txt3Label; private JTextField txt1Field,txt2Field,txt3Field; private JButton UseButton; private Panel ColorPanel; public Q1(){ super( "HSB To RGB" ); ActionEventHandler handler = new ActionEventHandler(); Container container = getContentPane(); container.setLayout( new FlowLayout() ); this.setLayout(null); ColorLabel=new JLabel("Base Color :"); container.add( ColorLabel ); ColorLabel.setBounds(160,10,150,50); txt1Label= new JLabel( "Hue°" ); container.add( txt1Label ); txt1Label.setBounds(100,150,80,50); txt1Field = new JTextField( 10 ); container.add( txt1Field ); txt1Field.setBounds(100,140,60,20); txt1Field.addActionListener( handler ); txt2Label= new JLabel( "Saturation%" ); container.add( txt2Label ); txt2Label.setBounds(180,150,80,50); txt2Field = new JTextField( 10 ); container.add( txt2Field ); txt2Field.setBounds(180,140,60,20); txt2Field.addActionListener( handler ); txt3Label= new JLabel( "Brightness%" ); container.add( txt3Label ); txt3Label.setBounds(270,150,80,50); txt3Field = new JTextField( 10 ); container.add( txt3Field ); txt3Field.setBounds(270,140,60,20); txt3Field.addActionListener( handler ); UseButton= new JButton("Use it"); container.add( UseButton ); UseButton.setBounds(190,190,70,20); UseButton.addActionListener( handler ); ColorPanel=new Panel(); ColorPanel.setBackground(Color.black); container.add(ColorPanel); ColorPanel.setBounds(155,60,150,50); } public void paint( Graphics g ){ super.paint( g ); g.drawLine( 80, 150,400, 150 ); } private class ActionEventHandler implements ActionListener { public void actionPerformed( ActionEvent event ){ float a =Float.parseFloat(txt1Field.getText()) /360; float b =Float.parseFloat(txt2Field.getText()) /100; float c =Float.parseFloat(txt3Field.getText()) /100; int rgb = Color.HSBtoRGB(a, b, c); int red = (rgb>>16)&0xFF; int green = (rgb>>8)&0xFF; int blue = rgb&0xFF; Color newcolor = new Color(red,green,blue); ColorLabel.setText("Base color: #" Integer.toHexString(newcolor.getRed()) Integer.toHexString(newcolor.getGreen()) Integer.toHexString(newcolor.getBlue())); ColorPanel.setBackground(newcolor); ColorPanel.repaint(); } } public static void main( String args[] ){ Q1 window = new Q1(); window.setSize( 500, 500 ); window.setVisible( true ); } } 編輯記錄
manpaul 重新編輯於 2007-11-24 12:00:22, 註解 無‧
|
yckuo
高階會員 發表:55 回覆:389 積分:238 註冊:2003-03-07 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |