Solved

J++

Posted on 1998-05-05
4
244 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 213
servlet doXXX methods 3 62
Why my table column Id is not passed to java object? 4 44
Need Help! Getting a syntax error and don't understand why 3 31
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

828 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