I am working on a simple GUI app that just draws some graphics on a canvas. The environment is Vista 64. When I run the program, the Windows resize and minimize buttons work, but the close button doesn’t. So I have to press the stop button in Eclipse to kill the program.
But sometimes I forget to press stop, and run the program again. The first instance gets stuck and I can’t get rid of it without closing Eclipse. If I get careless I can end up with several java windows I can’t close. Is there a way to get control of and close the windows? Also, why does the close button not work?
I doubt the code matters in this case but here it is:
import java.awt.*;
public class RobotFace extends Canvas{
/**
* @param args
*/
public static void main(String[] args) {
RobotFace c = new RobotFace();
c.setBackground(Color.white);
c.setSize(350, 350);
Frame f = new Frame();
f.add(c);
f.setLayout(new FlowLayout());
f.setSize(350,350);
f.setVisible(true);
}
public void paint(Graphics g){
g.setColor(Color.black);
int width = 150;
int height = 200;
g.drawRect((getWidth()-width)/2, (getHeight()-height)/2, width, height);
g.setColor(Color.gray);
g.fillRect((getWidth()-width)/2, (getHeight()-height)/2, width, height);
g.setColor(Color.white);
g.fillRect((getWidth()-80)/2, (getHeight()+50)/2, 80, 20);
g.setColor(Color.yellow);
g.fillOval((getWidth()-105)/2, (getHeight()-100)/2, 30, 30);
g.fillOval((getWidth()+45)/2, (getHeight()-100)/2, 30, 30);
}
}
Your Eclipse console for the first application instance should still be available, just not visible. On the Console tab, you can click the toolbar button that looks like a little blue monitor to switch between application instances. To stop the first application instance, you would select that instance using the little blue monitor (it’s called “Display Selected Console”), then click the “Stop” button.