Answer the question
In order to leave comments, you need to log in
Java frame won't close, how to fix?
I create a window in which a circle is displayed, but when I try to close the window, nothing happens. It can only be closed through the task manager. How can this misunderstanding be corrected?
import java.awt.*;
class CircleCanvas extends Canvas {
public void paint(Graphics g){
Dimension d=this.getSize();
int diam=Math.min(d.width-1,d.height-1)-60;
g.drawOval(20,20,diam,diam);
}
}
class MyFrame extends Frame {
public MyFrame(){
super("Painting");
// setBackground(Color.grey);
setLayout(new GridLayout(3,3));
add(new CircleCanvas());
setSize(500,400);
setVisible(true);
}
}
public class RunGn{
public static void main(String[] u) {
Frame f=new MyFrame();
});
}
}
Answer the question
In order to leave comments, you need to log in
https://www.tutorialspoint.com/awt/awt_window_list...
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
class CircleCanvas extends Canvas
{
public void paint(Graphics g)
{
Dimension d = this.getSize();
int diam = Math.min(d.width - 1, d.height - 1) - 60;
g.drawOval(20, 20, diam, diam);
}
}
class MyFrame extends Frame
{
public MyFrame()
{
super("Painting");
setBackground(Color.gray); // GRAY а не GREY
setLayout(new GridLayout(3, 3));
add(new CircleCanvas());
setSize(500, 400);
setVisible(true);
// обработчик событий
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});
}
}
public class RunGn
{
public static void main(String[] u)
{
Frame f = new MyFrame();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question