Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Java Swing code for zoom in and out

Have Programming Question? Ask it here!
 
 
 


Prajakta S
Java Swing code for zoom in and out
1 Answer(s)      2 years and 7 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
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"
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,java newsletter,java,tutorial
Causing Deadlocks in Swing Code (Follow-up) 2005-01-19 The Java Specialists' Newsletter [Issue 101b] - Causing Deadlocks in Swing Code (Follow-up) Author.... It is very dangerous sending out code samples that one does not understand fully
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
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
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   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
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
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
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
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
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
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  how to connect database with in grid view in java swing   Hi Friend, Please visit the following link: Grid view in java swing Thanks
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
with out class - Java Beginners
with out class  can we write a program with out a class in core java?if yes,give example
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
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.
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
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
java swing - Swing AWT
java swing  how to save data in sql 2005 while insert in textfield  Hi Friend, Try the following code: import java.sql.*; import javax.swing.*; import javax.swing.border.*; import java.awt.*; import
mkmapview zoom to current location
mkmapview zoom to current location  How can i zoom map to the current location
Advertisements
 

 

 

DMCA.com