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 2 of 2

Thread: trying to insert an image using button in java swing. please modify the content to get the right output

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

    Default trying to insert an image using button in java swing. please modify the content to get the right output

    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    class image implements ActionListener
    {
    	JFrame frmobj= new JFrame("image");
    	JPanel panel= new JPanel();
    	JButton b1= new JButton("image");
    	JLabel pic;
    	ImageIcon ico;
    	image()
    	{
    		frmobj.setVisible(true);
    		frmobj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frmobj.setBounds(200, 200, 500, 500);
    		frmobj.getContentPane().add(panel);
    		panel.add(b1);
    		b1.addActionListener(this);
    		pic= new JLabel(ico);
    		panel.add(pic);
     
     
    	}
    	public void actionPerformed(ActionEvent aet)
    	{
    		ico=new ImageIcon("D:\\z.jpg");	
     
    	}
    	public static void main(String[] args)
    	{
    		new image();
    	}
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,287
    My Mood
    Mellow
    Thanks
    252
    Thanked 777 Times in 762 Posts

    Default Re: trying to insert an image using button in java swing. please modify the content to get the right output

    Welcome to the forum! Thanks for taking the time to learn how to post code correctly. If you haven't already, please read this topic to learn other useful info for new members.

    Java's naming conventions include giving classes names that begin with capital letters. However, you should also avoid using class names that already exist in Java SE.

    We could do as you've asked, but code that worked in our development environments wouldn't necessarily work in yours. If you're getting errors, post them. Otherwise, describe what is happening when you press the button and how you would like that behavior to change.

Similar Threads

  1. How to show the output image (using java) as resultant image in webpage
    By Mumpy Zinu in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: February 24th, 2014, 08:00 AM
  2. Facing issues while rendering Jpeg200 image in Swing in Java 7
    By chandan2908 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 9th, 2013, 08:25 AM
  3. Replies: 1
    Last Post: June 29th, 2012, 02:29 PM
  4. press a button, get textfield content
    By chopficaro in forum AWT / Java Swing
    Replies: 1
    Last Post: May 2nd, 2010, 01:28 PM
  5. Content Based Image Retrieval
    By sanjay_jbp in forum AWT / Java Swing
    Replies: 9
    Last Post: March 1st, 2010, 08:55 PM