Web Analytics Made Easy -
StatCounter Moving a JLabel in a JFrame - CodingForum

Announcement

Collapse
No announcement yet.

Moving a JLabel in a JFrame

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Moving a JLabel in a JFrame

    I am attempting to make a game. I want to add a JLabel to the top right corner of the JFrame, or really just anywhere but the middle. This is almost exactly my code.



    public class World extends JFrame{
    public JLabel player = new JLabel(ImageIcon("image.jpg"));
    public World(){
    JFrame screen = new JFrame();
    screen.getContentPane().setBackground(new Color(0,105,0));
    show(screen);
    }

    public void show(JFrame screen){
    screen.add(player);
    screen.setSize(1300, 700);
    screen.setVisible(true);
    player.setLocation(300, 200); <-----THIS DOESNT WORK!
    repaint();
    }
    }


    Help would be awesome.

    Also, at first i had 2 images so my toon could switch directions, but those 2 different images were different sizes. If i swapped one out for another, the label would spawn in the middle of the jframe instead of the previous location. All i did was setIcon(); But once i made them the same size it worked fine. Any way i can make it work with different sized images?

  • #2
    Solved.

    Comment

    Working...
    X