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

Thread: No images being displayed

  1. #1
    Member
    Join Date
    Dec 2012
    Posts
    31
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default No images being displayed

    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.ButtonGroup;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JRadioButton;
    import javax.swing.JTextArea;
    import javax.swing.border.TitledBorder;
     
    public class ImageViewerFrame2 extends JFrame
    {
     
    	private static final int FRAME_WIDTH = 500;
    	private static final int FRAME_HEIGHT = 400;
     
    	private JRadioButton[] radio = new JRadioButton[6];
    	private ActionListener listener;
    	private JLabel GeneralLocation;
    	private JTextArea PreciseInfo;
    	private JLabel pictureLabel;
    	private String Description;
     
    	public ImageViewerFrame2()
    	{
     
     
     
    		GeneralLocation = new JLabel("Wonders of the world ");
    		add(GeneralLocation, BorderLayout.NORTH);
     
    		PreciseInfo = new JTextArea ("" + Description);
    		PreciseInfo.setRows(5);
    		PreciseInfo.setEditable(false);
     
    		add(PreciseInfo, BorderLayout.SOUTH);
     
     
     
    		pictureLabel = new JLabel("");
    		add(pictureLabel,BorderLayout.CENTER);
     
     
     
    		class ChoiceListener implements ActionListener
    		{ 
     
    			public void actionPerformed(ActionEvent event)
    			{ 
    				setText();
    			}
     
    		}
     
    		listener = new ChoiceListener();
     
    		createControlPanel();
    		setText();
    		setSize(FRAME_WIDTH, FRAME_HEIGHT);
     
    	}
     
     
    	public void createControlPanel()
    	{
     
    		JPanel AreaGroupPanel = createRadioButtons();
     
     
     
    		JPanel controlPanel = new JPanel();
    		controlPanel.add(AreaGroupPanel);
     
     
     
    		add(controlPanel, BorderLayout.WEST);
    	}
     
     
    	public JPanel createRadioButtons()
    	{
     
    		ButtonGroup group = new ButtonGroup();
    		JPanel panel = new JPanel();
    		for(int i = 0; i < radio.length; ++i) {
    			radio[i] = new JRadioButton("Area " + (i+1));
    			radio[i].addActionListener(listener);
    			group.add(radio[i]);
    			panel.add(radio[i]);
     
     
    		}
     
    		panel.setBorder(new TitledBorder("SELECT A BUTTON BELOW"));
     
    		return panel;
    	}
     
     
    	public void setText()
    	{
     
    		String[] imageStr = {"GreatWall.JPG","Taj_Mahal.JPG","MachuPicchu.JPG","ChristRedeemer.JPG","Colosseum.JPG","Petra.JPG"}; 
     
     
    		for(int i = 0; i < radio.length; ++i) {
    			if(radio[0].isSelected()) {
    				String Description = "You have selected Great Wall of China. The Great Wall of China is a series of fortifications\n made of stone, brick, tamped earth, wood, and other materials, generally built along \n an east-to-west line across the historical northern borders of China in part to \n protect the Chinese Empire or its prototypical states against intrusions by various \n nomadic groups or military incursions by various warlike peoples or forces";
    				pictureLabel.setIcon(new ImageIcon("http://www.javaprogrammingforums.com/images/imageStr[0]"));
    				PreciseInfo.setText(Description);}
     
    				else if(radio[1].isSelected()) {
    					String Description = "You have selected Taj Mahal. is a white marble mausoleum located in Agra, Uttar Pradesh, India. \n It was built by Mughal emperor Shah Jahan in memory of his third wife, Mumtaz Mahal. \n The Taj Mahal is widely recognized as the jewel of Muslim art in India and one of the \n universally admired masterpieces of the world's heritage";
    					pictureLabel.setIcon(new ImageIcon("http://www.javaprogrammingforums.com/images/imageStr[1]"));
    					PreciseInfo.setText(Description);
    					}
     
    				else if	(radio[2].isSelected()) {
    				String Description = "You have selected Machu Picchu.  Machu Picchu is located in the Cusco Region of Peru, South America.\n It is situated on a mountain ridge above the Urubamba Valley in Peru, which is 80 \n kilometres (50 mi) northwest of Cusco and through which the Urubamba River flows. \n Most archaeologists believe that Machu Picchu was built as an estate for the Inca emperor\n Pachacuti (1438–1472). Often referred to as the City of the Incas, it is perhaps the most \n familiar icon of Inca civilization";
    				pictureLabel.setIcon(new ImageIcon("http://www.javaprogrammingforums.com/images/imageStr[2]"));
    				PreciseInfo.setText(Description);
    		}
    				else if	(radio[3].isSelected()) {
    					String Description = "You have selected Christ the Redeemer. Chirst the Redeemer is a statue of Jesus Christ in Rio de Janeiro, Brazil; \n considered the largest Art Deco statue in the world and the 5th largest statue of Jesus \n in the world";
    					pictureLabel.setIcon(new ImageIcon("http://www.javaprogrammingforums.com/images/imageStr[3]"));
    					PreciseInfo.setText(Description);
    			}
    				else if	(radio[4].isSelected()) {
    					String Description = "You have selected the Colosseum. The Colosseum is considered one of the greatest \n works of Roman architecture and Roman engineering.";
    					pictureLabel.setIcon(new ImageIcon("http://www.javaprogrammingforums.com/images/imageStr[4]"));
    					PreciseInfo.setText(Description);
    			}
    				else if	(radio[5].isSelected()) {
    					String Description = "You have selected Petra.  is a historical and archaeological city in the Jordanian  \n governorate of Ma'an, that is famous for its rock-cut architecture and water conduit system.";
    					pictureLabel.setIcon(new ImageIcon("http://www.javaprogrammingforums.com/images/imageStr[5]"));
    					PreciseInfo.setText(Description);
    			}
     
     
     
    	}
     
     
     
    	}
    }
    import javax.swing.JFrame;
     
    public class ImageViewer
    {
     
    public static void main(String[] args)
    { 
     
    JFrame frame = new ImageViewerFrame2();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setTitle("Images");
    frame.setVisible(true);
     
    }
     
    }




    Can someone explain why there aren't any images being outputted?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: No images being displayed

    why there aren't any images being outputted?
    The most common reason is that the images are not where the program is looking for them.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Dec 2012
    Posts
    31
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: No images being displayed

    Would I be able to set it to "Desktop/GreatWall.JPG". Would that work if the image is there?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: No images being displayed

    If the Desktop directory is in the current directory when the program executes.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Can't seem to get this image to be displayed!
    By mkrage in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 27th, 2012, 06:07 PM
  2. no image is being displayed.. please help..
    By namita in forum AWT / Java Swing
    Replies: 2
    Last Post: July 23rd, 2012, 11:52 AM
  3. 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
  4. [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
  5. 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