相关疑难解决方法(0)

Java秒表每秒更新一次GUI?

我是Java初学者,我正在尝试构建一个简单的秒表程序,在swing GUI上显示时间.制作秒表很简单,但我找不到每秒钟更新GUI的方法,并在秒表上显示当前时间.我怎样才能做到这一点?

java user-interface swing stopwatch

5
推荐指数
1
解决办法
1万
查看次数

如果通过递归函数调用paintComponent不起作用?

  1. 我希望看到所有的Points一个接一个,但我看到只能看到1分.看到所有的变化,我改变了Points什么?
  2. System.out你可以看到10次"设置"然后2次"paintComponent".在调用每个时间集之后我应该改变什么呢?它改变了"paintComponente"?

================================================== ================================

public class exampe extends JPanel  
{
    int x; 
    int y;

    public void paintComponent(Graphics g) 
    {
        super.paintComponent(g);

        Graphics2D g2 = (Graphics2D) g;
        g2.fillOval(x-2,y-2,4,4);
        System.out.println("paintComponent");        
    }

    public void set(int X, int Y)
    {
        x = X;
        y = Y;
        System.out.println("set");
        super.repaint();
    }

    public static void main(String args[]) 
    {   
        int e=1;

        JFrame frame = new JFrame("TEST");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        exampe ex= new exampe();
        JScrollPane scroll = new JScrollPane(ex);
        frame.getContentPane().add(scroll);

        frame.setSize(400, 300);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);

        for(int i=0; …
Run Code Online (Sandbox Code Playgroud)

java swing paintcomponent

-5
推荐指数
1
解决办法
1926
查看次数

标签 统计

java ×2

swing ×2

paintcomponent ×1

stopwatch ×1

user-interface ×1