Я очень новичок в программировании на Java. В настоящее время я пытаюсь создать игру, в которой белые шары продолжают появляться на экране, и пользователь должен щелкнуть и перетащить мяч на правую сторону холста, чтобы он исчез. Я не закончил писать код, но код, который у меня есть, продолжает сбой моей программы Java. Может ли кто-нибудь сказать мне, что не так с кодом, который у меня есть, и почему моя программа продолжает рушиться? Спасибо!Создание объектов на клике
public class BubbleGame extends GraphicsProgram
{
//~ Instance/static variables
private GRect field;
private GRect goal;
private GObject gobj; /* The object being dragged */
private GPoint last; /* The last mouse position */
private RandomGenerator rgen = new RandomGenerator();
//~ Constructor ...........................................................
// ----------------------------------------------------------
/**
* Creates a new BubbleGame object.
*/
public void init()
{
//call method to create regions
CreateRegions();
//add mouse listeners
addMouseListeners();
//loop to add bubbles
while (true)
{
//create a filled bubble
GOval oval = new GOval (100, 100, 50, 50);
oval.setFilled(true);
oval.setColor(Color.WHITE);
add(oval);
//randomly generate coordinates within the field
//add the bubble and pause
}
}
//~ Methods ...............................................................
public void CreateRegions(){
//create and add the field with the size and color of your choice
field = new GRect(0, 0, getWidth() * .75, getHeight());
field.setFilled(true);
field.setColor(Color.GREEN);
add(field);
//create and add the adjacent goal with the size and color of your choice
goal = new GRect(493, 0, getWidth() * .25, getHeight());
goal.setFilled(true);
goal.setColor(Color.BLACK);
add(goal);
}
/* Called on mouse press to record the coordinates of the click */
public void mousePressed(MouseEvent e) {
last = new GPoint(e.getPoint());
gobj = getElementAt(last);
//later add check that not dragging field or goal
}
/* Called on mouse drag to reposition the object */
public void mouseDragged(MouseEvent e) {
if (gobj != null) {
gobj.move(e.getX() - last.getX(), e.getY() - last.getY());
last = new GPoint(e.getPoint());
}
}
/* Called on mouse drag to reposition the object */
public void mouseReleased(MouseEvent e) {
//if gobj has a value and its coordinates are contained by goal, make it invisible
}
}
«Это грохот» совсем не помогает. Что такое сообщение об ошибке? – Kayaman
Исключение из потока "main" java.lang.OutOfMemoryError: Java heap space Исключение в потоке "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space –