我创建了一个从JPanel扩展的类,其布局属性是GridBagLayout.我基本上需要显示一个JLabel(网格)数组,但是一旦创建了组件我就无法替换它.我试图删除我想要更改的组件,然后放置新组件,但结果很奇怪.例如,我创建了一个10x10 JLabel的数组,并想用这段代码替换position [0] [0]和position [9] [9]:
//At first i have the jpanel layout completely filled
this.remove(0);
this.add((JLabel) start, 0); //This was created with GridBagLayout.gridx = 0 and GridBagLayout.gridy = 0 and it's fine
this.remove(99);
this.add((JLabel) end, 99); //This was created with GridBagLayout.gridx = 9 and GridBagLayout.gridy = 9 and it's out of grid
this.revalidate();
Run Code Online (Sandbox Code Playgroud)
但只有位置[0] [0]看起来很好.我该怎么做才能更换一个组件?

我正在做一个与编译器设计相关的项目。我需要为基于 Java 的语言生成三个地址代码,这意味着使用对象和范围。我想您是否可以帮助我为以下示例生成 TAC(或向我推荐教程):
class A {
int x;
String y;
public A(int x, String y) {
this.x = x;
this.y = y;
}
}
Run Code Online (Sandbox Code Playgroud)
import A;
class B {
int f;
A foo;
public B() {
this.foo = null;
this.f = -1;
}
public boolean createFoo() {
this.foo = new A(0, "TAC Example");
return true;
}
public static void main() {
B bar = new B();
A baz = new A(666, "TAC generation");
bar.createFoo();
bar.foo.y = "Hello World";
if(bar.foo.x …Run Code Online (Sandbox Code Playgroud) java compiler-construction code-generation compiler-optimization