473,480 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

problems in a simple GUI application

65 New Member
i have two classes located in default package, and i got the following errors:
for the 1st class on line 22: ActionClass cannot be resolved
for the 2nd class on line 8: text cannot be resolved

for the first error, the two classes are public and stays in the same package so why cannot see each other?

for the second error, text variable has no access modifier (friendly access),
so it should be seen in the second class

can you help me about these issues? which points i am missing?

Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.awt.event.*;
  3.  
  4. public class GuiClass extends Frame {
  5.     TextField text = new TextField(20);
  6.     Button b;
  7.  
  8.  
  9.     public static void main(String[] args) {
  10.         GuiClass myWindow = new GuiClass("My first window");
  11.         myWindow.setSize(350,100);
  12.         myWindow.setVisible(true);
  13.     }
  14.  
  15.     public GuiClass(String title) {
  16.  
  17.         super(title);
  18.         setLayout(new FlowLayout());
  19.         b = new Button("Click me");
  20.         add(b);
  21.         add(text);
  22.         b.addActionListener(ActionClass);
  23.  
  24.     }
  25.  
  26.  
  27. }
  28.  
************************************************** **

Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.awt.event.*;
  3.  
  4. public class ActionClass implements ActionListener{
  5.     private int numClicks = 0;
  6.     public void actionPerformed(ActionEvent e) {
  7.         numClicks++;
  8.         text.setText("Button Clicked " + numClicks + " times");
  9.     }
  10.  
  11.     }
Oct 26 '07 #1
4 1254
JosAH
11,448 Recognized Expert MVP
i have two classes located in default package, and i got the following errors:
for the 1st class on line 22: ActionClass cannot be resolved
for the 2nd class on line 8: text cannot be resolved

for the first error, the two classes are public and stays in the same package so why cannot see each other?

for the second error, text variable has no access modifier (friendly access),
so it should be seen in the second class

can you help me about these issues? which points i am missing?

Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.awt.event.*;
  3.  
  4. public class GuiClass extends Frame {
  5.     TextField text = new TextField(20);
  6.     Button b;
  7.  
  8.  
  9.     public static void main(String[] args) {
  10.         GuiClass myWindow = new GuiClass("My first window");
  11.         myWindow.setSize(350,100);
  12.         myWindow.setVisible(true);
  13.     }
  14.  
  15.     public GuiClass(String title) {
  16.  
  17.         super(title);
  18.         setLayout(new FlowLayout());
  19.         b = new Button("Click me");
  20.         add(b);
  21.         add(text);
  22.         b.addActionListener(ActionClass);
  23.  
  24.     }
  25.  
  26.  
  27. }
  28.  
************************************************** **

Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.awt.event.*;
  3.  
  4. public class ActionClass implements ActionListener{
  5.     private int numClicks = 0;
  6.     public void actionPerformed(ActionEvent e) {
  7.         numClicks++;
  8.         text.setText("Button Clicked " + numClicks + " times");
  9.     }
  10.  
  11.     }
Your line #22 should look like this:

Expand|Select|Wrap|Line Numbers
  1.         b.addActionListener(new ActionClass());
  2.  
... but that's not your problem. Type 'javac' on the command line and see the
explanation of all the flags. Pay special attention to the -cp flag, the -sourcepath
flag and the -d flag. The -sourcepath flag tells javac where to find source files.
The -d flag tells javac where to store the generated class files. The -cp flag tells
javac where to find compiled class files. If you set all three flags to '.' (dot) you
can compile both your .java files as an argument '*.java' to javac.

kind regards,

Jos
Oct 26 '07 #2
stmfc
65 New Member
thanks a lot for the quick reply.
i corrected line 22, now its ok,
but still i have the "text cannot be resolved" error on line 8 of the code for the 2nd class. whats the problem here?

and i am using eclipse, do you think that i should worry about compiler flags?
Oct 26 '07 #3
r035198x
13,262 MVP
thanks a lot for the quick reply.
i corrected line 22, now its ok,
but still i have the "text cannot be resolved" error on line 8 of the code for the 2nd class. whats the problem here?

and i am using eclipse, do you think that i should worry about compiler flags?
You did not declare a variable called text in that class so it's not known. Is your first class compiling OK now? What does it look like now?
Oct 26 '07 #4
JosAH
11,448 Recognized Expert MVP
thanks a lot for the quick reply.
i corrected line 22, now its ok,
but still i have the "text cannot be resolved" error on line 8 of the code for the 2nd class. whats the problem here?

and i am using eclipse, do you think that i should worry about compiler flags?
Erm, no, if you're using Eclipse you don't have to worry about that; (you should've
told us that in your original post). You have defined a member 'text' in your GuiClass,
not in your ActionClass; so an object of ActionClass needs a reference to a GuiClass
to be able to use a 'text' variable in that first class.

kind regards,

Jos
Oct 26 '07 #5

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

Similar topics

14
2281
by: Jim Hubbard | last post by:
Are you up to speed on the difficulties in using the 1.1 .Net framework? Not if you are unaware of the 1,596 issues listed at KBAlertz (http://www.kbalertz.com/technology_3.aspx). If you are...
1
3020
by: 3f | last post by:
Hello; We have made a web application that people can download from our web site and installed on: Windows XP Windows 2000 Professional Windows 2003 Server Windows 2000 Server
5
3981
by: Scott | last post by:
I have a customer that had developed an Access97 application to track their business information. The application grew significantly and they used the Upsizing Wizard to move the tables to SQL...
5
1674
by: Scott | last post by:
I have a customer that had developed an Access97 application to track their business information. The application grew significantly and they used the Upsizing Wizard to move the tables to SQL...
16
2500
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client...
0
7041
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
7044
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
7084
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
6929
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
4481
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
2995
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...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
181
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.