import java.awt.*; import java.awt.event.*; import java.applet.*; public class RGB extends Applet { boolean isStandalone = false; Scrollbar scrollbar1 = new Scrollbar(); Scrollbar scrollbar2 = new Scrollbar(); Scrollbar scrollbar3 = new Scrollbar(); Label label1 = new Label(); Label label2 = new Label(); Label label3 = new Label(); Label label4 = new Label(); TextField textField1 = new TextField(); int Rv,Gv,Bv,RGBv; Color Clv=new Color(Rv,Gv,Bv); Button button1 = new Button(); Label label5 = new Label(); /**アプレットの初期化*/ public void init() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } label1.setText(Integer.toString(Rv)); textField1.setText(toHex(Rv)+toHex(Gv)+toHex(Bv)); } /**コンポーネントの初期化*/ private void jbInit() throws Exception { this.setLayout(null); scrollbar1.setBackground(Color.red); scrollbar1.setForeground(Color.black); scrollbar1.setMaximum(265); scrollbar1.setOrientation(0); scrollbar1.setValue(128); scrollbar1.setBounds(new Rectangle(72, 47, 135, 15)); scrollbar1.addAdjustmentListener(new java.awt.event.AdjustmentListener() { public void adjustmentValueChanged(AdjustmentEvent e) { scrollbar1_adjustmentValueChanged(e); } }); scrollbar2.setBackground(Color.green); scrollbar2.setForeground(Color.black); scrollbar2.setMaximum(265); scrollbar2.setOrientation(0); scrollbar2.setValue(128); scrollbar2.setBounds(new Rectangle(72, 70, 135, 16)); scrollbar2.addAdjustmentListener(new java.awt.event.AdjustmentListener() { public void adjustmentValueChanged(AdjustmentEvent e) { scrollbar2_adjustmentValueChanged(e); } }); scrollbar3.setBackground(Color.blue); scrollbar3.setForeground(Color.black); scrollbar3.setMaximum(265); scrollbar3.setOrientation(0); scrollbar3.setValue(128); scrollbar3.setBounds(new Rectangle(72, 96, 135, 17)); scrollbar3.addAdjustmentListener(new java.awt.event.AdjustmentListener() { public void adjustmentValueChanged(AdjustmentEvent e) { scrollbar3_adjustmentValueChanged(e); } }); label1.setText("label1"); label1.setBounds(new Rectangle(228, 47, 47, 16)); label2.setText("label2"); label2.setBounds(new Rectangle(228, 71, 47, 16)); label3.setText("label3"); label3.setBounds(new Rectangle(226, 97, 47, 16)); label4.setFont(new java.awt.Font("Dialog", 1, 14)); label4.setText("色のRGB"); label4.setBounds(new Rectangle(108, 11, 61, 23)); textField1.setText("textField1"); textField1.setBounds(new Rectangle(153, 138, 85, 21)); button1.setBounds(new Rectangle(29, 132, 30, 28)); label5.setText("16進数値"); label5.setBounds(new Rectangle(76, 137, 57, 23)); this.add(scrollbar1, null); this.add(label4, null); this.add(scrollbar2, null); this.add(scrollbar3, null); this.add(button1, null); this.add(label1, null); this.add(label2, null); this.add(label3, null); this.add(textField1, null); this.add(label5, null); Rv=Gv=Bv=128; } String toHex(int val){ String ms; ms=Integer.toHexString(val); if (val<16) ms="0"+ms; return ms; } void scrollbar1_adjustmentValueChanged(AdjustmentEvent e) { Rv=scrollbar1.getValue(); Color cv=new Color(Rv,Gv,Bv); label1.setText(Integer.toString(Rv)); textField1.setText(toHex(Rv)+toHex(Gv)+toHex(Bv)); button1.setBackground(cv); } void scrollbar2_adjustmentValueChanged(AdjustmentEvent e) { Gv=scrollbar2.getValue(); Color cv=new Color(Rv,Gv,Bv); label2.setText(Integer.toString(Gv)); textField1.setText(toHex(Rv)+toHex(Gv)+toHex(Bv)); button1.setBackground(cv); } void scrollbar3_adjustmentValueChanged(AdjustmentEvent e) { Bv=scrollbar3.getValue(); Color cv=new Color(Rv,Gv,Bv); label3.setText(Integer.toString(Bv)); textField1.setText(toHex(Rv)+toHex(Gv)+toHex(Bv)); button1.setBackground(cv); } }