1

所以我的代码和视频中叙述者的代码之间的唯一区别是接口(我有 Netbeans,他使用 Eclipse),而他说的一行代码是不必要的。在这里观看,如果有帮助的话。谢谢

    package pixelgen;
    import java.awt.Canvas;
    import java.awt.Dimension;
    import javax.swing.JFrame;

    public class PixelGen extends Canvas implements Runnable {

        public static final int HIGH = 120;
        public static final int WIDE = 120;
        public static final int SCALE = 3;

        public static final String NAME = "PixelGen";

        @Override 
        public void run(){
         }

       public static void main(String[] args) {
            PixelGen game = new PixelGen();
            game.setPreferredSize(new Dimension(WIDE * SCALE, HIGH * SCALE));
            game.setMaximumSize(new Dimension(WIDE * SCALE, HIGH * SCALE));
            game.setMinimumSize(new Dimension(WIDE * SCALE, HIGH * SCALE));

            JFrame frame = new JFrame(NAME);

            frame.add(game);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            frame.pack();
            frame.setVisible(true);
            frame.setResizable(true);


        }
    }
4

0 回答 0