Solved

J++

Posted on 1998-05-05
4
232 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
bunnyEars challenge 6 62
countX 22 69
base64 decode encode 12 96
compre toata in where clue oracle 4 41
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

744 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

15 Experts available now in Live!

Get 1:1 Help Now