Where will i put “Public static void main(String[] args)”?

前端 未结 4 1930
陌清茗
陌清茗 2021-01-17 00:54

I started coding java a few days ago. İ made a few succesfull programs but im stuck on this one. Where ever i write the \"Public static void main(String[] args)\" code i get

4条回答
  •  庸人自扰
    2021-01-17 01:17

    Your problem lies with these 3 lines:

    public class Panel_Test extends JFrame{
    
    public static void main(String[] args){
        public Board(){
    

    The main method should not have the constructor in it either, this needs to be separate and outside of the method. I would also suggest having a Board class with the Board constructor and a Panel_Test class with the main method in there. Try this instead:

    public class Panel_Test {
    
        public static void main(String[] args){
            new Board().doSwing();
        }
    }
    
    public class Board extends JFrame {
    
        public Board() {
        }    
    
        public void doSwing() {
        //Your Swing code here...
        }
    }
    

提交回复
热议问题