This is simple color generator which generate color using combination of red,green,blue. it is made by using awt package.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | import java.awt.BorderLayout; import java.awt.Color; import java.awt.FlowLayout; import java.awt.Font; import java.awt.Frame; import java.awt.GridLayout; import java.awt.Label; import java.awt.Panel; import java.awt.Rectangle; import java.awt.Scrollbar; import java.awt.TextField; import java.awt.Window; import java.awt.event.AdjustmentEvent; import java.awt.event.AdjustmentListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; class ColourGenerate extends WindowAdapter implements AdjustmentListener { private Frame f; private Label l1,l2,l3,l4; private TextField t1,t2,t3; private Scrollbar sb,sb1,sb2; private Panel p1,p2,p3,p4; ColourGenerate() { f=new Frame(); f.setTitle("COLOUR MIXER"); Rectangle r=new Rectangle(); r.width=400; r.height=400; r.x=100; r.y=200; f.setBounds(r); Rectangle r1; r1=f.getBounds(); f.setEnabled(true); Color c1; c1=f.getBackground(); l1=new Label("RED"); l2=new Label("GREEN"); l3=new Label("BLUE"); l4=new Label("R G B"); Font fr; fr=new Font("corrier New",Font.BOLD,20); l1.setFont(fr); l2.setFont(fr); l3.setFont(fr); l4.setFont(fr); sb=new Scrollbar(); sb.setOrientation(Scrollbar.VERTICAL); sb.setValue(0); sb.setVisibleAmount(0); sb.setMinimum(0); sb.setMaximum(255); sb.setUnitIncrement(1); sb.setBlockIncrement(20); sb1=new Scrollbar(Scrollbar.VERTICAL,0,1,0,255); sb2=new Scrollbar(Scrollbar.VERTICAL,0,1,0,255); t1=new TextField("0"); t2=new TextField("0"); t3=new TextField("0"); p4=new Panel(); p2=new Panel(); p3=new Panel(); p1=new Panel(); p4.setLayout(new GridLayout(1,3,10,10)); p4.add(sb); p4.add(sb1); p4.add(sb2); p2.setLayout(new BorderLayout()); p2.add(l4,"North"); p2.add(p4,"Center"); p1.setLayout(new FlowLayout(FlowLayout.CENTER,10,10)); p1.add(l1); p1.add(t1); p1.add(l2); p1.add(t2); p1.add(l3); p1.add(t3); p3.setBackground(Color.white); f.setLayout(new BorderLayout(5,5)); f.add(p1,"South"); f.add(p2,"East"); f.add(p3,"Center"); f.setVisible(true); sb.addAdjustmentListener(this); sb1.addAdjustmentListener(this); sb2.addAdjustmentListener(this); f.addWindowListener(this); } public static void main(String args[]) { new ColourGenerate(); } public void adjustmentValueChanged(AdjustmentEvent e) { Object o; o=e.getSource(); if(o==sb) { int v1,v2,v3; v1=sb.getValue(); t1.setText(""+v1); v2=sb1.getValue(); v3=sb2.getValue(); Color c1=new Color(v1,v2,v3); p3.setBackground(c1); } else if(o==sb1) { int v2; v2=sb1.getValue(); t2.setText(""+v2); Color c2=new Color(sb.getValue(),v2,sb2.getValue()); p3.setBackground(c2); } else if(o==sb2) { t3.setText(""+sb2.getValue()); Color c3=new Color(sb.getValue(),sb1.getValue(),sb2.getValue()); p3.setBackground(c3); } } public void windowClosing(WindowEvent e1) { Window w; w=e1.getWindow(); w.setVisible(false); w.dispose(); System.exit(1); } } |
No comments:
Post a Comment