swing 刷新问题
package scf.luffy;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class Bell extends JFrame {
private int x1 = 100;
private int y1 = 100;
private int x2 = 100;
private int y2 = 100;
private static final long serialVersionUID = -8672941220924959402L;
Bell() {
setLayout(new GridLayout(1,1));
setSize(500, 500);
setLocation(100, 100);
setResizable(false);
setVisible(true);
Thread t = new GoGoGo();
SwingUtilities.updateComponentTreeUI(this);
t.start();
}
public void paint(Graphics g) {
/**/
Graphics2D g2d = (Graphics2D) g;
setBackground(Color.PINK);
g2d.setColor(Color.red);
g.drawRect(x1, y1, x2, y2);// 画矩形
}
class GoGoGo extends Thread {
public void run() {
for (int i = 0; i < 10; i++) {
x1 += 10;
x2 += 10;
y1 += 10;
y2 += 10;
System.out.println(x1);
try {
sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
repaint();
validate();
}
}
}
public static void main(String[] args) {
new Bell();
}
}
以上代码运行后 会画出许多 图形,但是实际上就是一个,没有刷新而已。
怎么让他能刷新啊~
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class Bell extends JFrame {
private int x1 = 100;
private int y1 = 100;
private int x2 = 100;
private int y2 = 100;
private static final long serialVersionUID = -8672941220924959402L;
Bell() {
setLayout(new GridLayout(1,1));
setSize(500, 500);
setLocation(100, 100);
setResizable(false);
setVisible(true);
Thread t = new GoGoGo();
SwingUtilities.updateComponentTreeUI(this);
t.start();
}
public void paint(Graphics g) {
/**/
Graphics2D g2d = (Graphics2D) g;
setBackground(Color.PINK);
g2d.setColor(Color.red);
g.drawRect(x1, y1, x2, y2);// 画矩形
}
class GoGoGo extends Thread {
public void run() {
for (int i = 0; i < 10; i++) {
x1 += 10;
x2 += 10;
y1 += 10;
y2 += 10;
System.out.println(x1);
try {
sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
repaint();
validate();
}
}
}
public static void main(String[] args) {
new Bell();
}
}
以上代码运行后 会画出许多 图形,但是实际上就是一个,没有刷新而已。
怎么让他能刷新啊~
...全文
相关推荐
Java swing风格美化
**刷新组件**:设置完主题后,需要刷新所有Swing组件以应用新的外观。
JTable动态刷新数据
JTable 动态刷新数据JTable 动态刷新数据是指在 Java Swing 应用程序中,使用 JTable 组件展示数据,并实时更新数据的过程。
java浏览器+swing嵌套网页+源码免费
**错误处理**:处理加载失败、网络问题和其他可能出现的异常情况,确保程序的健壮性。6. **界面优化**:可能包括添加前进、后退按钮,刷新功能,以及地址栏等常见浏览器元素,提升用户体验。
swing-fixer:摆动修复工具
摆动固定器每当在以下方面遇到 Java Swing 问题时: 由于某些原因,我的 GUI 没有刷新, 在这个该死的代码中看不到任何变化, 任何其他与 Swing 相关且未被识别的问题来源只需致电:
Smartclient-Top-Cases:基于 JavaFX Java Swing 的应用程序显示按类型分组创建的顶级案例
通过分析这些代码,开发者可以深入理解如何在JavaFX和Swing中实现上述功能,包括数据模型的设计、UI组件的绑定、事件处理以及多线程同步等问题。7.


Java SE
