Solved

J++

Posted on 1998-05-05
4
235 Views
Last Modified: 2010-04-16
import java.awt.event.*;

gives me an error, Undefined package 'event'
I use version  1.0 ?
0
Comment
Question by:admiral
  • 2
4 Comments
 

Expert Comment

by:Charmaine041198
ID: 1220585
In the awt 1.0 model, event is a class in the java.awt package so the statement should be changed to "import java.awt.event" OR "java.awt.*".
The compiler imterprets the asterisk in your code as a package name instead of a class name.

0
 

Author Comment

by:admiral
ID: 1220586
I tried the code you  gave - it would not compile
Here is all the code if it can help:

thank you

import java.awt.*;
import java.applet.*;
import java.awt.event.*;





public class ThirdMethod extends Applet implements ActionListener
{
 Label theLabel= new Label("Enter your first name");
 TextField theName= new TextField(20);
 Button pressMe = new Button("Ok");


    public void init()
    {
     add(theLabel);
     add(pressMe);
     add(theName);
     pressMe.addActionListener(this);
    }

    public void actionPerformed(ActionEvent theEvent)
    {
     String newText;
     String usersName;
     usersName= theName.getText();
     newText=getGreeting(userName);
     theLabel.setText(newText);
    }
    public String getGreeting(String Name)
    {
      String greeting;
      greeting ="Hi" + Name +"!";
      return greeting;
    }
 }

0
 

Expert Comment

by:Charmaine041198
ID: 1220587
Visual J++ 1.0/1.1 does not support Sun jdk 1.1. Your code is written with jdk 1.1 so it can't be compiled in J++.
0
 
LVL 1

Accepted Solution

by:
dufort earned 50 total points
ID: 1220588
Where did you get this example? Here's your problem: you have a JDK 1.1 examples but a JDK 1.0 development tool. Let's call it a mismatch! If you want to learn Java, you have two choices:

1. Keep using this version of J++, stick to the 1.0 model, and get examples from old Java books (I would suggest the first version of "Java in a nutchell" from O'Reilly & Associates), or:

2. Keep your book (or whatever source for your example) and find a development tool that supports the 1.1 model.

I would suggest solution #2, because you will have to do this one day or another. I guess that you could get a low-cost upgrade for J++. Or, browse a little at http://www.davecentral.com (or somewhere else) to find shareware tools such as JPad and ED4W.

By the way, just for the fun of it, here is your example "translated" in the JDK 1.0 model. I guess it will work perfectly in your version of J++.

import java.awt.*;
import java.applet.*;

public class ThirdMethod extends Applet
      {
       Label theLabel= new Label("Enter your first name");
       TextField theName= new TextField(20);
       Button pressMe = new Button("Ok");


          public void init()
          {
           add(theLabel);
           add(pressMe);
           add(theName);
          }

          public boolean handleEvent(Event e)
          {
              if((e.id == Event.ACTION_EVENT) && (e.target == pressMe))
              {
                  String newText;
                 String userName;
                  userName = theName.getText();
                  newText = getGreeting(userName);
                  theLabel.setText(newText);
                                          
                  return true;
                }
                return false;
         }
                              
          public String getGreeting(String Name)
          {
            String greeting;
            greeting ="Hi " + Name +"!";
            return greeting;
          }
}

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now