Java Swing code for zoom in and out

Ads
 

Java Swing code for zoom in and out

hi..........

I require a code in java swing for image zoom in and zoom out can u tell me how it can be done or what is the code plz help??????????????????????????/

View Answers

October 3, 2011 at 3:49 PM

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

class zoomPanel extends Panel{
    MediaTracker tracker;
    Image img;
    Dimension imgSize,iniSize;

    public zoomPanel(){
    setSize(400,275);
    img=Toolkit.getDefaultToolkit().getImage("C:/map.jpg");
    tracker=new MediaTracker(this);
    tracker.addImage(img,1);

    try{
    tracker.waitForAll();
    }
    catch(Exception ie){}
    imgSize=iniSize=new Dimension(img.getWidth(this),img.getHeight(this));
    }

    public Dimension getPreferredSize(){
    return new Dimension(imgSize);
    }

    public void paint(Graphics g){
    if(imgSize.width<=iniSize.width)
        imgSize=iniSize; 
        g.drawImage(img,(getWidth()-imgSize.width)/2,(getHeight()-imgSize.height)/2,imgSize.width,imgSize.height,this);
    }
    public void increaseSize(){
        int x=10*imgSize.width/100; 
        int y=10*imgSize.height/100;
        imgSize=new Dimension(imgSize.width+x,imgSize.height+y); 
        if(imgSize.width>iniSize.width){
            setSize(imgSize);
            getParent().doLayout();
        }
        repaint();
     }
        public void decreaseSize(){
        int x=10*imgSize.width/100;
        int y=10*imgSize.height/100;
        imgSize=new Dimension(imgSize.width-x,imgSize.height-y);
        if(getWidth()>iniSize.width){
            setSize(imgSize);
            getParent().doLayout();
                }
        repaint();
        }
    }
    public class ZoomImage extends Frame implements ActionListener{
    Button zoomIn,zoomOut;
    Panel pS;
    zoomPanel pN;
    ScrollPane sp;

    public ZoomImage(){
    zoomIn=new Button("Zoom In");
    zoomOut=new Button("Zoom Out");

    zoomIn.addActionListener(this);
    zoomOut.addActionListener(this);
    pN=new zoomPanel();
    pS=new Panel();
    pS.setBounds(0,275,400,25);

    pS.add(zoomIn);
    pS.add(zoomOut);
    setLayout(null);

    sp=new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
    sp.setSize(400,275);

    sp.add(pN);

    Adjustable vadjust = sp.getVAdjustable();
    Adjustable hadjust = sp.getHAdjustable();
    hadjust.setUnitIncrement(10);
    vadjust.setUnitIncrement(10);

    add(sp);
    add(pS);
    setVisible(true);
    setSize(400,320);
    }
    public void paint(Graphics g){ }
    public void actionPerformed(ActionEvent ae){
    if(ae.getSource()==zoomIn) pN.increaseSize();
    if(ae.getSource()==zoomOut)pN.decreaseSize();

    }
    public static void main(String[]args){
        new ZoomImage();
    }
    }

Ads









Related Tutorials/Questions & Answers:
Java Swing code for zoom in and out
Java Swing code for zoom in and out  hi.......... I require a code in java swing for image zoom in and zoom out can u tell me how it can be done or what is the code plz help
JavaScript Zoom in and Zoom out
Out Effect: Zoom In Effect: Download Source Code:  ... illustrates you how to zoom in and zoom out of an image using JavaScript. Here we... and width of the image and make it to show the effect Zoom In and Zoom Out
Advertisements
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form
UIWebView Zoom in and out
UIWebView Zoom in and out  Hi, Can anyone give me the example of tap and zoom in and out the pdf loaded on uiwebview?? Thanks
Zoom Out Excel
zoom out excel       In this program we are going to make a java program through which we can zoom out(+) an excel sheet. This means you can make an excel sheet larger
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form"   import javax.swing.*; import java.sql.*; import java.awt.*; import
Commenting out your code - Java Tutorials
Commenting Erroneous Code & Unicode newline Correct In this section, you will find an interesting  problem related to commenting erroneous code... be its possible solution. First you need to get a look of the code: public
swing login code
swing login code  code for the login form
Causing Deadlocks in Swing Code
Causing Deadlocks in Swing At First Consider the Deadlocks A deadlock... that resources. It is a common problem in multithreading. Consider the Sample code... and by adding  the new DesktopPain to the Content Pain it starts the Swing Thread
java swing
java swing  view the book details using swing
java swing - Swing AWT
java swing  how to add image in JPanel in Swing?  Hi Friend, Try the following code: import java.awt.*; import java.awt.image....: http://www.roseindia.net/java/example/java/swing/ Thanks
java swing
java swing  what is java swing   Swing is a principal GUI toolkit for the Java programming language. It is a part of the JFC (Java Foundation Classes), which is an API for providing a graphical user interface for Java
Java swing
Java swing  Write a java swing program to calculate the age from given date of birth
Java swing
are displayed in the table..I need the source code in java swing...Java swing  If i am login to open my account the textfield,textarea and button are displayed. if i am entering the time of the textfield
java swing.
java swing.  Hi How SetBounds is used in java programs.The values in the setBounds refer to what? ie for example setBounds(30,30,30,30) and in that the four 30's refer to what
JAVA SWING
JAVA SWING  Hi.... Iam doing project in java...and my front end in swing ..our project is like billing software... then what are the topics i want cover? then how to design? pls help me
Java swing
to the database using java swing...Java swing  I create one table. That table contains task ID and Task Name. When I click the task ID one more table will be open and that table
intranet in java swing
intranet in java swing  i want source code of intranet establishment in java swing
Java swing
Java swing  when i enter the time into the textbox and activities into the textarea the datas saved into the database.the java swing code for the above item   import java.sql.*; import java.awt.*; import javax.swing.
java swing
java swing  what is code for diplay on java swing internal frame form MYSQL DB pls send   Here is a code of creating form on jinternalframe and connect to mysql. import java.io.*; import java.sql.*; import java.awt.
Java swing
Java swing  how to create simple addition program using java swing?   import java.awt.*; import javax.swing.*; import java.awt.event.*; class SumOfNumbers extends JFrame { SumOfNumbers(){ JLabel lab1=new
Swing error in code
Swing error in code  import java.rmi.*; import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*; public class SClientsr extends JFrame { TextField t1=new TextField(20); Label rs
Java swing
Java swing  How to combine two java files
java swing
java swing  meaning of out.flush
Java swing
Java swing  Design an appliaction for with details such as name,age,DOB,address,qualification and finaly when we click the view details button all... code
Java swing
Java swing  I create 2 text field f1,f2 and 2 button b1,b2.If i enter some text in the text field and click the button b1 the text field f1 text... f2 text will be shown in another one Messagedialog box.I Need the code

Ads