Here's my code; https://gist.github.com/anonymous/b8ef69a391c6c4e37b92
I've tried placing the "label1.setText("Bouncing bouncing ball" + bounceCount);" into the main method, but of course the variable bounceCount is a class variable and cannot be used inside the main method, is there any way around this?
答案 0 :(得分:0)
这里有两个选择。
private readonly HashSet<char> _operators = new HashSet<char>() { '+', '*', '-', '/' };
void AppendOperator(string operation)
{
char lastChar = Result.Text.LastOrDefault();
if (_operators.Contains(lastChar)) return;
Result.Text = num.ToString() + operation;
}
然后:
public int getBounceCount() {
return bounceCount;
}
while (true) {
game.moveBall();
game.checkBounceCount();
//JLabel label1 = new JLabel();
//label1.setText("Bouncing bouncing ball" + game.getBounceCount());
game.repaint();
Thread.sleep(10);
}
然后在主要方法中:
public class Game extends JPanel implements Runnable {
//...
public void run() {
//Your game's main animation loop
while (true) {
//Do your thing
}
}
}