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

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
;/html> Zoom Out Effect: ADS_TO_REPLACE_2 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
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
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.
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"
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
java code - Java Beginners
java code  can u please post java code for zoom in and zoom out an bufferedImage class image
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
provide code - Swing AWT
); } } ------------------------------------- visit for more information. http://www.roseindia.net/java/example/java/swing/ Thanks...provide code  Dear frnds please provide code for two player CHESS
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
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
source code - Swing AWT
source code  source code for a program to shutdown, restart, log off the pc after clicking jbutton on jpanel or a jframe by user. thanks in advance
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 - Swing AWT
java swing   how i can insert in JFrame in swing?  Hi Friend, Try the following code: import java.awt.*; import javax.swing.*; import java.awt.event.*; class FormDemo extends JFrame { JButton ADD; JPanel
java swing - Swing AWT
java swing  how i can insert multiple cive me exampleolumn and row in one JList in swing?plz g  Hi Friend, Please clarify your question. Thanks
java swing - Swing AWT
java swing   Iam developing a java web browser.Actually my code works fine ie. i can load a web page without proxy.But in my place i have only proxy... a proxy or how to make my java web browser to listen to proxy setting??? please help
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
Need source code - Swing AWT
Need source code  Hai, In java swing, How can upload and retrieve the images from the mysql database?   Hi Friend, To upload and insert image in database, try the following code: import java.sql.*; import
Java swing
Java swing  what are the root classes of all classes in swing
Java swing
Java swing  Does Swing contains any heavy weight component
java swing
java swing  view the book details using swing
I need help on my Java code.... please please help me out!?
I need help on my Java code.... please please help me out!?  Well my code is supposed to ask for an input file and then (ex: input.txt), read... in the file. Also it should be displayed on the screen. However my code doesn't display
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  how to connect database with in grid view in java swing   Hi Friend, Please visit the following link:ADS_TO_REPLACE_1 Grid view in java swing Thanks
ModuleNotFoundError: No module named 'commented-out-code'
ModuleNotFoundError: No module named 'commented-out-code'  Hi, My... named 'commented-out-code' How to remove the ModuleNotFoundError: No module named 'commented-out-code' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'commented-out-code'
ModuleNotFoundError: No module named 'commented-out-code'  Hi, My... named 'commented-out-code' How to remove the ModuleNotFoundError: No module named 'commented-out-code' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'commented-out-code'
ModuleNotFoundError: No module named 'commented-out-code'  Hi, My... named 'commented-out-code' How to remove the ModuleNotFoundError: No module named 'commented-out-code' error? Thanks   Hi, In your
AWT code for popUpmenu - Swing AWT
AWT code for popUpmenu  Respected Sir/Madam, I am writing a program in JAVA/AWT.My requirement is, a Form consists of a "TextBox" and a "Button... the code. ThanQ.   import java.awt.BorderLayout; import
tetris game code - Swing AWT
tetris game code  To develop a JAVA puzzle game which is a "variation" of the Tetris game
java swing
java swing  add two integer variables and display the sum of them using java swing
Java swing
Java swing  Write a java swing program to calculate the age from given date of birth

Ads