Results 1 to 4 of 4
  1. #1
    shane5317 is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Question Cannot find symbol

    Java Code:
    import javax.swing.*;
    import javax.swing.JOptionPane;
    import java.awt.*;
    import java.awt.event.*;
    
    public class ClickImage extends JFrame implements ActionListener{
    	final static int  FrameWidth = 350;
    	final static int FrameHeight = 200;
    	
    	public ClickImage(){
    		JFrame FoodLabel = new JFrame("Favourite Food");
    		setSize(FrameWidth,FrameWidth);
    		setVisible(true);
    		JLabel heading = new JLabel("Please Select Your Favourite Food");
    		JLabel greeting = new JLabel("");
    		heading.setFont(new Font("Arial",Font.BOLD, 16));
    		JTextField answer = new JTextField(10);
    		JButton btn1 = new JButton("Chinese Food");
    		JButton btn2 = new JButton("Fast Food");
    		JButton btn3 = new JButton("West Food");
    		JButton btn4 = new JButton("Mamak Food");
    		btn1.setToolTipText("Click it for Favourite");
    		setLayout(new FlowLayout());
    		add(heading);
    		add(btn1);
    		add(btn2);
    		add(btn3);
    		add(btn4);
    		add(answer);
    		add(greeting);
    		btn1.addActionListener(this);
    		setDefaultCloseOperation(EXIT_ON_CLOSE);	
    	}
    	public void actionPerformed(ActionEvent e){
    		
    		[COLOR="Black"]String name = answer.getText();
    		String greet = "Hello" + name;
    		greeting.setText(greet);[/COLOR]
    	}
    	public static void main(String[] args){
    	ClickImage show = new ClickImage();	
    	}
    }
    Anyone please correct my code, i am beginner of Java. What wrong wtih my coding.:confused:
    Last edited by Eranga; 03-02-2011 at 12:20 PM. Reason: code tags added

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  3. #3
    shane5317 is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default

    symbol : variable answer
    location: class ClickImage
    String name = answer.getText();
    ^
    1 error

    i get this error!!!!:confused:

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Cannot find symbol
    By Johanis in forum New To Java
    Replies: 18
    Last Post: 11-09-2010, 09:34 PM
  2. Can not find symbol ???
    By AliceNewbie in forum New To Java
    Replies: 1
    Last Post: 02-17-2010, 02:44 AM
  3. cannot find symbol
    By GabWit in forum New To Java
    Replies: 3
    Last Post: 01-25-2009, 01:13 AM
  4. Replies: 9
    Last Post: 10-18-2008, 09:26 PM
  5. Replies: 3
    Last Post: 05-01-2008, 09:30 AM

Posting Permissions

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