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? - import java.awt.*;
-
import java.awt.event.*;
-
-
public class GuiClass extends Frame {
-
TextField text = new TextField(20);
-
Button b;
-
-
-
public static void main(String[] args) {
-
GuiClass myWindow = new GuiClass("My first window");
-
myWindow.setSize(350,100);
-
myWindow.setVisible(true);
-
}
-
-
public GuiClass(String title) {
-
-
super(title);
-
setLayout(new FlowLayout());
-
b = new Button("Click me");
-
add(b);
-
add(text);
-
b.addActionListener(ActionClass);
-
-
}
-
-
-
}
-
*************** *************** *************** ******* - import java.awt.*;
-
import java.awt.event.*;
-
-
public class ActionClass implements ActionListener{
-
private int numClicks = 0;
-
public void actionPerformed(ActionEvent e) {
-
numClicks++;
-
text.setText("Button Clicked " + numClicks + " times");
-
}
-
-
}
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? - import java.awt.*;
-
import java.awt.event.*;
-
-
public class GuiClass extends Frame {
-
TextField text = new TextField(20);
-
Button b;
-
-
-
public static void main(String[] args) {
-
GuiClass myWindow = new GuiClass("My first window");
-
myWindow.setSize(350,100);
-
myWindow.setVisible(true);
-
}
-
-
public GuiClass(String title) {
-
-
super(title);
-
setLayout(new FlowLayout());
-
b = new Button("Click me");
-
add(b);
-
add(text);
-
b.addActionListener(ActionClass);
-
-
}
-
-
-
}
-
*************** *************** *************** ******* - import java.awt.*;
-
import java.awt.event.*;
-
-
public class ActionClass implements ActionListener{
-
private int numClicks = 0;
-
public void actionPerformed(ActionEvent e) {
-
numClicks++;
-
text.setText("Button Clicked " + numClicks + " times");
-
}
-
-
}
Your line #22 should look like this: -
b.addActionListener(new ActionClass());
-
... 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
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?
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?
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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.
|
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
|
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...
|
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...
|
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.
| |
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
| |
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |