Results 1 to 20 of 20
  1. #1
    MW130 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    317
    Rep Power
    2

    Default How can I put this image from one class into the other?

    I have two classes. One is a game, and the other is a frame that displays an image. They are both on JFrames. I want to put the image onto my class that is a game, and I tried just putting the part that makes the image in the image class, but it will not let me use the JFrame from my other class, saying that it doesn't exist. How do I make them recognize each other? Here is my code

    Game:
    Java Code:
    import java.awt.BorderLayout;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Image;
    import javax.imageio.ImageIO;
    import javax.swing.ImageIcon;
    import javax.swing.JPanel;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Graphics;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.util.Timer;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import java.util.*;
     
        public class myGame extends JComponent {
        Random ar = new Random();
        public int x = ar.nextInt(400);
        Random har = new Random();
        public int y = har.nextInt(400);
        Random r = new Random();
        Random rand = new Random();
        Random newx;
        Random newy;
        int resetTimes = 0;
        int ex = r.nextInt(400);
        int why = rand.nextInt(400);
    
        
        
        public void ResetIt(){
        	if(x <= ex+17.5 && y <= why+17.5 && x >= ex-17.5 && y >= why-17.5){
        	    
        		newx = new Random();
        		newy = new Random();
        		int newex = newx.nextInt(450);
        	    int newwhy = newy.nextInt(450);
        		x = newex;
        		y = newwhy;
        		resetTimes++;
        		repaint();
        		
        	}
        }
        KeyListener kw = new KeyListener(){
    
    		@Override
    		public void keyTyped(KeyEvent e) {
    			// TODO Auto-generated method stub
    			
    		}
    
    		@Override
    		public void keyPressed(KeyEvent e) {
            int k = e.getKeyCode();
            if (k == KeyEvent.VK_W){
    	    y=y-10;
    	    repaint();
    	    ResetIt();
    
            }
            if (k == KeyEvent.VK_S){
            	y = y+10;
            	repaint();
        	    ResetIt();
    
            }
            if(k == KeyEvent.VK_A){
        	    x=x-10;
        	    repaint();
        	    ResetIt();
    
            }
        	if(k == KeyEvent.VK_D) {
        	    x=x+10;
        	    repaint();
        	    ResetIt();
        	            }
        	if(k == KeyEvent.VK_Q) {
        	    x=x-10;
        	    y=y-10;
        	    repaint();
        	    ResetIt();
        	            }
        	if(k == KeyEvent.VK_E) {
        	    x=x+10;
        	    y=y-10;
        	    repaint();
        	    ResetIt();
        	            }
        };
            
    		
    
    		@Override
    		public void keyReleased(KeyEvent e) {
    			// TODO Auto-generated method stub
    			
    		}
        	
        
        };
        myGame() {
            JFrame f = new JFrame("Square Mover 1.0");
            JPanel p = new JPanel();
            p.setLayout(new BorderLayout());
            p.add(this);
            f.add(p);
            f.setSize(500, 500);
            f.setVisible(true);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.addKeyListener(kw);
            p.setBackground(Color.blue);
            
        }
     
        public void paintComponent(Graphics g) {
        	g.setColor(Color.red);
            g.fillRect(x, y, 50, 50);
        	g.setColor(Color.black);
            g.drawRect(ex, why,70,70);
            g.setColor(Color.red);
            g.fillRect(x, y, 50, 50);
            g.setColor(Color.white);
            g.drawString("enter",ex+5,why-10);
            g.setColor(Color.white);
            g.drawString("Score:"+resetTimes,20,20);
            g.drawString("Use WASD to move around", 150, 20);
    		g.drawString("Level "+resetTimes/5, 20, 50);
    		
        }
     
    
        public static void main(String[] args) {
            myGame d = new myGame();
            d.ResetIt();
            DisplayImage l = new DisplayImage();
            l.setUp();
        }
     
    }
    Image:

    Java Code:
    import java.awt.BorderLayout;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    
    
    
    public class DisplayImage extends JPanel {
    	private BufferedImage image;
    	public DisplayImage(){
    		try{
    			image = ImageIO.read(new File("/Users/MW/Downloads/petergriffin.png"));
    		} catch(Exception e){System.out.println("Error");}
    	}
    	public void paintComponent(Graphics g){
    		super.paintComponent(g);
    		g.drawImage(image,0,0,null);
    	}
    	public void setUp(){
    		JFrame f = new JFrame();
    		f.setSize(500,500);
    		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		f.setVisible(true);
    		f.add(this);
    	    setLayout(new BorderLayout());
    }
    	
    
    }

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,501
    Rep Power
    5

    Default Re: How can I put this image from one class into the other?

    Do you really want to have two frames? Besides you can't add a JFrame to another JFrame because you can't add a Window to a Container. So perhaps you just want to have another class that extends JPanel and holds an image which can be added to your game? Then remove the Frame stuff from your DisplayImage class and add an instance of that to your JFrame in your game class. And from looking at your code you may be about to repeat the mistakes you made in the other thread.

    Note: Normally, the frame holds one or more panels. And those panels may hold more panels or components. Extending JPanel or JComponent allows the developer to customize "Widgets" which may be added to their GUI or whatever creation they are making.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    MW130 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    317
    Rep Power
    2

    Default Re: How can I put this image from one class into the other?

    Quote Originally Posted by jim829 View Post
    Do you really want to have two frames? Besides you can't add a JFrame to another JFrame because you can't add a Window to a Container. So perhaps you just want to have another class that extends JPanel and holds an image which can be added to your game? Then remove the Frame stuff from your DisplayImage class and add an instance of that to your JFrame in your game class. And from looking at your code you may be about to repeat the mistakes you made in the other thread.

    Note: Normally, the frame holds one or more panels. And those panels may hold more panels or components. Extending JPanel or JComponent allows the developer to customize "Widgets" which may be added to their GUI or whatever creation they are making.

    Regards,
    Jim
    No, I do not want to have two frames. I just needed to because my picture class won't recognize the frame from my Game class.
    Also, what do you mean by add an instance of that?
    If I remove the frame, then the image won't display because I can't call f.add(this);

  4. #4
    MW130 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    317
    Rep Power
    2

    Default Re: How can I put this image from one class into the other?

    Alright Jim so I did what you said and now when I try to draw the Image within my game class, it cannot recognize it. It doesn't "acknowledge" it from the actual Image class.
    Code now:

    Java Code:
     
    import java.awt.BorderLayout;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    
    
    
    public class DisplayImage extends JPanel {
    	private BufferedImage image;
    	public DisplayImage(){
    		try{
    			image = ImageIO.read(new File("/Users/MWaldman/Downloads/petergriffin.png"));
    		} catch(Exception e){System.out.println("Error");}
    	}
    	
    	
    	
    
    }
    Game:
    Java Code:
    import java.awt.BorderLayout;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Image;
    import javax.imageio.ImageIO;
    import javax.swing.ImageIcon;
    import javax.swing.JPanel;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Graphics;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.util.Timer;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import java.util.*;
     
        public class myGame extends JComponent {
        Random ar = new Random();
        public int x = ar.nextInt(400);
        Random har = new Random();
        public int y = har.nextInt(400);
        Random r = new Random();
        Random rand = new Random();
        Random newx;
        Random newy;
        int resetTimes = 0;
        int ex = r.nextInt(400);
        int why = rand.nextInt(400);
    
        
        
        public void ResetIt(){
        	if(x <= ex+17.5 && y <= why+17.5 && x >= ex-17.5 && y >= why-17.5){
        	    
        		newx = new Random();
        		newy = new Random();
        		int newex = newx.nextInt(450);
        	    int newwhy = newy.nextInt(450);
        		x = newex;
        		y = newwhy;
        		resetTimes++;
        		repaint();
        		
        	}
        }
        KeyListener kw = new KeyListener(){
    
    		@Override
    		public void keyTyped(KeyEvent e) {
    			// TODO Auto-generated method stub
    			
    		}
    
    		@Override
    		public void keyPressed(KeyEvent e) {
            int k = e.getKeyCode();
            if (k == KeyEvent.VK_W){
    	    y=y-10;
    	    repaint();
    	    ResetIt();
    
            }
            if (k == KeyEvent.VK_S){
            	y = y+10;
            	repaint();
        	    ResetIt();
    
            }
            if(k == KeyEvent.VK_A){
        	    x=x-10;
        	    repaint();
        	    ResetIt();
    
            }
        	if(k == KeyEvent.VK_D) {
        	    x=x+10;
        	    repaint();
        	    ResetIt();
        	            }
        	if(k == KeyEvent.VK_Q) {
        	    x=x-10;
        	    y=y-10;
        	    repaint();
        	    ResetIt();
        	            }
        	if(k == KeyEvent.VK_E) {
        	    x=x+10;
        	    y=y-10;
        	    repaint();
        	    ResetIt();
        	            }
        };
            
    		
    
    		@Override
    		public void keyReleased(KeyEvent e) {
    			// TODO Auto-generated method stub
    			
    		}
        	
        
        };
        myGame() {
            JFrame f = new JFrame("Square Mover 1.0");
            JPanel p = new JPanel();
            p.setLayout(new BorderLayout());
            p.add(this);
    		f.add(this);
            f.add(p);
            f.setSize(500, 500);
            f.setVisible(true);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.addKeyListener(kw);
            p.setBackground(Color.blue);
            
        }
     
        public void paintComponent(Graphics g) {
        	g.setColor(Color.red);
            g.fillRect(x, y, 50, 50);
        	g.setColor(Color.black);
            g.drawRect(ex, why,70,70);
            g.setColor(Color.red);
            g.fillRect(x, y, 50, 50);
            g.setColor(Color.white);
            g.drawString("enter",ex+5,why-10);
            g.setColor(Color.white);
            g.drawString("Score:"+resetTimes,20,20);
            g.drawString("Use WASD to move around", 150, 20);
    		g.drawString("Level "+resetTimes/5, 20, 50);
    		g.drawImage(image,50,50,null);
    		
        }
     
    
        public static void main(String[] args) {
            myGame d = new myGame();
            d.ResetIt();
            DisplayImage l = new DisplayImage();
        }
     
    }

  5. #5
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,501
    Rep Power
    5

    Default Re: How can I put this image from one class into the other?

    You deleted way too much of your DisplayImage class. I deleted your setup method as you don't need it. I deleted the layout as you don't need it and put the sizing in the constructor.

    Java Code:
    public class DisplayImage extends JPanel {
        private BufferedImage image;
        public DisplayImage(){
            try{
                image = ImageIO.read(new File("/Users/MW/Downloads/petergriffin.png"));
            } catch(Exception e){System.out.println("Error");
            setPreferredSize(new Dimension(500,500));
        }
        public void paintComponent(Graphics g){
            if (image != null) { // added to prevent null pointer exception
               super.paintComponent(g);
               g.drawImage(image,0,0,null);
            }
        }
    }
    Now you can add an instance of this class to your game class. When the game class does its repainting the paintComponent method of each of its components will be called. And I suggest you look at the tutorials in my signature and go thru them from the beginning. There are lots of things to learn which would go into making a game.

    Regards,
    Jim
    Last edited by jim829; 01-17-2014 at 03:09 AM.
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  6. #6
    MW130 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    317
    Rep Power
    2

    Default Re: How can I put this image from one class into the other?

    Hey Jim,

    So I fixed the code and now I am receiving no errors, but the image did not show up. I know it is reading the file path correctly because the exception handler isn't being called but now I'm confused as to why the image isn't appearing on to my game screen.

    Code now

    Image class:

    Java Code:
     import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    
    public class DisplayImage extends JPanel {
        private BufferedImage image;
        public DisplayImage(){
            try{
                image = ImageIO.read(new File("/Users/MWaldman/Downloads/petergriffin.png"));
            } catch(Exception e){System.out.println("Error");
            setPreferredSize(new Dimension(500,500));
        }
        }
        public void paintComponent(Graphics g){
            if (image != null) { // added to prevent null pointer exception
               super.paintComponent(g);
               g.drawImage(image,0,0,null);
            }
        }
    }
    Game class

    Java Code:
     import java.awt.BorderLayout;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Image;
    import javax.imageio.ImageIO;
    import javax.swing.ImageIcon;
    import javax.swing.JPanel;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Graphics;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.util.Timer;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import java.util.*;
    
    public class myGame extends JComponent {
    	Random ar = new Random();
    	public int x = ar.nextInt(400);
    	Random har = new Random();
    	public int y = har.nextInt(400);
    	Random r = new Random();
    	Random rand = new Random();
    	Random newx;
    	Random newy;
    	int resetTimes = 0;
    	int ex = r.nextInt(400);
    	int why = rand.nextInt(400);
    
    	public void ResetIt() {
    		if (x <= ex + 17.5 && y <= why + 17.5 && x >= ex - 17.5
    				&& y >= why - 17.5) {
    
    			newx = new Random();
    			newy = new Random();
    			int newex = newx.nextInt(450);
    			int newwhy = newy.nextInt(450);
    			x = newex;
    			y = newwhy;
    			resetTimes++;
    			repaint();
    		}
    
    	}
    
    	KeyListener kw = new KeyListener() {
    
    		@Override
    		public void keyTyped(KeyEvent e) {
    		}
    
    		@Override
    		public void keyPressed(KeyEvent e) {
    			int k = e.getKeyCode();
    			if (k == KeyEvent.VK_W) {
    				y = y - 10;
    				repaint();
    				ResetIt();
    			}
    			if (k == KeyEvent.VK_S) {
    				y = y + 10;
    				repaint();
    				ResetIt();
    			}
    			if (k == KeyEvent.VK_A) {
    				x = x - 10;
    				repaint();
    				ResetIt();
    			}
    
    			if (k == KeyEvent.VK_D) {
    				x = x + 10;
    				repaint();
    				ResetIt();
    			}
    
    			if (k == KeyEvent.VK_Q) {
    				x = x - 10;
    				y = y - 10;
    				repaint();
    				ResetIt();
    			}
    
    			if (k == KeyEvent.VK_E) {
    				x = x + 10;
    				y = y - 10;
    				repaint();
    				ResetIt();
    			}
    
    		};
    
    		@Override
    		public void keyReleased(KeyEvent e) {
    			// TODO Auto-generate
    
    		}
    
    	};
    
    	myGame() {
    		JFrame f = new JFrame("Square Mover 1.0");
    		JPanel p = new JPanel();
    		p.setLayout(new BorderLayout());
    		p.add(this);
    		f.add(p);
    		f.setSize(500, 500);
    		f.setVisible(true);
    		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		f.addKeyListener(kw);
    		p.setBackground(Color.blue);
    
    	}
    
    	public void paintComponent(Graphics g) {
    		g.setColor(Color.red);
    		g.fillRect(x, y, 50, 50);
    		g.setColor(Color.black);
    		g.drawRect(ex, why, 70, 70);
    		g.setColor(Color.red);
    		g.fillRect(x, y, 50, 50);
    		g.setColor(Color.white);
    		g.drawString("enter", ex + 5, why - 10);
    		g.setColor(Color.white);
    		g.drawString("Score:" + resetTimes, 20, 20);
    		g.drawString("Use WASD to move around", 150, 20);
    		g.drawString("Level " + resetTimes / 5, 20, 50);
    	}
    
    	public static void main(String[] args) {
            new DisplayImage();
    		myGame d = new myGame();
    		d.ResetIt();
    		DisplayImage l = new DisplayImage();
    	}
    
    }
    Thanks for your help.

  7. #7
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,501
    Rep Power
    5

    Default Re: How can I put this image from one class into the other?

    Did you understand what I said when I said, "Now you can add an instance of this class to your game class?" Just instantiating your DisplayClass is not sufficient. You must add the instance to your game class (in its Frame). And please, don't take this personally because you have potential. But you are trying to do too much with your limited knowledge of Java and painting and events, etc. You still need to read the tutorials and get a book and start slowly. Experiment with the various capabilities before you put them all together. Otherwise, I am afraid you will go down a path of frustration.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  8. #8
    MW130 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    317
    Rep Power
    2

    Default Re: How can I put this image from one class into the other?

    Ah I know I need to get the basics down but I have read various books and I find that I learn better when I take on challenges, and this is quite a challenge :)
    That is just my learning style though. I will look through more. For the time, being I did now add the instance to my JFrame, but instead of just being another part of my game, the picture overtakes the whole screen. You can't see any part of the game. (I know the game is behind) I just don't know why the image is completely covering the game when it should be added onto it, since it is transparent in the background. Do you have any clue as to why it's happening?
    DisplayImage code has not changed.
    I added an "I" instance of the image class to my JFrame. I also tried adding it to a panel. Either way, it blocks the whole game..
    Here is the game class code.
    Java Code:
     import java.awt.BorderLayout;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Image;
    import javax.imageio.ImageIO;
    import javax.swing.ImageIcon;
    import javax.swing.JPanel;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Graphics;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.util.Timer;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import java.util.*;
    
    public class myGame extends JComponent {
    	Random ar = new Random();
    	public int x = ar.nextInt(400);
    	Random har = new Random();
    	public int y = har.nextInt(400);
    	Random r = new Random();
    	Random rand = new Random();
    	Random newx;
    	Random newy;
    	int resetTimes = 0;
    	int ex = r.nextInt(400);
    	int why = rand.nextInt(400);
    
    	public void ResetIt() {
    		if (x <= ex + 17.5 && y <= why + 17.5 && x >= ex - 17.5
    				&& y >= why - 17.5) {
    
    			newx = new Random();
    			newy = new Random();
    			int newex = newx.nextInt(450);
    			int newwhy = newy.nextInt(450);
    			x = newex;
    			y = newwhy;
    			resetTimes++;
    			repaint();
    		}
    	}
    
    	KeyListener kw = new KeyListener() {
    
    		@Override
    		public void keyTyped(KeyEvent e) {
    		}
    
    		@Override
    		public void keyPressed(KeyEvent e) {
    			int k = e.getKeyCode();
    			if (k == KeyEvent.VK_W) {
    				y = y - 10;
    				repaint();
    				ResetIt();
    			}
    			if (k == KeyEvent.VK_S) {
    				y = y + 10;
    				repaint();
    				ResetIt();
    			}
    			if (k == KeyEvent.VK_A) {
    				x = x - 10;
    				repaint();
    				ResetIt();
    			}
    
    			if (k == KeyEvent.VK_D) {
    				x = x + 10;
    				repaint();
    				ResetIt();
    			}
    
    			if (k == KeyEvent.VK_Q) {
    				x = x - 10;
    				y = y - 10;
    				repaint();
    				ResetIt();
    			}
    
    			if (k == KeyEvent.VK_E) {
    				x = x + 10;
    				y = y - 10;
    				repaint();
    				ResetIt();
    			}
    
    		};
    
    		@Override
    		public void keyReleased(KeyEvent e) {
    			// TODO Auto-generate
    
    		}
    
    	};
    
    	myGame() {
    		DisplayImage I = new DisplayImage();
    		JFrame f = new JFrame("Square Mover 1.0");
    		JPanel p = new JPanel();
    		p.setLayout(new BorderLayout());
    		p.add(this);
    		f.add(p);
    		p.add(I);
    		f.setSize(500, 500);
    		f.setVisible(true);
    		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		f.addKeyListener(kw);
    		p.setBackground(Color.blue);
    
    	}
    
    	public void paintComponent(Graphics g) {
    		g.setColor(Color.red);
    		g.fillRect(x, y, 50, 50);
    		g.setColor(Color.black);
    		g.drawRect(ex, why, 70, 70);
    		g.setColor(Color.red);
    		g.fillRect(x, y, 50, 50);
    		g.setColor(Color.white);
    		g.drawString("enter", ex + 5, why - 10);
    		g.setColor(Color.white);
    		g.drawString("Score:" + resetTimes, 20, 20);
    		g.drawString("Use WASD to move around", 150, 20);
    		g.drawString("Level " + resetTimes / 5, 20, 50);
    	}
    
    	public static void main(String[] args) {
            new DisplayImage();
    		myGame d = new myGame();
    		d.ResetIt();
    		DisplayImage l = new DisplayImage();
    	}
    
    }

  9. #9
    Daryn is offline Senior Member
    Join Date
    Oct 2012
    Posts
    176
    Rep Power
    2

    Default Re: How can I put this image from one class into the other?

    You just never added l to the jframe
    With the right know how, anything is possible

  10. #10
    MW130 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    317
    Rep Power
    2

    Default Re: How can I put this image from one class into the other?

    Quote Originally Posted by Daryn View Post
    You just never added l to the jframe
    I did. I put p.add(I);
    but I had also tried
    Java Code:
    f.add(I);
    but it
    doesn't change the problem. I had tried it before, doesn't matter if added to panel or frame.

  11. #11
    Daryn is offline Senior Member
    Join Date
    Oct 2012
    Posts
    176
    Rep Power
    2

    Default Re: How can I put this image from one class into the other?

    Alright Ill take a better look in a bit. Why do you have p.add(this) and did you get a chance to see the the post in the other thread about images in swing?
    With the right know how, anything is possible

  12. #12
    MW130 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    317
    Rep Power
    2

    Default Re: How can I put this image from one class into the other?

    No idea why I had that in there. Deleted. Will take a look now at your code. Really appreciate your help.

    But deleting that changed nothing
    Last edited by MW130; 01-18-2014 at 07:10 AM.

  13. #13
    MW130 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    317
    Rep Power
    2

    Default Re: How can I put this image from one class into the other?

    I tried resizing it, but I do not think it is a resize issue.

  14. #14
    Daryn is offline Senior Member
    Join Date
    Oct 2012
    Posts
    176
    Rep Power
    2

    Default Re: How can I put this image from one class into the other?

    Is it making the background the color you want
    With the right know how, anything is possible

  15. #15
    MW130 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    317
    Rep Power
    2

    Default Re: How can I put this image from one class into the other?

    Well, before, when I had the game class, yes. The background was blue, and the game worked fine. When I added the small image class, I believe it is just sitting atop all of the game, so maybe the game is behind the image. But the image is mostly transparent. Short answer; yes, for the game (when not with the image class) but for the Current code, No, because the image is covering everything so no.

  16. #16
    Daryn is offline Senior Member
    Join Date
    Oct 2012
    Posts
    176
    Rep Power
    2

    Default Re: How can I put this image from one class into the other?

    Okay cause I was gonna say maybe the background covers the top. Also just in case your interested I wrote some methods for making 2d games with images like your doing. I gotta package the images into the example file and then it will be on my website to download along with a tutorial.
    With the right know how, anything is possible

  17. #17
    MW130 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    317
    Rep Power
    2

    Default Re: How can I put this image from one class into the other?

    Quote Originally Posted by Daryn View Post
    Okay cause I was gonna say maybe the background covers the top. Also just in case your interested I wrote some methods for making 2d games with images like your doing. I gotta package the images into the example file and then it will be on my website to download along with a tutorial.
    Ok. But do you know how I can just make the image display with the game instead of cover it?

  18. #18
    Daryn is offline Senior Member
    Join Date
    Oct 2012
    Posts
    176
    Rep Power
    2

    Default Re: How can I put this image from one class into the other?

    Im sorry Im not sure I don't have much experience with using awt to put my images on and also with using the image reader. I always just use image Icons
    With the right know how, anything is possible

  19. #19
    MW130 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    317
    Rep Power
    2

    Default Re: How can I put this image from one class into the other?

    Quote Originally Posted by Daryn View Post
    Im sorry Im not sure I don't have much experience with using awt to put my images on and also with using the image reader. I always just use image Icons
    How would I do it with imageicons?

  20. #20
    Daryn is offline Senior Member
    Join Date
    Oct 2012
    Posts
    176
    Rep Power
    2

    Default Re: How can I put this image from one class into the other?

    Did you read my other post in you other thread
    With the right know how, anything is possible

Similar Threads

  1. Replies: 3
    Last Post: 12-08-2013, 09:28 PM
  2. Image Observer class
    By RTP_123 in forum New To Java
    Replies: 3
    Last Post: 06-10-2012, 05:13 AM
  3. Class to store Image+Text
    By Gudradain in forum New To Java
    Replies: 2
    Last Post: 11-23-2008, 08:32 AM
  4. Image class (getRGB)
    By shaungoater in forum New To Java
    Replies: 1
    Last Post: 03-07-2008, 09:47 PM
  5. Replies: 0
    Last Post: 01-08-2008, 05:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •