我只想制作一个基本的计数器,由于某种原因,我无法弄清楚如何在1到100之间绘制一个随机数.有人可以解释一下我要做什么来绘制1到100之间的随机数吗?
这就是我想到的:
int value;
private int count = 1;
Random rand;
}
Run Code Online (Sandbox Code Playgroud) 为什么我的定时器出错了?在代码下方,它说明错误是什么.我无法弄清楚我做错了什么......任何人都可以帮助我
import java.util.Timer;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
/**
*
* @author Rich
*/
public class Board extends JPanel implements ActionListener{
Dude p;
Image img;
Timer time;
public Board() {
p = new Dude();
addKeyListener(new AL());
setFocusable(true);
ImageIcon i = new ImageIcon("images.jpg");
img = i.getImage();
time = new Timer(5,this);
time.start();
}
public void actionPerformed(ActionEvent e) {
p.move();
repaint();
}
Run Code Online (Sandbox Code Playgroud)
基本上我得到的错误是
no suitable constructor found for Timer(int,OurGame.Board)
constructor java.util.Timer.Timer(java.lang.String,boolean) is not applicable
(actual argument int cannot be converted to java.lang.String by method …Run Code Online (Sandbox Code Playgroud) Can anyone explain to me why my Homework keeps retuning a value of 1.0, I asked my teacher and he tells me "langauges are very similar I do not remember in this languge -.-..... you should not be learning this because you are in java 1 not java 2" ...... anyway im trying to get ahead and teach myself
/**
* Author Rich Talcik, Do not Edit or modify
* Homework assignment2
* 09/11/13
* Problem 2.7 page 109
* …Run Code Online (Sandbox Code Playgroud)