Results 1 to 2 of 2
- 12-17-2012, 03:13 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 57
- Rep Power
- 0
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:
and these are the errors that the compiler is throwing at me when I try to check the 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"); box.setSize(240,240); box.setVisible(true); box.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("Hello World"); label.setSize(160,160); label.setVisible(true); box.add(label); JButton B1 = new JButton("Exit"); B1.setVisible(true); box.add(B1); box.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.Exit(0);} });}}
Test.java:22: error: cannot find symbol
System.Exit();}
^
symbol: method Exit(int)
location: class System
Test.java:20: 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!!
- 12-17-2012, 03:24 PM #2
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 - Play indie games, learn from game tutorials and source code, upload your own games!
Similar Threads
-
Keep on getting cannot find symbol errors...
By wizar in forum New To JavaReplies: 6Last Post: 11-25-2010, 04:31 AM -
"Cannot find symbol" errors in Java
By 23Zone in forum New To JavaReplies: 1Last Post: 02-17-2010, 07:13 AM -
cannot find symbol
By GabWit in forum New To JavaReplies: 3Last Post: 01-25-2009, 12:13 AM -
cannot find symbol symbol :constructor Error. Please help! =(
By KalEl in forum New To JavaReplies: 9Last Post: 10-18-2008, 08:26 PM -
cannot find symbol symbol : class Item location: package platypos.services.order
By officialhopsof in forum New To JavaReplies: 3Last Post: 05-01-2008, 08:30 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks