AdjustmentEvent

Advertisements

Prev Tutorial Next Tutorial

Event handling for Scrollbar

AdjustmentEvent class and AdjustmentListener interface are used for handling event for scrollbar.

This event class and Listener interface are associalted with Scrollbar component adjustmentValueChanged() contains the logic to perform any operation if scrollbar position is changed.

GUI ComponentEvent classListener InterfaceMethod (abstract method)
ScrollbarAdjustmentEventAdjustmentListenerpublic void adjustmentValueChanged(ItemEvent e)

Example of AdjustmentEvent

import java.awt.*;
import java.awt.event.*;

class AdjustmentEventEx extends Frame implements AdjustmentListener
{
int rval=0,gval=0,bval=0;
Scrollbar sr,sb,sg;
Panel ps;
AdjustmentEventEx()
{
	ps=new Panel();
	Label l1=new Label("Red");
	Label l2=new Label("Green");
	Label l3=new Label("Blue");
	sr=new Scrollbar(Scrollbar.HORIZONTAL,0,5,0,255);
	sg=new Scrollbar(Scrollbar.HORIZONTAL,0,5,0,255);
	sb=new Scrollbar(Scrollbar.HORIZONTAL,0,5,0,255);
	ps.add(l1);
	ps.add(sr);
	ps.add(l2);
	ps.add(sg);
	ps.add(l3);
	ps.add(sb);
	add("South",ps);
	sr.addAdjustmentListener(this);
	sg.addAdjustmentListener(this);
        sb.addAdjustmentListener(this);
	setSize(400,400);
	setVisible(true);
	}
	public void adjustmentValueChanged( AdjustmentEvent e)
	{
		if(e.getSource().equals(sr))
		{
			rval=sr.getValue();
			setBackground(new Color(rval,bval,gval));
		}
		if(e.getSource().equals(sg))
		{
			gval=sg.getValue();
			setBackground(new Color(rval,gval,bval));
		}
		if(e.getSource().equals(sb))
		{
			bval=sb.getValue();
			setBackground(new Color(rval,gval,bval));
		}
	}

	public static void main(String[] args) 
	{
		AdjustmentEventEx ae=new AdjustmentEventEx();
	}
}

Download code Click

adjustmentevent example
Prev Tutorial Next Tutorial

Advertisements

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

Download Projects

Advertisements


Buy Websites 9999595223

Buy Fresh and Payment Receive Media.net Account with Website. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs