Results 1 to 6 of 6
Thread: Missing Method in GUI
- 04-01-2014, 03:01 PM #1
Senior Member
- Join Date
- Apr 2012
- Posts
- 112
- Rep Power
- 0
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(); } }
- 04-01-2014, 03:34 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 25
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 **
- 04-01-2014, 03:42 PM #3
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 10
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
- 04-02-2014, 05:20 PM #4
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(); }
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!
- 04-02-2014, 05:35 PM #5
Senior Member
- Join Date
- Apr 2012
- Posts
- 112
- Rep Power
- 0
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?
- 04-02-2014, 05:49 PM #6
Re: Missing Method in GUI
Post your code.
Get in the habit of using standard Java naming conventions!
Similar Threads
-
Array-Poker Shuffle Method/ cut Method/ deal cards Method NO IDEA how to start..
By NoobieCode in forum New To JavaReplies: 7Last Post: 04-11-2013, 05:31 AM -
Netbeans created .jar file says missing main method...
By ChexWithRaisins in forum NetBeansReplies: 19Last Post: 11-26-2011, 12:03 AM -
error: Missing method, body, or declare abstract public static void main
By MBD in forum New To JavaReplies: 2Last Post: 09-27-2011, 03:59 PM -
giving missing return statement error.due to withdraw method.
By qadeer37 in forum New To JavaReplies: 5Last Post: 01-16-2010, 11:14 PM -
Missing return statement help and format method help
By Chewart in forum New To JavaReplies: 18Last Post: 12-02-2009, 12:01 PM
Bookmarks