我是Java经验的初学者,所以希望您能帮助我。
我想从 JTextfield 中读取步数。但是如何使楼梯可变呢?
Graphics g = textP.getGraphics();
int x = 5;
int y = 20;
int width = 10;
int height = 10;
对于循环 1 - 同时给出 6 件的 drawRect
for (int i = 0; i < 6; i++) {
g.drawRect(x, y * i, width, height);
}
对于循环 2 - 同时给出 5 个 drawRect
for (int i = 1; i < 6; i++) {
g.drawRect(x + 15, y * i, width, height);
}
对于循环 3 - 同时给出 4 个 drawRect
for (int i = 2; i < 6; i++) {
g.drawRect(x + 30, y * i, width, height);
}
对于循环 4 - 同时给出 3 个 drawRect
for (int i = 3; i < 6; i++) {
g.drawRect(x + 45, y * i, width, height);
}
对于循环 5 - 同时给出 2 件的 drawRect
for (int i = 4; i < 6; i++) {
g.drawRect(x + 60, y * i, width, height);
}
对于循环 6 - 同时给出 1 个 drawRect
for (int i = 5; i < 6; i++) {
g.drawRect(x + 75, y * i, width, height);
}
输出(必须由 rect ipv *):
*
**
***
****
*****
******