import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.Window;
public class autoSize extends Applet
{
int width,height,a=200,b=200;
public void init() {
//addWindowStateListener(new Mouse());
this.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent evt) {
width = getWidth();
height = getHeight();
// repaint();
}
});
setSize(300,300);
}
public void paint(Graphics g){
//g.drawOval((width-a)/2,(height-b)/2,a,b);//定中心位置
//g.drawOval((width-a)/2,(height-b)/2,(a*width)/300,(b*width)/300);计算长宽缩放
g.drawOval((width-(a*width)/300)/2,(height-(b*width)/300)/2,(a*width)/300,(b*width)/300);
//计算圆心保持中心位置
}
//class Mouse extends WindowAdapter {
// public void windowStateChanged(WindowEvent e) {
// width = size().width;
// height = size().height;
// repaint();
// } //end mousePressed
//end Mouse
}