我的JFrame不会出现

时间:2013-06-12 05:09:31

标签: java swing jframe

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

    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);


        }
    }

0 个答案:

没有答案