473,606 Members | 2,115 Online
Bytes | Software Development & Data Engineering Community
+ 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 1259
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
2312
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 going to use .Net......I highly recommend signing up for the free KBAlertz newsletter at http://www.kbalertz.com/default.aspx. Looking at all of the errors and quirks sometimes makes me wonder if this thing is really ready for prime time.
1
3036
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
3996
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 2000. Of course there were no modifications made to the queries and they noticed significant performance issues. They recently upgraded the application to Access XP expecting the newer version to provide performance benefits and now queries take...
5
1684
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 2000. Of course there were no modifications made to the queries and they noticed significant performance issues. They recently upgraded the application to Access XP expecting the newer version to provide performance benefits and now queries take...
16
2518
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 uses IE to talk with a server. The user on the client (IE) sees an ASP net page containing a TextBox. He can write some text in this text box and push a submit button.
0
8009
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7939
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
8428
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...
1
8078
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8299
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5962
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
3919
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
1548
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1285
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.