新手敲了书上的代码心血来潮想要打一个爱心的图形界面出来,下面是我的代码和一些注释以及效果图,附上爱心算法的原出处(好吧,找不到了)
import java.awt.*;//包含了很多类与接口,其中有基本组件,容器类组件,2D图形绘制组件,布局管理器,事件处理模型 import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class GraphicsTest extends Frame { double x[] = new double[360]; double y[] = new double[360]; int xx[] = new int[360]; int yy[] = new int[360]; int k = 0; public GraphicsTest() { super();//子类调用父类的无参构造方法 this.setTitle("爱你"); this.setSize(600, 600); this.setLocation(500, 300); this.setVisible(true); setSize(480, 460);//设置窗口的大小 setLocationRelativeTo(null);//设置窗口指定的位置,null和0为默认在中间 addWindowListener(new WindowAdapter() {//事件监听器,//windowAdapter只需自己的部分,其他方法定义为空 public void windowClosing(WindowEvent e) {//windowClosing正在关闭窗口 System.exit(0);/