Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 5th, 2013, 06:21 PM
jumpman8947 jumpman8947 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 5 jumpman8947 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 57 m 46 sec
Reputation Power: 0
Displaying java image

Hi I'm trying to create a program that displays buttons(JButton) as well as images inside of panels. Everything is going well except my images aren't showing up. Buttons are fine its just the images that's giving me the problem. here's the code thanks,
Code:
import java.awt.*;
import javax.swing.*;

public class Work extends JFrame
{
	private final int WINDOW_WIDTH = 1000;				//Window width
	private final int WINDOW_HEIGHT = 1000;				//Window height
	private JPanel imagePanel;
	private JLabel imageLabel;
	private JLabel ImageIcon;
	private JLabel label1;
	private JLabel label2;
	private JLabel label3;

	public Work()
		{
			// Set the title bar text.
			setTitle("Border Layout");

			setSize(WINDOW_WIDTH, WINDOW_HEIGHT);

			// Specify an action for the close button.
			setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

			//Add a BorderLayout manager to the content pane.
		setLayout(new BorderLayout());

		//Create five panels.
				JPanel panel1 = new JPanel();
				JPanel panel2 = new JPanel();
				JPanel panel3 = new JPanel();
				JPanel panel4 = new JPanel();
				JLabel panel5 = new JLabel();

				JButton button1 = new JButton("Click to Enter");
				JButton button2 = new JButton("Exit");
				JLabel label1 = new JLabel("bible");
				JLabel label2 = new JLabel ();
				JLabel label3 = new JLabel();

				panel1.add(button1);
				panel2.add(button2);
				panel3.add(label1);
				panel4.add(label2);
				panel5.add(label3);

				add(panel1, BorderLayout.CENTER);
				add(panel2, BorderLayout.SOUTH);
				add(panel3, BorderLayout.WEST);
				add(panel4, BorderLayout.EAST);
				add(panel5, BorderLayout.NORTH);

				pack();
				setVisible(true);
			}
			private void ImageIcon()
			{
				ImageIcon image = new ImageIcon("bible3.gif");
				JLabel label1 = new JLabel(image);
				pack();
				setVisible(true);

			}
			private void label1()
			{
				ImageIcon image = new ImageIcon("bible3.gif");
				JLabel label1 = new JLabel(image);
				pack();
				setVisible(true);
			}

			public static void main(String[] args)
			{
				new Work();
			}



		}



ps the default size isn't showing what I set it up to be its not that important to me now, but I know I'm going to have to fix it in the future.

Reply With Quote
  #2  
Old March 5th, 2013, 06:55 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: Eastern Florida
Posts: 2,951 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 29 m 42 sec
Reputation Power: 345
Quote:
my images aren't showing up

Where are you trying to show any images? What component is supposed to show the image?

Variables defined inside of a method are local to that method. When the method exits, the variable and its value go away. If you want a variable to exist and have a value after a method exists, you need to define the variable outside of any method.

There are 4 different variables defined with the same name in the posted code: label1

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Displaying java image

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap