【发布时间】:2015-05-07 16:46:07
【问题描述】:
我正在尝试将JFrame 返回到另一种方法中,以便我可以从中添加/删除内容,但是我不想每次我想重新绘制时都创建一个新的JFrame。我知道我需要在另一个类中重新绘制它,但是我不明白将它“获取”到类中,代码:
public class TileFrame{
public TileFrame {
//all the usual jframe creation stuff here (not the issue)
JButton[][] tiles = new JButton[4][4];
for (int i=0; i<4; i++) {
for (int j=0; j<4; j++){
tiles[i][j] = new JButton();
}
}
}
}
public class doSomethingWithTheTileFrame{
public doSomethingWithTheTileFrame{
retrievedTileFrame = getTileFrame();
retrievedtileframe .....do stuff to this (this is already sorted)
}
}
public static void main (String[] args) {
TileFrame tileframe = new TileFrame();
doSomethingWithTheTileFrame();
}
我要问的是如何检索这个tileframe(JFrame)而不是每次都在doSomethingWithTheTileFrame 中创建一个新的?基本上我在问如何将 TileFrame 从 main 方法传递回 doSomethingWithTileFrame。
非常感谢。
【问题讨论】:
-
What I am asking is how to I retrieve this tileframe (a JFrame)和//all the usual jframe creation stuff here (not the issue)--> 这个 JFrame 是不是声明为局部变量(那么 getter/setter e.i. 的生活会更容易),为了更好地帮助尽快发布 SSCCE/MCVE,简短, 可运行, 可编译