Results 1 to 6 of 6
  1. #1
    shodai is offline Senior Member
    Join Date
    Apr 2012
    Posts
    106
    Rep Power
    0

    Default Missing Method in GUI

    I have written the following test program, but I keep getting the same error: Return type for the method is missing. Does this make sense to anyone?


    Java Code:
    import javax.swing.*;
    import java.awt.*;
    
    public class BUTTONtest
    {
      private JFrame frame;
      private JButton btnOK;
      private JButton btnStop;
      private JButton btnStop1;
      private JButton btnStop2;
      private JButton btnStop3;
      private JTextField txtAddress;
      private JLabel lblAddress;
      
      public BUTTONtest()
      {
        //This creates our frame
        frame = new JFrame ("title goes here");
        frame.setSize (400, 350);
        frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        
        //Sets up the window into a 3 x 2 grid
        frame.getContentPane ().setLayout (new GridLayout(3,2));
        
        JPanel panel1 = new JPanel();
        panel1.setLayout(new FlowLayout());
        frame.getContentPane().add (panel1);
        
        
        JPanel panel2 = new JPanel();
        panel2.setLayout(new FlowLayout());
        frame.getContentPane().add (panel2);
        
        
        JPanel panel3 = new JPanel();
        panel1.setLayout(new FlowLayout());
        frame.getContentPane().add (panel3);
        
        
        JPanel panel4 = new JPanel();
        panel1.setLayout(new FlowLayout());
        frame.getContentPane().add (panel4);
        
        
        JPanel panel5 = new JPanel();
        panel1.setLayout(new FlowLayout());
        frame.getContentPane().add (panel5);
        
        
        JPanel panel6 = new JPanel();
        panel1.setLayout(new FlowLayout());
        frame.getContentPane().add (panel6);
        
        btnOK = new JButton ("Hello");
        panel1.add (btnOK);
        
        btnStop = new JButton ("Stop Or I Will Shoot");
        btnStop.setForeground (Color.BLUE);
        panel1.add (btnStop);
        
        btnStop1 = new JButton ("Stop Again");
        btnStop.setBackground (Color.RED);
        panel1.add (btnStop1);
        
        btnStop2 = new JButton ("Stop 2");
        btnStop2.setForeground (Color.MAGENTA);
        btnStop2.setBackground (Color.PINK);
        panel4.add (btnStop2);
        
        btnStop3 = new JButton ("Stop a Third Time");
        btnStop3.setForeground (Color.BLACK);
        panel5.add (btnStop3);
        
        lblAddress = new JLabel ("Put in your address ");
        panel6.add (lblAddress);
        
        txtAddress = new JTextField (10);
        panel6.add(txtAddress);
        
        frame.setVisible (true);
      }
      
      public static void main (String []args)
      {
        new BUTTONtest();
      }
      
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Missing Method in GUI

    Post the full error, highlighting the line in your code which is causing the problem.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,354
    Rep Power
    6

    Default Re: Missing Method in GUI

    The posted code compiles and runs just fine. Did you put it all in a file named BUTTONtest.java - case sensitive?

    And do yourself a favor: use a proper Java naming convention. Name the class (and source file, and constructor) ButtonTest
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Missing Method in GUI

    This is not the cause of your problem, but you should not create or manipulate Swing objects outside the Swing thread.

    This:

    Java Code:
    public static void main (String []args)
      {
        new BUTTONtest();
      }
    ...should be:

    Java Code:
    public static void main(String[] args) {
       SwingUtilities.invokeLater(new Runnable() {
          @Override
          public void run() {
             new BUTTONtest();
          }
       });
    }
    Get in the habit of using standard Java naming conventions!

  5. #5
    shodai is offline Senior Member
    Join Date
    Apr 2012
    Posts
    106
    Rep Power
    0

    Default Re: Missing Method in GUI

    As per usual, the solution to one problem leads to another. I am trying to call a method in a separate class using the command button in the program. I have tried moving the code that was calling the method in the main method to the method that controls the command button. Any ideas?

  6. #6
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

Similar Threads

  1. Replies: 7
    Last Post: 04-11-2013, 06:31 AM
  2. Netbeans created .jar file says missing main method...
    By ChexWithRaisins in forum NetBeans
    Replies: 19
    Last Post: 11-26-2011, 01:03 AM
  3. Replies: 2
    Last Post: 09-27-2011, 04:59 PM
  4. Replies: 5
    Last Post: 01-17-2010, 12:14 AM
  5. Replies: 18
    Last Post: 12-02-2009, 01:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •