Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Problem with layering Icons
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
goober69




PostPosted: Mon Jun 02, 2008 3:30 pm   Post subject: Problem with layering Icons

Hey guys, quick question. I made this little prog that loads numbers from a text file that coorespond with tiles to display on the screen. The program compiles fine, and the tiles are displayed exactly how I want on the screen (using ImageIcon), but when I try and load an image ontop of them (once again using ImageIcon, the image does not display. Funny thing is when I don't display the tiles, the image is displayed, so I think it's being loaded under the tile images :S Any help is appreciated.
code:

import javax.swing.*;
import java.awt.*;
import java.io.*;
public class MAIN{
    public static void MAIN(){
       
        //LOAD THE TILES
        Graphics mario = new Graphics();
        Image[] TILE = new Image[225];
        int cntr = 0;
        try {
        BufferedReader in = new BufferedReader(new FileReader("1.txt"));
        String record = null;
        for(int i = 0;i<15;i++) {
        String[] temp1 = in.readLine().split("\\s");
        for(int x = 0;x<temp1.length;x++){
            TILE[cntr] = Toolkit.getDefaultToolkit().getImage(temp1[x]+".PNG");
            cntr = cntr + 1;
//             System.out.print(temp1[x]+" ");
        }                                  //BOTH SYSTEM.out LINES ARE FOR DEBUGGING PURPOSES ONLY
//         System.out.println();
        }
        in.close();
        } catch (IOException e) {
        }
       
        //DISPLAY THE TILES
        JFrame M = new JFrame("Title of window");
        M.setLayout(null);
        int TX = 0, TY = 0;
        for(int i = 0;i<225;i++){
            if(TX>448){
                TY=TY+32;
                TX=0;
            }
            M.add(new JLabel(new ImageIcon(TILE[i]))).setBounds(TX,TY,32,32);
            TX = TX + 32;
        }
       
       
        M.setSize(488,514);
        M.setVisible(true);
        M.validate();
       
        //LOAD AND DISPLAY MAIN CHARACTER
        int MX = 34, MY = 34;
        JLabel Mario = new JLabel(new ImageIcon(mario.Mario(0)));      //PROBLEM IS SOMEWHERE AROUND HERE I THINK
        Mario.setBounds(MX,MY,16,16);
        M.add(Mario);
        M.validate();               
    }
}
Sponsor
Sponsor
Sponsor
sponsor
HellblazerX




PostPosted: Mon Jun 02, 2008 4:09 pm   Post subject: Re: Problem with layering Icons

I don't believe you stack JLabels on top of one another, however, you can do it with JLayeredPanes. However, for you program (I'm assuming you're making a Mario game), I would recommend you do your graphics with the paint method rather than with Swing (JLayerPanes were created with the idea of overlapping windows in mind, not animations).
goober69




PostPosted: Tue Jun 03, 2008 8:01 am   Post subject: Re: Problem with layering Icons

alright, i've already looked into the JLayeredPane thing, and when I tried to implement it, none of my images showed up in my window... I'd like to use the Graphics.DrawImage or w.e, but I've read through countless tutorials on it and it confuses the bejesus out of me :S If you could maybe help me out on that I think I could take it from there..
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: