Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Event on Slide bar In Java

                         

Introduction

In this section, you will learn about the event handling for a swing component named Slide bar. This section provides a complete solution for the appropriate functionality by providing a program.

Program Description:

This program gives you two slide bar and a image inside the frame. One slide bar is arranged as horizontal while another one is as vertical. And the image is stayed in between both slide bar. When you drag the horizontal slide bar then the image will be increased or decreased from left and right according to the value of the slide bar while when you drag the vertical slide bar then the image will be increased or creased from top and bottom according to the value of the slide bar.

Code Description:

In this program, you will see that the complete code has been written under the DynamicIconText class. This class has a main method in which there are two slide bars have been created by using JSlider class and it's constructor. Constructor of JSlider class is has four parameters as follows:

  • First is used for orientation of the slide bar. Here a field JSlider.HORIZONTAL has been used for the arranging the slide bar horizontal on the frame. It's default value is 0. And the value of JSlider.VERTICAL field is 1 that is used for arranging slide bar vertical on the frame.
  • Second argument is also a integer value that is used for the minimum limitation of the slide bar.
  • Third one is used for the maximum limitation of the slide bar component.
  • And last one is for the value of the slide bar. This value is set for slide bar component when the frame is opened.

There are some APIs are explained below these are used in the following program:

getValue(): This method is used for getting value of the slide bar. This method returns a integer value.

Here is the code of this program:        

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;

public class DynamicIconText{
  public static void main(String[] args) {
    final JSlider width = new JSlider(JSlider.HORIZONTAL, 5150125);
    final JSlider height = new JSlider(JSlider.VERTICAL, 5150125);

    class DynamicIcon implements Icon {
      public int getIconWidth() {
        return width.getValue();
      }

      public int getIconHeight(){
        return height.getValue();
      }

      public void paintIcon(Component c, Graphics g, int x, int y) {
        g.fill3DRect(x, y, getIconWidth(), getIconHeight()true);
      }
    }
    
    Icon icon = new DynamicIcon();
    final JLabel jl = new JLabel(icon);

    class Updater implements ChangeListener {
      public void stateChanged(ChangeEvent e) {
        jl.repaint();
      }
    };

    Updater ud = new Updater();
    width.addChangeListener(ud);
    height.addChangeListener(ud);
    JFrame fm = new JFrame();
    fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container ca = fm.getContentPane();
    ca.setLayout(new BorderLayout());
    ca.add(width, BorderLayout.NORTH);
    ca.add(height, BorderLayout.WEST);
    ca.add(jl, BorderLayout.CENTER);
    fm.setSize(250,250);
    fm.setVisible(true);
  }
}

Output this program:

Download this program.

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

Hi All,
I want to thanks all developer under roseindia.net.
I think it is a excellent!excellent!excellent! tutorial site in the world.
Specially Thank to all of you for Java Swt Tutorial.

Dayal Manna

Posted by Dayal Manna on Monday, 07.23.07 @ 18:48pm | #21783

Latest Searches:
Photoshop Web Layouts
Ñ?оâ???Ñ?опÑ?п???Ñ
JSTL : Submit Form Tex
jsp login
Linux Caixa Mல??ர?
Java Count Vowels in t
convert of avi to 3gp
Linux Caixa MÃ? Ã? Ã
J2se Tutorialcoonectiv
json lib/componen...]=
jsp login by insertin
rational clear case
Multiplication of Two
call ร?????ร
sample program for mar
interview question in
inheritence
5. Create an applet fo
Java date format
enum example
determinan of a matrix
Photoshop Effects Lase
jdbc using prepared st
character in javascrip
Flash Text Effects Col
sample program for mar
call à®°??????à®°????à
.getString
java bean
ImageReader
Photoshop Drawing Drag
system.out.println(x
flowchart to generate
javagrid
ADO NET C
Linux Caixa Mத��
Examples on List
java program to write
list content
how to capture multipl
wrapper class
loops in java
java date compare exam
�£??�£?�¢�?�£
delete data in mysql d
<bean:define>
how to declare an arra
append CRLF
importing class in to
auto-logout
call நà¯??தà¯?தà
select atleast one rad
Photoshop Photo Retouc
consructor overloading
Combattons la programm
request.setAttribute i
sockets
how checked row should
Combattons la programm
jdk download
Photoshop Effects Disp
javabean program
jstl list size
concatenate java
Exceptions
dojo Multiple Select
dojo Multiple CheckBox
informatica
how to input number in
properties file in str
logger in struts
�?�ะ�
Configure
JSP:File Input Paramet
socket_create php
jasper report
PGP Java API 2.0
jQuery to Select Multi
packages in java
�����?��
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.