小编Qui*_*ibo的帖子

由于"@Override"注释而无法绘制图形

我一直在尝试绘制JFrame,所以我可以在将来使用这些实验来创建我可能创建的程序.但是,我发现了一个我无法解决的问题:如何在设置定时器的同时绘制内容.

public static void MyTimer() {
JFrame frame = new JFrame("Colors");

    int width = 700;
    int height = 700;

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setBackground(Color.BLACK);
    frame.pack();
    frame.setSize(width, height);
    frame.setVisible(true);
    frame.setResizable(false);
    TimerTask task;
task = new TimerTask() {
    int a = 2;

    @Override
    public void run(Graphics g) {
        g.drawRect(a, 2, a + 66, 68);
    g.fillRect(a, 2, a + 66, 68);

        a = a + 20;
    }
};
     timer.schedule(task, 0, 1000);

}
Run Code Online (Sandbox Code Playgroud)

如你所见,我试图每秒画一个新的广场.问题是,我在代码中遇到错误:

方法不会覆盖或实现超类型的方法

我怎样才能解决这个问题?

java graphics swing overriding jpanel

2
推荐指数
1
解决办法
93
查看次数

我的函数返回的最后一个列表有错误

我刚刚开始学习Haskell,我打算编写一个返回到最后一个列表2的函数。

lastButOne x = if ((==) (length x) 2)
               then (head x)
               else (tail x)
Run Code Online (Sandbox Code Playgroud)

这是错误的:

    ? Occurs check: cannot construct the infinite type: a ~ [a]
    ? In the expression: (tail x)
      In the expression:
        if ((==) (length x) 2) then (head x) else (tail x)
      In an equation for ‘lastButOne’:
          lastButOne x = if ((==) (length x) 2) then (head x) else (tail x)
    ? Relevant bindings include
        x :: [a] (bound at D:\\tool\8.6.3\test\lBoErr.hs:1:12)
        lastButOne :: [a] -> …
Run Code Online (Sandbox Code Playgroud)

haskell

2
推荐指数
1
解决办法
45
查看次数

标签 统计

graphics ×1

haskell ×1

java ×1

jpanel ×1

overriding ×1

swing ×1