Results 1 to 8 of 8
  1. #1
    asmitarnd is offline Member
    Join Date
    Mar 2011
    Posts
    22
    Rep Power
    0

    Thumbs down components display

    hi frnds,

    I m trying to display multiple images on a single JFrame.I want to add those images directly to my JFrame.I have created a class where i get multiple images.But now i m trying to create multiple objects of the same class and add those objects JFrame directly.Can i do so? And if yes how?

    I have tried with this



    /*displaying image on a frame*/

    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.net.ConnectException;
    import java.util.Iterator;
    import java.util.Vector;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;

    import PQSDKMultiTouch.*;

    /**
    * @author PQLabs
    *
    */
    public class TestClient extends PQMTClient
    {

    public ImageDrawingComponent imageCompent;
    public ImageDrawingComponent imageCompent1;

    public static void main(String[] args)throws Exception
    {
    JFrame f = new JFrame("PQ test");
    f.setSize(1024, 768);
    //exit application when window is closed.

    //JPanel panel = new JPanel();

    f.addWindowListener(new WindowAdapter()
    {
    public void windowClosing(WindowEvent e)
    {
    System.exit(0);
    }
    });


    TestClient testClient=new TestClient();
    testClient.Init();

    //panel .add(testClient.imageCompent);
    //panel .add(testClient.imageCompent1);


    //f.getContentPane().add(new JPanel());

    /******** this is what i want to do**********/

    f.add(testClient.imageCompent);
    f.validate();
    f.add(testClient.imageCompent1);


    //f.pack();
    f.setVisible(true);
    }

    public TestClient()
    {
    imageCompent = new ImageDrawingComponent("img1.jpg");
    imageCompent1 = new ImageDrawingComponent("img2.jpg");

    }

    }






    //Loading image

    import java.awt.*;
    import java.awt.geom.AffineTransform;
    import java.awt.image.AffineTransformOp;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;

    import javax.imageio.ImageIO;



    public class ImageDrawingComponent extends Component
    {
    BufferedImage img;
    Graphics2D g2;

    public ImageDrawingComponent(String fileName)
    {
    try
    {
    img=ImageIO.read(new File(fileName));
    } catch (IOException e) {
    e.printStackTrace();
    }

    public void paint(Graphics g)
    {
    g2=(Graphics2D)g;

    AffineTransform at = AffineTransform.getScaleInstance(currentRate, currentRate);
    g2.drawImage(img, at, null);

    }



    can anyone plz help me as soon as possible.waiting for your reply.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,185
    Rep Power
    20

    Default

    Can you use code tags when posting code please.

    What happens when you try to add your image components to the JFrame?

  3. #3
    asmitarnd is offline Member
    Join Date
    Mar 2011
    Posts
    22
    Rep Power
    0

    Default

    only the last image added to the JFrame gets loaded on that frame

  4. #4
    asmitarnd is offline Member
    Join Date
    Mar 2011
    Posts
    22
    Rep Power
    0

    Default

    I have also tried with array of BufferedImage.I m able to display those images but the thing is that i m developing multitouch appln so when i try to interact with single image those 3 images are treated as a single image.so i m trying with that approach which i had posted.can u help mi for the same.waiting

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    I believe the frames content pane is a borderlayout, try changing it to a flow layout and see what happens.

  6. #6
    asmitarnd is offline Member
    Join Date
    Mar 2011
    Posts
    22
    Rep Power
    0

    Default

    I have also tried with each and every LayoutManagers but still it does'nt work.Can u plz help me to find the position of the image with respect to that frame

  7. #7
    asmitarnd is offline Member
    Join Date
    Mar 2011
    Posts
    22
    Rep Power
    0

    Default

    String [] files ={ "D:\\rnd\\testImages\\test.jpg","D:\\rnd\\testImag es\\test1.jpg" ,"D:\\rnd\\testImages\\test2.jpg"};
    BufferedImage[] images = new BufferedImage[files.length];
    int i;
    for(i = 0; i < files.length; i++)
    {
    try
    {
    images[i] = ImageIO.read(new File(files[i]));
    System.out.println("i m here");
    }
    catch(Exception e)
    {
    System.out.println("Cant find file " +files[i]);
    }
    }


    g2.drawImage(images[0],0,0,null);
    g2.drawImage(images[1],200,0,null);
    g2.drawImage(images[2],250,0,null);


    this is the paint method which i had tried with to display multiple images on a single JFrame.It works fine i m able to display multiple images.But now i m developing a multitouch application so when i try to interact with a single image all three images are treated as single image.so can u plz help mi to find the location of each image on a single JFrame?waiting for reply

  8. #8
    asmitarnd is offline Member
    Join Date
    Mar 2011
    Posts
    22
    Rep Power
    0

    Default

    hi,
    i have successfully displayed multiple images on asingle frame but i m facing another problem.All the images are displayed of same size though i change the resolution of those images.The only difference i have done in the previously posted program is that class ImageDrawingComponent instead of extending Component it extends JPanel now.can u plz help to solve this issue.waiting for reply

Similar Threads

  1. Replies: 1
    Last Post: 12-01-2010, 07:35 PM
  2. Replies: 1
    Last Post: 05-31-2010, 09:46 AM
  3. Replies: 8
    Last Post: 12-29-2008, 08:12 AM
  4. Replies: 0
    Last Post: 06-28-2008, 10:26 PM
  5. GUI components not display
    By Eranga in forum AWT / Swing
    Replies: 2
    Last Post: 03-12-2008, 03:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •