Results 1 to 3 of 3
  1. #1
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    450
    Rep Power
    7

    Default challenge for swing programmers

    hi i am pandian.
    i have tried to display image in Jframe .
    but it is only applicable for jpeg and png .

    but i want to display image in bmp format.

    i couldn't get it.

    help me.

    regards
    mak.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Let's see your attempt. What you should do is to write a very small compilable app that does nothing at all except try to show a BMP picture in the JFrame. Post it here with code tags and let's see what we can do to help you along. Oh, also are you using ImageIO to read in the BMP?

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Here's my attempt:
    Java Code:
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.net.URL;
    
    import javax.imageio.ImageIO;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    
    public class ShowBMP
    {
      private static final String IMAGE_PATH =  
        "http://wvnvaxa.wvnet.edu/vmswww/images/test32v5.bmp";
      private JPanel mainPanel = new JPanel()
      {
        @Override
        protected void paintComponent(Graphics g)
        {
          super.paintComponent(g);
          if (image != null)
          {
            g.drawImage(image, 0, 0, this);
          }
        }
      };
      Image image;
    
      public ShowBMP()
      {
        try
        {
          image = ImageIO.read(new URL(IMAGE_PATH));
          int width = image.getWidth(mainPanel);
          int height = image.getHeight(mainPanel);
          mainPanel.setPreferredSize(new Dimension(width, height));
        }
        catch (MalformedURLException e)
        {
          e.printStackTrace();
        }
        catch (IOException e)
        {
          e.printStackTrace();
        }
      }
    
      public JComponent getPanel()
      {
        return mainPanel;
      }
    
      private static void createAndShowGUI()
      {
        JFrame frame = new JFrame("ShowBMP Application");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(new ShowBMP().getPanel());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      }
    
      public static void main(String[] args)
      {
        javax.swing.SwingUtilities.invokeLater(new Runnable()
        {
          public void run()
          {
            createAndShowGUI();
          }
        });
      }
    }

Similar Threads

  1. Ultimate challenge in JComboBox
    By vaidhu in forum AWT / Swing
    Replies: 3
    Last Post: 08-21-2008, 07:56 PM
  2. Looking for JAVA Programmers!
    By offshoring in forum Jobs Offered
    Replies: 0
    Last Post: 02-05-2008, 07:52 AM
  3. Hello java programmers...
    By coder_ in forum Introductions
    Replies: 2
    Last Post: 01-23-2008, 06:23 AM
  4. java programming challenge Number 1
    By tacosalad in forum New To Java
    Replies: 5
    Last Post: 01-16-2008, 11:25 PM
  5. The Million Musician Challenge 0.821
    By levent in forum Java Software
    Replies: 0
    Last Post: 05-25-2007, 08:39 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
  •