Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: no image is being displayed.. please help..

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default no image is being displayed.. please help..

    import javax.swing.*;
    import javax.imageio.ImageIO;
    import java.awt.Graphics;
    import java.io.*;
    import java.awt.Image;
    import java.awt.*;


    public class MyClass {

    public static void main(String[] args)throws Exception {
    new Extra();

    }

    }
    class Extra extends JFrame
    {
    JMenuBar mb;
    JMenu File,View,Settings,Audio,Video,Help;
    JMenuItem OpenFile,OpenDirectory,OpenDisc,Exit,PlayList, Messages,SwitchInterface,AddInterface,Bookmarks,Pr eferences,About;
    MyPanel mp;
    Extra()
    {

    super("JKS Player");
    setLayout(null);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mb=new JMenuBar();
    File=new JMenu("File");
    View=new JMenu("View");
    Settings=new JMenu("Settings");
    Audio=new JMenu("Audio");
    Video=new JMenu("Video");
    Help=new JMenu("Help");
    OpenFile=new JMenuItem("Open File");
    OpenDirectory=new JMenuItem("Open Directory");
    OpenDisc=new JMenuItem("Open Disc");
    Exit=new JMenuItem("Exit");
    PlayList=new JMenuItem("PlayList");
    Messages=new JMenuItem("Messages");
    SwitchInterface=new JMenuItem("Switch Interface");
    AddInterface=new JMenuItem("Add Interface");
    Bookmarks=new JMenuItem("Bookmarks");
    Preferences=new JMenuItem("Preferences");
    About=new JMenuItem("About");
    mb.add(File);
    mb.add(View);
    mb.add(Settings);
    mb.add(Help);
    File.setBounds(0, 0, 5,2 );
    View.setBounds(5, 0, 5,2);
    Settings.setBounds(10,0,5,2);
    Help.setBounds(15, 0, 5, 2);
    File.add(OpenFile);
    File.add(OpenDirectory);
    File.add(OpenDisc);
    File.add(Exit);
    View.add(PlayList);
    View.add(Messages);
    Settings.add(SwitchInterface);
    Settings.add(AddInterface);
    Settings.add(Bookmarks);
    Settings.add(Preferences);
    Help.add(About);
    mp=new MyPanel();
    add(mp);
    pack();
    setVisible(true);
    mb.setVisible(true);
    mp.setVisible(true);
    setSize(600,600);
    setJMenuBar(mb);

    }
    class MyPanel extends JPanel
    {


    public void Paint(Graphics g)
    {
    try{
    Image img=ImageIO.read(new File("C:\\Users\\Mehta\\Desktop\\images\\Capture a.jpg"));
    g.drawImage(img,5,2,this);
    }catch(Exception e){ };
    }
    }

    }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: no image is being displayed.. please help..

    a) Java is case sensitive - paint != Paint. b) You should not read an image for every call to paint. Read it once, keep a references, and use the reference to paint c) Please wrap your code in the code tags. The forum rules describe how to do this d) Suggested reading: Code Conventions for the Java Programming Language

    Thread moved to http://www.javaprogrammingforums.com/awt-java-swing/

  3. #3
    Junior Member
    Join Date
    Jul 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: no image is being displayed.. please help..

    thank you. But I still cannot find the solution.

Similar Threads

  1. Applet: Calculated variable can't be displayed
    By iTTerror in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 12th, 2012, 01:23 AM
  2. [SOLVED] Refreshing Variables Displayed on a JPanel
    By StandbyExplosion in forum What's Wrong With My Code?
    Replies: 6
    Last Post: August 24th, 2011, 06:14 PM
  3. Replies: 2
    Last Post: February 14th, 2011, 05:36 PM
  4. Getting a red Oval to displayed on screen
    By warnexus in forum What's Wrong With My Code?
    Replies: 8
    Last Post: January 13th, 2011, 08:27 PM
  5. Certain Chinese Characters not displayed properly.
    By kerwintang in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: August 20th, 2009, 08:23 AM