Page 3 of 5 FirstFirst 12345 LastLast
Results 41 to 60 of 83
Like Tree1Likes

Thread: Images and stuff

  1. #41
    Coold0wn is offline Member
    Join Date
    Aug 2011
    Posts
    71
    Rep Power
    0

    Default

    i just dont like them at all.. too confusing..
    and i dont have problems with JFrames.. its like the most easy thing :D
    my whole program works without Panels or Labels until now.

    i have set up my whole program by the link you just gave me :P
    but it somehow didnt work when i tried to get images in there.. only buttons..

    okay ill try the rest with labels now.. its a whole new frame what im doing now.

    thank you guys

  2. #42
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default

    If you give us some code examples, I might be able to help you further. You could also specify what is so confusing. You are still adding stuff to a container but it is not a JPanel nor a JFrame that you are writing to. I am not too sure which one it is because you have not given me any of the code you are currently working on. Give me some code and I can see what I can do.

  3. #43
    Coold0wn is offline Member
    Join Date
    Aug 2011
    Posts
    71
    Rep Power
    0

    Default

    wow guys... ive been coding for a while now , and nearly everything seems to work! thx :)
    but:
    1) i dont know how to do manual positioning with Panels, and Labels.. (there are spaces between the labels, or the labels are not fully filled idk. , if i had a second layer, it will be south of the first one, not on top of it)
    2) something else, but i might have just found a solution for that.. ill try

    edit: okay , the second problem solves itself, when i have solved the first one..

    this is my layer code:

    Java Code:
    import java.awt.Dimension;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import java.util.ArrayList; 
    import javax.swing.*;
    
    public class Layer
    {
    private JFrame MainFrame;
    private int x = 40;
    private int y = 20;
    private ArrayList<Tile> tiles;
    private ArrayList<JLabel> labels;
    private ArrayList<ImageIcon> imageIcons;
    private JPanel Panel;
    private ImageIcon[] tileset;
    
        public Layer(Editor e, JFrame Frame, ImageIcon[] i, JPanel p)
        {
            MainFrame = Frame;
            Panel = p;
            tileset = i;
            tiles = new ArrayList<Tile>();
            labels = new ArrayList<JLabel>();
            imageIcons = new ArrayList<ImageIcon>();
            imageIcons.add(tileset[1]);
            for(int z = 0; z < x*y; z++)
            {
                tiles.add(new Tile());
                imageIcons.add(tileset[36]);
                labels.add(new JLabel(imageIcons.get(z)));
                Panel.add(labels.get(z));
            }
            imageIcons.remove(800);
            MainFrame.add(Panel);
            
        }
        
        public void delete()
        {
        }
        
        public void tileSetzen(int t, int id)
        {
            int TileNummer = t;
            //TileNummer = (((xWert - (xWert % x))/x)+((yWert - (yWert % y)) * y)); 
            tiles.get(TileNummer).setImageNummer(id);
            redrawImage(TileNummer);
        }
        
        public void redrawImage(int nr)
        {
            MainFrame.remove(Panel);
            Panel.remove(labels.get(nr));
            labels.remove(nr);
            imageIcons.remove(nr);
            //
            imageIcons.add(nr, tileset[tiles.get(nr).gibImageNummer()]);
            labels.add(nr, new JLabel(imageIcons.get(nr)));
            Panel.add(labels.get(nr));
            MainFrame.add(Panel);
            
        }
    }
    Tile is a class which has a integer parameter : ImageNummer ( = ImageNumber)
    ImageIcon i will be my big 512x512 picture split into image Icons and put them into an array.
    Panel p = Panel that contains all the layers
    Last edited by Coold0wn; 08-12-2011 at 06:45 PM.

  4. #44
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default

    Are you using the Absolute Positioning layout?

  5. #45
    Coold0wn is offline Member
    Join Date
    Aug 2011
    Posts
    71
    Rep Power
    0

    Default

    ive set the JFrame that i give the layer to
    DrawFrame.getContentPane().setLayout(null);
    now.
    this makes it be absolute positioning, doesnt it?
    well it works with the other frame.. so i guess yes :P

  6. #46
    Coold0wn is offline Member
    Join Date
    Aug 2011
    Posts
    71
    Rep Power
    0

    Default

    reworked the layer class... but now i got no images in the layer..
    there might be something wrong with the redrawImage(int imageNr) method...
    Java Code:
    import java.awt.Dimension;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import java.util.ArrayList; 
    import javax.swing.*;
    
    public class Layer
    {
    private JFrame MainFrame;
    private int x = 40;
    private int y = 20;
    private ArrayList<Tile> tiles;
    private ArrayList<JLabel> labels;
    private ArrayList<ImageIcon> imageIcons;
    private JPanel Panel;
    private ImageIcon[] tileset;
    
        public Layer(Editor e, JFrame Frame, ImageIcon[] i, JPanel p)
        {
            MainFrame = Frame;
            Panel = p;
            tileset = i;
            tiles = new ArrayList<Tile>();
            labels = new ArrayList<JLabel>();
            imageIcons = new ArrayList<ImageIcon>();
            for(int z = 0; z < x*y; z++)
            {
                tiles.add(new Tile());
                imageIcons.add(tileset[1]);
                labels.add(new JLabel(imageIcons.get(z)));
                Panel.add(labels.get(z));
            }
            for(int a = 0; a < x*y; a++)
            {
                redrawImage(a);
            }
            MainFrame.add(Panel);
            labels.get(0).setBounds(32,32,32,32);
            MainFrame.add(Panel);
            
        }
        
        public void delete()
        {
        }
        
        public void tileSetzen(int tilenr, int id)
        {
            int TileNummer = tilenr;
            //TileNummer = (((xWert - (xWert % x))/x)+((yWert - (yWert % y)) * y)); 
            tiles.get(TileNummer).setImageNummer(id);
            redrawImage(TileNummer);
        }
        
        public void redrawImage(int nr)
        {
            MainFrame.remove(Panel);
            Panel.remove(labels.get(nr));
            labels.remove(nr);
            imageIcons.remove(nr);
            //
            imageIcons.add(nr, tileset[tiles.get(nr).gibImageNummer()]);
            labels.add(nr, new JLabel(imageIcons.get(nr)));
            labels.get(nr).setBounds(32*(nr % x), 32*(nr-( nr % y))/y, 32, 32);
            Panel.add(labels.get(nr));
            MainFrame.add(Panel);
            
        }
    }

    i dont know if you can do this like that...
    the sence of that method is, to change the picture in the label.

  7. #47
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default

    My only problem is the fact that I do not use ArrayList very often so I may need to relearn how to use it. Is anything coming up? And you should start by making sure that the JLabels come up first with some text inside of them and then try to put some pictures in them.

  8. #48
    Coold0wn is offline Member
    Join Date
    Aug 2011
    Posts
    71
    Rep Power
    0

    Default

    1: why should i do that? is there a bigger reason?
    2: when i first run the program, everything is fine, and he draws the layer, but when i try to add another one... nothing happens on the screen.
    i can see that he added one to the array list, with all the arraylists and stuff, but he didnt put it to the JFrame..
    do you know why this could be?

    the code now:
    Java Code:
    import java.awt.Dimension;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import java.util.ArrayList; 
    import javax.swing.*;
    
    public class Layer
    {
    private JFrame MainFrame;
    private int x = 40;
    private int y = 20;
    private ArrayList<Tile> tiles;
    private ArrayList<JLabel> labels;
    private ArrayList<ImageIcon> imageIcons;
    //private JPanel Panel;
    private ImageIcon[] tileset;
    
        public Layer(Editor e, JFrame Frame, ImageIcon[] i, JPanel p)
        {
            MainFrame = Frame;
            //Panel = p;
            tileset = i;
            tiles = new ArrayList<Tile>();
            labels = new ArrayList<JLabel>();
            imageIcons = new ArrayList<ImageIcon>();
            for(int z = 0; z < x*y; z++)
            {
                tiles.add(new Tile());
                imageIcons.add(tileset[1]);
                labels.add(new JLabel(imageIcons.get(z)));
                //Panel.add(labels.get(z));
                MainFrame.getContentPane().add(labels.get(z));
            }
            for(int a = 0; a < x*y; a++)
            {
                tileSetzen(a, 16);
            }        
        }
        
        public void delete()
        {
        }
        
        public void tileSetzen(int tilenr, int id)
        {
            int TileNummer = tilenr;
            //TileNummer = (((xWert - (xWert % x))/x)+((yWert - (yWert % y)) * y)); 
            tiles.get(TileNummer).setImageNummer(id);
            redrawImage(TileNummer);
        }
        
        public void redrawImage(int nr)
        {
            MainFrame.getContentPane().remove(labels.get(nr));
            //MainFrame.remove(Panel);
            //Panel.remove(labels.get(nr));
            labels.remove(nr);
            imageIcons.remove(nr);
            //
            imageIcons.add(nr, tileset[tiles.get(nr).gibImageNummer()]);
            labels.add(nr, new JLabel(imageIcons.get(nr)));
            labels.get(nr).setBounds(32*(nr % x), 16*(nr-( nr % x))/y, 32, 32);
            //Panel.add(labels.get(nr));
            MainFrame.getContentPane().add(labels.get(nr));
            
        }
    }
    Last edited by Coold0wn; 08-12-2011 at 09:07 PM.

  9. #49
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default

    How are you adding the other layers?
    Using just text verifies that fact that they are all there. Also, put up more println() statements to verify that everything is going right. Your code seems fine, but I am not to sure. I need to know how you are implementing this.

  10. #50
    Coold0wn is offline Member
    Join Date
    Aug 2011
    Posts
    71
    Rep Power
    0

    Default

    cant find a solution..
    it just doesnt want to draw the other tiles but the first one...
    you know why that could be?

    (array.get(10) = list[10] => returns the 10 array field
    array.add("hallo") => adds a String "hallo" at the last array field
    array.add(2, "hallo") => adds a String "hallo" at the second array field
    array.remove(x) => removes number x)

  11. #51
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default

    This still does not give me enough information. Show me the source of the program you are using to acutally add all of these components into you JFrame or JPanel.

  12. #52
    Coold0wn is offline Member
    Join Date
    Aug 2011
    Posts
    71
    Rep Power
    0

    Default

    ... well... my program is kind of big..
    if i put everything here.. you could scroll for some minutes :P

    the problem is, that when i open the programm the first time, there is no problem for the layer to be drawn,
    but if i want to add another one.. it doesnt work anymore

    it doesnt work neither when i just dont let the first layer get drawn and then the now first one ..
    i dont know what this could be..

    do you have teamviewer or sth? then you could connect and see...

  13. #53
    Coold0wn is offline Member
    Join Date
    Aug 2011
    Posts
    71
    Rep Power
    0

    Default

    okay i just found my mistake..
    some how my imageIcons get converted into BufferedImages...

  14. #54
    Coold0wn is offline Member
    Join Date
    Aug 2011
    Posts
    71
    Rep Power
    0

    Default

    okay that was a fail... my image icons are imageicons wiht a reference to a buffered image...
    i missunderstood that
    .. so im back to 0

  15. #55
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    If you were to write a small simple program (SSCCE) that uses/shows some of the techniques you are having problems with and posted it here, then you could get some help

  16. #56
    Coold0wn is offline Member
    Join Date
    Aug 2011
    Posts
    71
    Rep Power
    0

    Default

    hm .. you mean a program that does the same like this, but leaves all unneeded (for the bugsearch) stuff away?

  17. #57
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    Yes. Only include the classes and methods you are having problems with, but with enough to give a show for what you are trying to do.

  18. #58
    Coold0wn is offline Member
    Join Date
    Aug 2011
    Posts
    71
    Rep Power
    0

    Default

    okay .. done it, i will comment it , so you know what is happening
    or shal i just tell you here?

  19. #59
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    Post it here.

  20. #60
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

Page 3 of 5 FirstFirst 12345 LastLast

Similar Threads

  1. where the stuff goes?
    By Izabela in forum New To Java
    Replies: 16
    Last Post: 08-31-2010, 02:00 PM
  2. Replies: 6
    Last Post: 05-26-2010, 12:17 AM
  3. Table, beginner stuff
    By drwk in forum New To Java
    Replies: 1
    Last Post: 01-24-2010, 07:19 PM
  4. Simple Stuff 0.1
    By Java Tip in forum Java Software
    Replies: 0
    Last Post: 07-19-2008, 04:27 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
  •