• Post Reply Bookmark Topic Watch Topic
  • New Topic

Display the data on the Graphics object  RSS feed

 
Natalie Green
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

What I have to do: Use Applet to create two instances of the Employee class. Display the data on the Graphics object. Display in the applet the names and values of all of the instance variables in each instance of the class. Also display the value of any static variables.

What I'm doing:

I'm not able to display hours per week for e1 and e2. Please, give me a hint...
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

The variables e1 and e2 are local variables in the init() method (declared in lines 28 and 29). These variables do not exist outside of the init() method. The paint() method is a separate method, so the variables e1 and e2 don't exist there.

you should make e1 and e2 member variables in the EmployeeApplet class, instead of local variables in the init() method.

There's another problem with your code, but it's more a design problem. EmployeeApplet is an applet. You are not just using it as an applet, but also to hold all the data, and then you're creating multiple instances of the class to hold data. You should make a separate class Employee to hold the data. Put the getter and setter methods and the hoursPerWeek variable in that class. Then use that Employee class in your EmployeeApplet class. The variables e1 and e2 should be of type Employee, not EmployeeApplet.
 
Natalie Green
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Jesper de Jong!

I put all my getters and setters in a different class Employee and now my EmployeeApplet looks a lot better and it works!


I think I can resolve this issue. Thank you!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!