java frame update_java – 更新JFrame

我有一个JFrame,我想模拟倒计时(如火箭发射).所以我通过隐藏各种控件(setVisible(false))并显示带有文本的JLabel来设置框架(这是应该倒计时的文本:3,2,1,Go).

JLabel上的文字从“3”开始.我的目的是简单地执行程序等待1秒,然后将文本更改为“2”,再等一秒,更改为“1”等.最后,我隐藏了JLabel并重新显示了所有控件,一切都正常进行.

我在做什么不起作用.它似乎等待了正确的时间,当它完成时,我的JFrame看起来很棒并按预期工作.但在倒计时方法的4秒钟内,我看到的只是一个白色的JFrame.不是我想要的3,2,1.

这是我的代码.谁能看到我做错了什么?谢谢!

public void countdown() {

long t0, t1;

myTest.hideTestButtons(true);

myTest.repaint();

t0 = System.currentTimeMillis();

do {

t1 = System.currentTimeMillis();

} while ( (t1 - t0) < 1000);

myTest.TwoSeconds();

myTest.repaint();

t0 = System.currentTimeMillis();

do {

t1 = System.currentTimeMillis();

} while ( (t1 - t0) < 1000);

myTest.OneSecond();

myTest.repaint();

t0 = System.currentTimeMillis();

do {

t1 = System.currentTimeMillis();

} while ( (t1 - t0) < 1000);

myTest.Go();

myTest.repaint();

t0 = System.currentTimeMillis();

do {

t1 = System.currentTimeMillis();

} while ( (t1 - t0) < 1000);

myTest.hideTestButtons(false);

myTest.repaint();

}

public void TwoSeconds() {

lblCountdown.setText("2");

}

public void OneSecond() {

lblCountdown.setText("1");

}

public void Go() {

lblCountdown.setText("Go!");

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以为您提供一个简单的 Java Frame 类实现图书馆管理系统的示例代码。 ```java import javax.swing.*; import java.awt.*; import java.awt.event.*; public class LibraryManagementSystem extends JFrame implements ActionListener { // 声明组件 JLabel titleLabel, bookNameLabel, authorLabel, publisherLabel, yearLabel, quantityLabel; JTextField bookNameField, authorField, publisherField, yearField, quantityField; JButton addButton, deleteButton, updateButton, searchButton; public LibraryManagementSystem() { // 设置窗口标题 setTitle("图书馆管理系统"); // 设置窗口大小 setSize(400, 300); // 设置窗口布局为流布局 setLayout(new FlowLayout()); // 初始化组件 titleLabel = new JLabel("图书信息管理"); bookNameLabel = new JLabel("书名:"); authorLabel = new JLabel("作者:"); publisherLabel = new JLabel("出版社:"); yearLabel = new JLabel("出版年份:"); quantityLabel = new JLabel("数量:"); bookNameField = new JTextField(20); authorField = new JTextField(20); publisherField = new JTextField(20); yearField = new JTextField(20); quantityField = new JTextField(20); addButton = new JButton("添加"); deleteButton = new JButton("删除"); updateButton = new JButton("更新"); searchButton = new JButton("查询"); // 添加组件到窗口中 add(titleLabel); add(bookNameLabel); add(bookNameField); add(authorLabel); add(authorField); add(publisherLabel); add(publisherField); add(yearLabel); add(yearField); add(quantityLabel); add(quantityField); add(addButton); add(deleteButton); add(updateButton); add(searchButton); // 添加按钮的点击事件监听器 addButton.addActionListener(this); deleteButton.addActionListener(this); updateButton.addActionListener(this); searchButton.addActionListener(this); // 设置窗口可见 setVisible(true); } @Override public void actionPerformed(ActionEvent e) { // 处理按钮点击事件 if (e.getSource() == addButton) { // 添加图书 // TODO: 实现添加图书的逻辑 } else if (e.getSource() == deleteButton) { // 删除图书 // TODO: 实现删除图书的逻辑 } else if (e.getSource() == updateButton) { // 更新图书 // TODO: 实现更新图书的逻辑 } else if (e.getSource() == searchButton) { // 查询图书 // TODO: 实现查询图书的逻辑 } } public static void main(String[] args) { // 创建图书馆管理系统窗口 new LibraryManagementSystem(); } } ``` 这是一个简单的示例代码,你可以根据自己的实际需求进行修改和完善。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值