473,416 Members | 1,548 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,416 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 9824
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; ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.