Results 1 to 2 of 2
  1. #1
    zlloyd1 is offline Member
    Join Date
    Nov 2012
    Rep Power

    Angry Cannot find symbol errors question

    I am trying to write some simple code in an attempt to gain some much needed knowledge of the java language, but I am getting errors that I cannot understand when I try to compile my program.... This is my code:
    Java Code:
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test extends JFrame{
    public static void main(String[] args){
    JFrame box = new JFrame();
    box.setTitle("Week1 test");
    JLabel label = new JLabel("Hello World");
    JButton B1 = new JButton("Exit");
    box.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
    and these are the errors that the compiler is throwing at me when I try to check the code: error: cannot find symbol
    symbol: method Exit(int)
    location: class System error: cannot find symbol
    box.addActionListener(new ActionListener(){
    symbol: method addActionListener((anonymous ActionListener))
    location: variable box of type JFrame

    I cannot understand what is wrong here, I mean I imported the javax.swing.*; which I thought had all of the action and event listeners contained within. I mean, I am not exactly sure about System.Exit(), but addActionListener I am pretty sure is correct for what I am trying to do. I have created a JFrame, and added a JLabel, and a JButton to it, but I need the button to actually do something, to close the window when pressed. I have been advised that action listeners are how to do this, and that if I import the swing library, I can use them in my code. Unfortunately the compiler has a different idea, and won't recognize these as existing java operations.
    PLEASE, I am very new to java, and really need to be able to figure out how to use the language, any help would be GREATLY appreciated!!

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Washington, DC
    Rep Power

    Default Re: Cannot find symbol errors question

    Where is the Exit() method of the System class? Note: case matters.

    Where is the addActionListener() method of JFrame? When would that be triggered?
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

Similar Threads

  1. Keep on getting cannot find symbol errors...
    By wizar in forum New To Java
    Replies: 6
    Last Post: 11-25-2010, 04:31 AM
  2. "Cannot find symbol" errors in Java
    By 23Zone in forum New To Java
    Replies: 1
    Last Post: 02-17-2010, 07:13 AM
  3. cannot find symbol
    By GabWit in forum New To Java
    Replies: 3
    Last Post: 01-25-2009, 12:13 AM
  4. Replies: 9
    Last Post: 10-18-2008, 08:26 PM
  5. Replies: 3
    Last Post: 05-01-2008, 08:30 AM

Tags for this Thread

Posting Permissions

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