GUI Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bobbybrown
    New Member
    • Mar 2007
    • 9

    GUI Problem

    I have now moved my Main code into the GUI project file, but there is a load of code that Netbeans is saying that is wrong.
    This is the code that i have moved. It was suggested yeterday by an admin guy to move this code into my gui coded area and just put a method that refers to it.
    What i am trying to do is using my FileCHooser let the user pick a file then read it in using this method below. But I get a lot of errors and i dont know what is wrong???

    Code:
    public class Main {
        
    public Main()
    {}
        
    public static void main(String[] args)
    {       
        Process p = new Process();
        String filename;
        filename = "";
        
        if(args.length==0)
        {
            System.out.println("Please enter the filename of the bus network.");
            try
            {
                 filename = p.input();
            }
            catch (IOException x)
            {
                System.out.println("Unrecoverable IO Exception.");
                Runtime.getRuntime().exit(0);
            } 
        }
        else
        {
            filename = args[0];
        }
        
            
        try
        {
            p.readFile(filename);
        }
        catch (IOException x)
        {
            System.out.println("Unrecoverable IO Exception.");
            Runtime.getRuntime().exit(0);
        }  
                
        
        while(true)
        {
        try
        {
            System.out.println("Please select what you would like to do.");
            System.out.println("Search, Edit, Delete or Exit");
            p.menu(p.input());
        }
        catch (IOException x)
        {
            System.out.println("IO Exception.");
        }
        }
        
    }
          
    }

    Erorrs are:
    Inner classes cannot have static declarations
    Java.lang.Proce ss is abstract: cannot initialise
    Cannot find method input();
    Cannot find method readFile();
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by bobbybrown
    I have now moved my Main code into the GUI project file, but there is a load of code that Netbeans is saying that is wrong.
    This is the code that i have moved. It was suggested yeterday by an admin guy to move this code into my gui coded area and just put a method that refers to it.
    What i am trying to do is using my FileCHooser let the user pick a file then read it in using this method below. But I get a lot of errors and i dont know what is wrong???

    Code:
    public class Main {
        
    public Main()
    {}
        
    public static void main(String[] args)
    {       
        Process p = new Process();
        String filename;
        filename = "";
        
        if(args.length==0)
        {
            System.out.println("Please enter the filename of the bus network.");
            try
            {
                 filename = p.input();
            }
            catch (IOException x)
            {
                System.out.println("Unrecoverable IO Exception.");
                Runtime.getRuntime().exit(0);
            } 
        }
        else
        {
            filename = args[0];
        }
        
            
        try
        {
            p.readFile(filename);
        }
        catch (IOException x)
        {
            System.out.println("Unrecoverable IO Exception.");
            Runtime.getRuntime().exit(0);
        }  
                
        
        while(true)
        {
        try
        {
            System.out.println("Please select what you would like to do.");
            System.out.println("Search, Edit, Delete or Exit");
            p.menu(p.input());
        }
        catch (IOException x)
        {
            System.out.println("IO Exception.");
        }
        }
        
    }
          
    }

    Erorrs are:
    Inner classes cannot have static declarations
    Java.lang.Proce ss is abstract: cannot initialise
    Cannot find method input();
    Cannot find method readFile();
    How did you merge the classes. Let's see your code.

    Comment

    • bobbybrown
      New Member
      • Mar 2007
      • 9

      #3
      I just put it in, copy and paste, then tried to make an instance of Main after the filechooser. In the button part
      But i get errors


      <code removed>

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by bobbybrown
        I just put it in, copy and paste, then tried to make an instance of Main after the filechooser. In the button part
        But i get errors


        <code removed>
        Now that wont work. Rename the main method in the main class to something else and put that method inside the class with the GUI. After the filechooser create a String array with the arguments required to call that method in the main class and call it from there

        Comment

        • bobbybrown
          New Member
          • Mar 2007
          • 9

          #5
          Originally posted by r035198x
          Now that wont work. Rename the main method in the main class to something else and put that method inside the class with the GUI. After the filechooser create a String array with the arguments required to call that method in the main class and call it from there
          I Really dnt know what to do to be honest...

          Comment

          • bobbybrown
            New Member
            • Mar 2007
            • 9

            #6
            I thought i already did that above

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by r035198x
              Now that wont work. Rename the main method in the main class to something else and put that method inside the class with the GUI. After the filechooser create a String array with the arguments required to call that method in the main class and call it from there
              You copied the whole class not just the main method. Go through these steps above and verify that you've done each of these steps and tell us if you get any errors.

              Comment

              Working...