Results 1 to 3 of 3

Thread: Help With Code

  1. #1
    Join Date
    Mar 2011
    Posts
    93
    Rep Power
    0

    Default Help With Code

    Hello. I'm trying to write this bit of code I got out of a book about java. I believe I have copied the code correctly, yet when I compile it, I get an error message: invalid method declaration; return type required; public FeedInfo() {
    Can anyone show me my error? Thanks in advance.

    Java Code:
    import java.awt.GridLayout;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class FeedInfor extends JFrame {
    	private JLabel nameLabel = new JLabel("Name: ", 			SwingConstants.RIGHT);
    	private JTextField name;
    	private JLabel urlLabel = new JLabel("URL: ", 			SwingConstants.RIGHT);
    	privateJTextField url;
    	private JLabel typeLabel = new JLabel("Type: ", 			SwingConstants.RIGHT);
    	privateJTextField type;
    
    	public FeedInfo() {
    		super("Feed Information");
    		setSize(400, 105);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setLookAndFeel();
    		
    		String response1 = JOptionPane.showInputDialog			(null, "Enter the site name: ");
    		name = newJTextField(response1, 20);
    
    		String response2 = JOptionPane.showInputDialog			(null, "Enter the site address: ");
    		url = new JTextField(response2, 20);
    
    		String[] choices = { "Personal", "Commercial", 			"Unknown" };
    		int response3 = JOptionPane.showOptionDialog				(null, 
    			"What type of site is it?", 
    			"Site Type", 
    			0, 
    			JOptionPane.QUESTION_MESSAGE, 					null, 
    			choices, 
    			choices[0]);
    		type = new JTextField(choices[response3], 20);
    
    		setLayout(new GridLayout(3, 2));
    		add(nameLabel);
    		add(name);
    		add(urlLabel);
    		add(url);
    		add(typeLabel);
    		add(type);
    		setLookAndFeel();
    		setVisible(true);
    	}
    
    	private void setLookAndFeel() {
    		try {
    			UIManager.setLookAndFee(								UIManager.getSystemLookAndFeelClassName					());
    			SwingUtilities.updateComponentTreeUI(this);
    		} catch (Exception e) {
    			System.err.println("Couldn't use the 					system " + "look and feel: " + e);
    		}
    	}
    	
    	public static void main(String[] arguments) {
    		FeedInfo frame = new FeedInfo();
    	}
    }

  2. #2
    cultclassic is offline Member
    Join Date
    Mar 2011
    Posts
    64
    Rep Power
    0

    Default

    You have a typo in your ClassName....
    change it to
    Java Code:
    public class FeedInfo extends JFrame {
    Right now java thinks the constructor
    Java Code:
    public FeedInfo() {
    is just a method, in class FeedInfor and is looking for the return type.
    Last edited by cultclassic; 05-17-2011 at 10:40 PM.

  3. #3
    Join Date
    Mar 2011
    Posts
    93
    Rep Power
    0

Similar Threads

  1. Replies: 0
    Last Post: 02-21-2011, 11:50 AM
  2. Replies: 1
    Last Post: 03-04-2010, 11:19 AM
  3. Convert java code to midlet code
    By coldvoice05 in forum New To Java
    Replies: 1
    Last Post: 08-12-2009, 11:14 AM
  4. Convert java code to midlet code
    By coldvoice05 in forum Advanced Java
    Replies: 1
    Last Post: 08-09-2009, 01:21 PM
  5. Replies: 1
    Last Post: 04-26-2007, 03:52 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
  •