Prajakta S
Java Swing code for zoom in and out
1 Answer(s)      3 years and 10 months ago
Posted in : Java Beginners

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??????????????????????????/

Advertisement
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();
    }
    }









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
JAVA image zoom in/out - Framework
JAVA image zoom in/out  how to write function in java for image zoom in and zoom out using jFreeChart?  Hi Friend, Try the following code: import java.awt.* ; import org.jfree.ui.*; import org.jfree.data.
Advertisements
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
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
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
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
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
MX Zoom Effect in Flex4
MX Zoom Effect in Flex4: The component will zoom in or out on a center point using Zoom effect. The tag of Zoom effect is <mx:Zoom>. The syntax is following: <mx:Zoom id="ID" originX="Calculated"
java code - Swing AWT
java code  Imagine you need to open a standard combination dial lock... to write a Java program that prints all possible combinations so you can print them... to open the lock  Hi Friend, Try the following code: class
java code - Swing AWT
java code  i want to open a new dialog box after clicking "upload" button, it should have a text field, browse button to browse the file from directory  Hi Friend, Try the following code: 1)OpenDialog.java import
java code - Swing AWT
java code  Hello .anyone can plz tell me code for this .First create a button wen it is clicked its enters into another window asking for Name .After...   Hi Friend, Try the following code: import java.io.*; import
Java Code - Swing AWT
Java Code  Write a Program using Swings to Display JFileChooser that Display the Naem of Selected File and Also opens that File
Java Code - Swing AWT
Java Code  How to Display a Save Dialog Box using JFileChooser and Save the loaded Image from Panel in any Location.  Hi Friend, Try the following code: import java.io.*; import java.awt.*; import java.util.
Java Code - Swing AWT
Java Code  How to Make an application by using Swings JMenuBar and other components for drawing various categories of Charts(Line,Bar etc
Java swing code - Java Beginners
Java swing code  How to set a font for a particular cell in JTable... in Swing. We have a huge amount of good examples on JTable here. http://www.roseindia.net/java/example/java/swing I hope this would be helpful to you
Java swing code - Java Beginners
Java swing code  How to validate input data entered into the swing applications in java?   Hi Friend, Try the following code: import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.util.
java code - Java Beginners
java code  can u please post java code for zoom in and zoom out an bufferedImage class image
uiwebview zoom
uiwebview zoom  Hi, I want to zoom UIWebview programmatically. Please provide me code. Thanks   Hi, First you set the "Scales Pages to Fit" property of your webview in interface builder. Then use the following code
swing login code
swing login code  code for the login form
put image on form creating in swing-swing code - Swing AWT
put image on form creating in swing-swing code  i want to display image on swing panel and get the image co ordinate by mouse clicking.and also zoom the image at particular area of image. please give solution on my email id
code - Swing AWT
code  i want example problem for menubar in swings  Hi Friend, Please visit the following links: http://www.roseindia.net/java/example/java/swing/SwingMenu.shtml http://www.roseindia.net/java/example/java/swing
verify the code and give me the code with out errors
verify the code and give me the code with out errors   import...","HARDWARE","VB.NET","JAVA","ASP.NET","ECE"}; JLabel l7=new JLabel("COURSE...++","JAVA","J2EE","VB.NET","ASP.NET","PHP","NETWORKING","WIRELESS"}; JLabel l8=new
with out class - Java Beginners
with out class  can we write a program with out a class in core java?if yes,give example
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 - 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