java中设置位置的方法setLocation(x,y)不管用,请高手指教!设置按钮位置不论x,y如何改变按钮始终置顶居中
publicclassGameextendsJFrame{publicGame(Stringtxt){super();setSize(500,400);setLocati...
public class Game extends JFrame{
public Game(String txt){
super();
setSize(500,400);
setLocationRelativeTo(null);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JPanel jp=new JPanel();
JButton jb=new JButton(txt);
jb.setLocation(200,100);
jp.add(jb);
setContentPane(jp);
setVisible(true);
} 展开
public Game(String txt){
super();
setSize(500,400);
setLocationRelativeTo(null);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JPanel jp=new JPanel();
JButton jb=new JButton(txt);
jb.setLocation(200,100);
jp.add(jb);
setContentPane(jp);
setVisible(true);
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询