我有几个奇怪的问题,我似乎无法找到原因。这是针对数组中的队列整数。我有一个似乎正常的add()方法,但我的remove()方法是复制数组前面的数字并将其粘贴在gui显示的后面。我还设法让我的remove()方法从错误的一端获取整数。所以我最终在gui的文本字段中删除了下一个最后一个整数,显示当我点击删除按钮时,从数组前面的整数挂起到列表的末尾。我已经尝试了所有我能想到的东西,似乎无法解决问题。
public void add (int q) {
Random rand = new Random();
queue[rear] = rand.nextInt(100);
if (count == 0) {
queueList = Integer.toString(queue[rear]);
field2.setText(queueList);
}
else if (count >= 1) {
queueList = (field2.getText() + ", " + queue[rear]);
field2.setText(queueList);
}
count++;
rear = (rear + 1) % queue.length;
}//End add method
public int remove() {
queueList = "";
front = 0;
front = (front + 1) % queue.length;
if (count == 0) {
queueList = Integer.toString(queue[front]);
field2.setText(queueList);
} else if (count >= 1){
for (int i = front; i <= count; i++) {
queueList = queueList + ", " + queue[i % count];
field2.setText(queueList);
}
}
count--;
return front;
}//End remove method