0
 package com.tests;

 import javax.swing.ImageIcon;
 import javax.swing.JButton;
  import javax.swing.JFrame;

 public class LevelUp {

public static void main(String[] args)  {
    // TODO Auto-generated method stub
     final int width = 1000;
     final int height = width / 16*9;

 //buttons      
 JButton button = new JButton("Yus");

 //location
 button.setBounds(0, 0, 50, 50);

   JFrame frame = new JFrame("Level");
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setResizable(false);
   frame.setVisible(true);
   frame.setIconImage(new ImageIcon("Biblioteker\\Billeder\\giggle.jpeg").getImage());
   frame.setSize(width, height);
   frame.setLocationRelativeTo(null);

   //add to jframe
   frame.add(button);

} }

Why wont this work? Also I am new to java and eclipse in general, any help would be appreciated. Thanks in advance!

ShuLei
  • 11
  • 3

1 Answers1

0

setBounds works in null layout. Add this line..

frame.setLayout(null);
subash
  • 3,116
  • 3
  • 18
  • 22
  • Wow, I had no idea that it was so simple, looked it up several times, but couldn't see why that would work, I dont understand much of this yet, thanks a lot! – ShuLei Dec 06 '13 at 10:59
  • Instead of making a new question thread, I have another problem, that I hope you could answer. When I use the debug instead of play, I should be able to edit the script live, right? (ex: edit the x and y position of the button and it would change live) It worked once for me, but now it doesn't. I looked it up and they said something about skipping break points, but that option is not toggled. Do you have any idea how to fix this? Thanks in advance, again. – ShuLei Dec 06 '13 at 11:03
  • What is your question? Change the location of button dynamically? is this? – subash Dec 06 '13 at 11:09
  • Yeah like having the game running in the side and then changing stuff while its running. Like Unity 3D, you could click play and change ex. a position of a button or add one and it will pop up while game is running – ShuLei Dec 06 '13 at 11:13
  • JOptionPane.showMessageDialog() What is your thinking about it? – subash Dec 06 '13 at 11:18
  • Nono, it's not a code, it's build in in Eclipse. Right to the left of the Run 'scriptname' button, there is a Debug 'scriptname' button. When you click the Debug button, you should be able to change or add in your script live, right? – ShuLei Dec 06 '13 at 11:22