AdjustmentEvent

Google 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

Google Advertisements

Buy This Ad Space @$50 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

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user. Cloud Computing Tutorial

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects. Download Java C C++ Projects

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: hitesh.xc@gmail.com or 8076671483 Try this Keyword C++ Programs