Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2010
    Posts
    47
    Rep Power
    0

    Question Graphics issue, pic won't show up.

    Hi.
    Making a menu for my game, and then i've made a picture with instructions to be shown in a new JFrame, next to the menus JFrame. But the image won't show up in my new JFrame. All the code:
    PHP Code:
    import javax.swing.*;
    
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    
    public class Menu extends JFrame implements ActionListener{
    
    	private ImageIcon image;
    	private JButton start;
    	
    	public Menu(){
    		super("Main Menu");
    		setLayout(null);
    		start = new JButton("Start");
    		start.setBounds(0, 60, 195, 30);
    		setVisible(true);
    		setResizable(false);
    		setSize(200, 250);
    		setLocation(650, 250);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		start.addActionListener(this);
    		add(start);
    		
    	}
    	
    	public void actionPerformed(ActionEvent e) {
    		if(e.getSource() == start){
    		    
    			new Rules();
    		}
    		
    	}
    
    	public class Rules extends JPanel implements ActionListener{
    		
    		public Rules(){
    			JFrame rules = new JFrame("How to");
    			rules.setLayout(null);
    			rules.setVisible(true);
    			rules.setResizable(false);
    			rules.setSize(400, 250);
    			rules.setLocation(850, 250);
    			rules.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		}
    		
    		public void paintComponent(Graphics g){
    			super.paintComponent(g);
    			image = new ImageIcon("imgs/Ibz.png");
    			image.paintIcon(this, g, 0, 0);
    			
    			Graphics2D g2 = (Graphics2D) g;
    		}
    		
    		@Override
    		public void actionPerformed(ActionEvent arg0) {
    			// TODO Auto-generated method stub
    			
    		}
    		
    	}
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

    Default

    Don't perform file I/O or business logic in a painting method override. Painting methods are strictly for painting.

    Load the image to an instance field in the constructor, and paint it in the paintComponent override. Also, don't needlessly construct an ImageIcon -- you can load an Image using ImageIO#read(...)

    db

Similar Threads

  1. Cross-Browser Issue with show/hide divs
    By jmchaffie in forum New To Java
    Replies: 3
    Last Post: 03-10-2011, 10:41 AM
  2. Graphics wont show up(paintComponent)
    By TheBreadCat in forum New To Java
    Replies: 3
    Last Post: 02-13-2011, 07:00 PM
  3. Drawing a graphics onto another Graphics ?
    By Ziden in forum Java Applets
    Replies: 0
    Last Post: 01-08-2011, 08:30 PM
  4. Replies: 3
    Last Post: 05-27-2010, 11:54 AM
  5. netbeans 6.0 not show commpunent or show blank page
    By fahimaamir in forum NetBeans
    Replies: 1
    Last Post: 01-26-2008, 07:20 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
  •