♠ Posted by Unknown in Core Java at 06:42
Applet: AWT ScrollBar Class
//Write an applet that contains three scroll-bars.
package mj;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.*;
public class ScrollBarApplet extends Applet implements AdjustmentListener
{
Scrollbar rsb,gsb,bsb;
Canvas can;
public void init()
{
rsb=new Scrollbar(Scrollbar.HORIZONTAL,0,5,0,255);
rsb.addAdjustmentListener(this);
bsb=new Scrollbar(Scrollbar.HORIZONTAL,0,5,0,255);
bsb.addAdjustmentListener(this);
gsb=new Scrollbar(Scrollbar.HORIZONTAL,0,5,0,255);
gsb.addAdjustmentListener(this);
can=new Canvas();
can.setSize(20,30);
Label l2=new Label("green");
Label l3=new Label("blue");
add(l1);
add(rsb);
add(l2);
add(bsb);
add(l3);
add(gsb);
}
public void adjustmentValueChanged(AdjustmentEvent ae)
{
can.repaint();
}
public void paint(Graphics gg)
{
int r=rsb.getValue();
int b=bsb.getValue();
int g=gsb.getValue();
can.setBackground(new Color(r,g,b));
}
}
0 comments:
Post a Comment