473,666 Members | 2,138 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cannot find symbol class (Java swing)

18 New Member
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
1 9878
Nepomuk
3,112 Recognized Expert Specialist
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
28812
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 System.out.println(i + ": " + sqrt(4));
1
4924
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 javax.servlet.*; import javax.servlet.http.*; import com.wrox.proj2ee.ch12.*// The requesthandlers interface in this package. public class ShowRecordRequesthandler implements RequestHandler
2
5472
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 javax.swing.*; public class imagemanip
4
5103
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 light for this error on how to rectify it. C:\Documents and Settings\wei cheng\Desktop\aa1\test.java:122: cannot find symbol symbol : method objCompare(java.lang.Object,Person) location: class test if...
2
2976
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: cannot find symbol symbol : constructor Pay() location: class Pay Pay Emp2 = new Pay();
2
6650
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) Location: class Week5MortgageGUI Week5MortgageLogic allint = logic.allInterest(amount, term, rate); Week5MortgageGUI.java:152:cannot find symbol symbol: method allInterest(double,double,double) Location: class Week5MortgageGUI
10
13071
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 source files to C:\Users\Tommy\Desktop\build\classes C:\Users\Tommy\Desktop\PlasmaMS PET\SeanSource V.5.7\src\net\sf\odinms\provider\xmlwz\FileStoredPngMapleCanvas.java:14: warning: com.sun.imageio.plugins.png.PNGImageReaderSpi is Sun proprietary API...
2
2867
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 greatly appreciated. Here's is the compiler message: InventoryItemDemo.java:9: cannot find symbol symbol : constructor InventoryItem(java.lang.String,int) location: class InventoryItem InventoryItem Item1 = new InventoryItem("Item 1", 41), ...
4
5108
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 + "\nPayment#" + x + "\nMonthly Payment$" + fixdecimal.format(payment)+ "\nRemaining Balance $" + fixdecimal.format(remainBalance) + "\nInterest Paid $" + ...
1
2430
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
8356
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8871
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7386
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5664
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2771
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.