buttonname.setBounds(xlocation,ylocation, width, height);对我不起作用?


 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);

}}

为什么这行不通?此外,我是Java和eclipse的新手,任何帮助将不胜感激。提前感谢!

setBounds null布局中工作。添加此行。.

frame.setLayout(null);

相关内容

  • 没有找到相关文章

最新更新