473,427 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,427 software developers and data experts.

Cannot find symbol class (Java swing)

Hey,

I seem to have a problem on a Java Swing Program with ActionListener. I've tried to use getSource in our class but seem don't have an idea why it won't work when I tried to program at home. ( I'm using an earlier version of JCreator in school and a JCreator Pro here at home, Does that affect the program at all? )

Here's the code:
Expand|Select|Wrap|Line Numbers
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4.  
  5. public class Group2 extends JFrame implements ActionListener{
  6.  
  7. public void Group2(){
  8.         JLabel text = new JLabel("Enter a number to partition: ");
  9.         JTextField input = new JTextField(15);
  10.          JButton submit=new JButton("Submit");
  11.         String listboxitems[]={"5","1111111","111111111","1111111111"};
  12.         JList listbox = new JList(listboxitems);
  13.         JLabel timeprocessed=new JLabel("It x milliseconds to process the output");
  14.            setSize(350, 250);
  15.         setTitle("Group 2 COPRO2 & DATASTRUCT Project");
  16.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  17.  
  18.           FlowLayout layoutManager = new FlowLayout(FlowLayout.CENTER);
  19.         layoutManager.setHgap(10);
  20.         layoutManager.setVgap(10);
  21.         setLayout(layoutManager);
  22.         getContentPane().setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
  23.         getContentPane().add(text);
  24.         getContentPane().add(input);
  25.         getContentPane().add(submit);
  26.         getContentPane().add(listbox);
  27.         getContentPane().add(timeprocessed);
  28.         submit.addActionListener(this);
  29. }
  30. public void actionPerformed(ActionEvent ae){
  31. if(ae.getSource()==submit){
  32.         timeprocessed.setVisible(true);}
  33. else{
  34. System.out.println("error");
  35. }
  36.          }
  37.  
  38.     public static void main(String[] args) {
  39.         new Group2().setVisible(true);
  40. }
  41.  
  42.  
  43. }
The error text:
Expand|Select|Wrap|Line Numbers
  1. C:\Documents and Settings\User\Desktop\Group2.java:31: cannot find symbol
  2. symbol  : variable submit
  3. location: class Group2
  4. if(ae.getSource()==submit){
  5.                    ^
  6. C:\Documents and Settings\User\Desktop\Group2.java:32: cannot find symbol
  7. symbol  : variable timeprocessed
  8. location: class Group2
  9.         timeprocessed.setVisible(true);}
  10.         ^
  11. 2 errors
Thank You!
Oct 17 '10 #1

✓ answered by Nepomuk

This looks like a scope problem. Try defining the Objects submit and timeprocessed outside of the constructor and just initializing them inside:
Expand|Select|Wrap|Line Numbers
  1.  //...
  2.  
  3. private JButton submit;
  4. private JLabel timeprocessed;
  5.  
  6. public class Group2 extends JFrame implements ActionListener{
  7.  
  8. public void Group2(){
  9.         //...
  10.         submit=new JButton("Submit");
  11.         String listboxitems[]={"5","1111111","111111111","1111111111"};
  12.         JList listbox = new JList(listboxitems);
  13.         timeprocessed=new JLabel("It x milliseconds to process the output");
  14.         //...
  15. }
  16. public void actionPerformed(ActionEvent ae){
  17. if(ae.getSource()==submit){
  18.         timeprocessed.setVisible(true);}
  19. else{
  20. System.out.println("error");
  21. }
  22.          }
  23.     //...
  24. }
Greetings,
Nepomuk

1 9830
Nepomuk
3,112 Expert 2GB
This looks like a scope problem. Try defining the Objects submit and timeprocessed outside of the constructor and just initializing them inside:
Expand|Select|Wrap|Line Numbers
  1.  //...
  2.  
  3. private JButton submit;
  4. private JLabel timeprocessed;
  5.  
  6. public class Group2 extends JFrame implements ActionListener{
  7.  
  8. public void Group2(){
  9.         //...
  10.         submit=new JButton("Submit");
  11.         String listboxitems[]={"5","1111111","111111111","1111111111"};
  12.         JList listbox = new JList(listboxitems);
  13.         timeprocessed=new JLabel("It x milliseconds to process the output");
  14.         //...
  15. }
  16. public void actionPerformed(ActionEvent ae){
  17. if(ae.getSource()==submit){
  18.         timeprocessed.setVisible(true);}
  19. else{
  20. System.out.println("error");
  21. }
  22.          }
  23.     //...
  24. }
Greetings,
Nepomuk
Oct 19 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Bjorn Jensen | last post by:
Hi! An beginner question: Pleas help me with this (-: Error (the arrow points on the s in sqrt) ===== tal.java:6: cannot find symbol symbol : method sqrt(int) location: class tal...
1
by: Shiva48 | last post by:
Thanks to Gannon11 and ro351988- Moderator. I give below the complete Java file and pls help me to rectify the errors. package com.wrox.proj2ee.ch10.app; import java.io.*; import...
2
by: blkcygnus | last post by:
im trying to learn simple image processing-but i cant even get the thing to draw onscreen! heres the code import java.awt.*; import java.awt.geom.*; import java.awt.image.*; import...
4
by: jingchua | last post by:
Hi, can anyone help out here???? I have the below error after compling the file. Any idea what is wrong in the declaration that was done in the above code??? Appreciate any help on shedding some...
2
by: jazzyme2 | last post by:
New to Java. Working on this and ran into this problem. Any clues? java:42: cannot find symbol symbol : constructor Pay() location: class Pay Pay Emp1 = new Pay(); ^ 43:...
2
by: karinmorena | last post by:
I'm having 4 errors, I'm very new at this and I would appreciate your input. The error I get is: Week5MortgageGUI.java:151:cannot find symbol symbol: method allInterest(double,double,double)...
10
by: CodeNoob | last post by:
please help been working on a project got it down to 5 errors from 100 now i have no idea what to do. Errors: init: deps-jar: Created dir: C:\Users\Tommy\Desktop\build\classes Compiling 306...
2
suzee_q00
by: suzee_q00 | last post by:
Compiler seems to be hanging up on "new" but I know it isn't but I can't seem to figure out what it is that it doesn't like. Been chasing my tail for the last couple of days. Any help would be...
4
by: LadiPrather | last post by:
These error say there is not symbols, I have changed them some many times till I am lost. Please someone help. JOptionPane.showMessageDialog(null,"Oringinal Balance = $" + recieveAmount + ...
1
by: monkey0525 | last post by:
I'm writing a program that reads information from three seperate classes. Here is my code: public class Animal { protected int id; protected String type; protected double mass; ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.