How do I get java to remember set points on a grid - eclipse

So, my assignment was to create a class with multiple animals that each moved in a certain way as practice for working with multiple objects. One that has stumped me to no end, is the "Turtle" class. The Turtle is supposed to move in a clockwise motion in a 5x5 square, first going south, then west, then north then east. It goes in one direction for 5 "steps" and then switches. so it would go south for 5 steps and then go west for 5 steps, etc. My problem right now is that it only goes in a diagonal line going northeast whenever I try to run the code.Anyway, here's the code I needed to work with:
This is the main method:
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
public class AnimalSimulator {
public static void main(String[] args) {
DrawingPanel forest = new DrawingPanel(720, 640);
Graphics2D pen = forest.getGraphics();
Animal [] animals = new Animal[15];
for (int i = 0; i < animals.length;i++){
//int selection = (int) (Math.random()*6+1);
int randX = (int) (Math.random()*720+1);
int randY = (int) (Math.random()*640+1);
Turtle t = new Turtle("Reptile", "Tortoise", new Point(randX, randY), Color.CYAN);
animals [i] = t;
}
for (int time = 1; time <= 100; time++){
for (int i = 0; i < animals.length; i++){
//System.out.println(animals[i]);
//Graphics.drawString(animals[i].toString(), animals[i].getLocation().x, animals[i].getLocation().y);
pen.setColor(animals[i].getColor());
pen.fillRect(animals[i].getLocation().x, animals[i].getLocation().y, 10,10);
animals[i].move();
for (int a = 0; a< animals.length; a++){
if(a!= i){
//if (animals[i].equals(animals[a])){
//animals[a] = null;
}
}
}
forest.sleep(50);
}
}
}
this is the turtle method:
import java.awt.Color;
import java.awt.Point;
public class Turtle extends Animal {
public Turtle(String type, String name, Point location, Color color) {
super(type, name, location, color);
// TODO Auto-generated constructor stub
}
#Override
public String toString() {
return "T";
}
#Override
public void move() {
int newX = getLocation().x+3;
int negX = getLocation().x-3;
int newY = getLocation().y+3;
int negY = getLocation().y-3;
for(int i = 1; i <= 5; i++){
setLocation(new Point(getLocation().x, newY));
}
for(int i = 1; i <= 5; i++){
setLocation(new Point(negX, getLocation().y));
}
for(int i = 1; i <= 5; i++){
setLocation(new Point(getLocation().x, negY));
}
for(int i = 1; i <= 5; i++){
setLocation(new Point(newX, getLocation().y));
}
}
}
and finally, we have the animal class that turtle extends into:
import java.awt.Color;
import java.awt.Point;
public abstract class Animal {
private String type;
public Animal(String type, String name, Point location, Color color) {
super();
this.type = type;
this.name = name;
this.location = location;
this.color = color;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
private String name;
private Point location;
private Color color;
public abstract String toString();
public abstract void move ();
public Point getLocation() {
return location;
}
public void setLocation(Point location) {
this.location = location;
}
}
I know that's a lot to sift through and I'm sorry if I'm not allowed to post questions about something this complex. I've just been running around in circles inside my head and I decided to ask other peoples opinions. Oh yeah, I'm using eclipse as well. Thank you for taking a look!

The problem is with your move method. All the new points are being set before the image can be repainted. Add the following to the Turtle class.
public class Turtle extends Animal {
private int steps=0;
And then replace the move method with:
#Override
public void move() {
if(steps<5)
setLocation(new Point(getLocation().x+3, getLocation().y));
else if(steps<10)
setLocation(new Point(getLocation().x, getLocation().y+3));
else if(steps<15)
setLocation(new Point(getLocation().x-3, getLocation().y));
else
setLocation(new Point(getLocation().x, getLocation().y-3));
steps++;
if(steps>=20)
steps=0;
}
Here, the position is only being re-evaluated every time the repaint function is called.

Related

Item in ScrollView is not seen in Scene, but it shows in hierarchy

I am trying to display a list, generated dinamically. I created a prefab with the things I need in it (a TextView, 3 TMP_InputFields and 2 Buttons.)
To manage the different list items, I created a script (SkillManager, since the items represents skill the player can choose), which I attached to the prefab.
Then, I add every item (currently I am adding only one for testing purposes) to a List, iterate that list, and add the prefab to the Content of a ScrollView:
for(int i = 0; i < listaSkills.Count; i++)
{
GameObject listItem = Instantiate(SkillPrefab) as GameObject;
listItem.GetComponent<SkillManager>().skill = listaSkills[i];
//listItem.transform.SetParent(SkillsContent.transform, false);
listItem.transform.parent = SkillsContent.transform;
}
When I run this, no item is seen in the ScrollView, but I can see the SkillItem added to the hierarchy:
If I move to Scene tab after playing, I see a square with red lines crossing it:
Why is my item not displaying? Why the red cross? How can I populate my ScrollView?
EDIT:
This is the code of SkillManager, the script added to SkillPrefab:
public class SkillManager : MonoBehaviour
{
public TMP_InputField toSpend;
public TMP_InputField rangos;
public TMP_InputField modificadores;
public TMP_InputField total;
public Button plusButton;
public Button minusButton;
public TMP_Text nombre;
public Skill skill;
private int modificador;
private int pointsToSpend;
private int totalPoints;
// Start is called before the first frame update
void Start()
{
print("Start");
if(total!=null)
total.text = "0";
if(modificadores!=null)
modificadores.text = "0";
if (toSpend != null)
{
toSpend.GetComponent<TMP_InputField>().text = GetSkillPoints();
totalPoints = int.Parse(total.GetComponent<TMP_InputField>().text);
pointsToSpend = int.Parse(toSpend.GetComponent<TMP_InputField>().text);
}
else
{
GameObject GameObjectToSpend = GameObject.FindGameObjectWithTag("tospend");
toSpend = GameObjectToSpend.GetComponent<TMP_InputField>();
if (toSpend == null)
{
print("Sigue siendo nulo");
}
else
{
toSpend.text= GetSkillPoints();
//totalPoints = int.Parse(total.GetComponent<TMP_InputField>().text);
if(total!=null)
totalPoints = int.Parse(total.text);
if(toSpend!=null)
pointsToSpend = int.Parse(toSpend.text);
}
}
if (skill != null)
{
modificador = GetModificador(skill);
string sModificador = modificadores.GetComponent<TMP_InputField>().text;
int iModificador = int.Parse(sModificador);
modificadores.GetComponent<TMP_InputField>().text = iModificador.ToString();
}
if (plusButton != null)
{
plusButton.onClick.AddListener(PlusButtonClicked);
minusButton.onClick.AddListener(MinusButtonClicked);
}
}
private string GetSkillPoints()
{
return "1";
}
public void MinusButtonClicked()
{
string ranks = rangos.GetComponent<TMP_InputField>().text;
int ranksInt = int.Parse(ranks);
if (ranksInt > 0)
{
int newRank = ranksInt - 1;
pointsToSpend += 1;
rangos.GetComponent<TMP_InputField>().text = newRank.ToString();
toSpend.GetComponent<TMP_InputField>().text = pointsToSpend.ToString();
total.GetComponent<TMP_InputField>().text = (newRank + modificador).ToString();
skill.Puntos = newRank;
}
}
public void PlusButtonClicked()
{
string ranks=rangos.GetComponent<TMP_InputField>().text;
int ranksInt = int.Parse(ranks);
Character character = Almacen.instance.Character;
int level = character.CharacterLevel;
if (ranksInt < level && pointsToSpend > 0)
{
int newRank = ranksInt + 1;
rangos.GetComponent<TMP_InputField>().text = newRank.ToString();
pointsToSpend -= 1;
toSpend.GetComponent<TMP_InputField>().text = pointsToSpend.ToString();
total.GetComponent<TMP_InputField>().text = (newRank + modificador).ToString();
skill.Puntos = newRank;
}
}
private int GetModificador(Skill skill)
{
int retorno=0;
if (skill.Clasea)
{
retorno += 3;
}
else
{
retorno += 0;
}
retorno += GetModificadorCaracteristica();
return retorno;
}
private int GetModificadorCaracteristica()
{
Utils utils = new Utils();
int retorno = 0;
int characteristic=0;
switch (skill.Caracteristica)
{
case "Fue":
characteristic = Almacen.instance.Character.EffectiveStr;
break;
case "Des":
characteristic = Almacen.instance.Character.EffectiveDex;
break;
case "Con":
characteristic = Almacen.instance.Character.EffectiveCon;
break;
case "Int":
characteristic = Almacen.instance.Character.EffectiveInt;
break;
case "Sab":
characteristic = Almacen.instance.Character.EffectiveWis;
break;
case "Car":
characteristic = Almacen.instance.Character.EffectiveCha;
break;
}
retorno = utils.GetCharModifier(characteristic);
return retorno;
}
}
it looks like you instantiate the object as a GameObject. but this will not be seen in the canvas because it isn't a UI component. you may want to add a sprite or image to the component and instantiate that into the Canvas. it will look something like this:
public class SkillPrefab
{
//put all your variables here!!!
public Sprite skillSprite;
}
public class YourClassName : MonoBehaviour
{
[SerializeField]
public List<SkillPrefab> skills = new List<SkillPrefab>();
private void Update()
{
Sprite listItem = Instantiate(skills[0].skillSprite); //the index is the skill you want to spawn in the list.
}
}
this does take into account that you have made your skills into a list of skills that you can acces.

How do I create entities from an archetype that are renderable

Im playing around with the new DOTS packages.
One thing i have not managed to do is use an archetype to create an entity that is visible in the scene. This is what I have so far, I can see the entities being created in the entity debugger, but they are not rendered. Any help is appreciated. I guess i'm missing some component on the archetype.
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
public class CreateStuff : MonoBehaviour
{
public int CountX = 100;
public int CountY = 100;
void Start()
{
var entityManager = World.Active.EntityManager;
var archetype = entityManager.CreateArchetype(typeof(Translation), typeof(Scale), typeof(Rotation), typeof(MeshRenderer), typeof(MeshFilter));
for (int x = 0; x < CountX; x++)
{
for (int y = 0; y < CountY; y++)
{
var instance = entityManager.CreateEntity(archetype);
var position = transform.TransformPoint(new float3(x - CountX / 2, noise.cnoise(new float2(x, y) * 0.21F) * 10, y - CountY / 2));
entityManager.SetComponentData(instance, new Translation() { Value = position });
entityManager.SetComponentData(instance, new Scale() { Value = 1 });
}
}
}
}
I am not sure if you are still looking for an answer. This is how I managed to get it working.
[SerializeField] private Mesh _mesh;
[SerializeField] private Material _mat;
private void Start()
{
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
EntityArchetype entityArchetype = entityManager.CreateArchetype(
typeof(RenderMesh),
typeof(LocalToWorld),
typeof(RenderBounds),
);
// create 100 entities
NativeArray<Entity> entityArray = new NativeArray<Entity>(100, Allocator.Temp);
entityManager.CreateEntity(entityArchetype, entityArray);
for (int i = 0; i < entityArray.Length; i++)
{
Entity entity = entityArray[i];
entityManager.SetSharedComponentData(entity, new RenderMesh
{
mesh = _mesh,
material = _mat,
});
}
entityArray.Dispose();
}
I did this by following this tutorial on youtube.
you can use the GameObjectConversionUtility
public GameObject Prefab;
var prefab = Unity.Entities.GameObjectConversionUtility.ConvertGameObjectHierarchy(Prefab, World.Active);
var entityManager = World.Active.EntityManager;
var instance = entityManager.Instantiate(prefab);
And if your Prefab has a renderer it will automagicly have one when it's an entity
If you haven't, do check out the ECS examples: https://github.com/Unity-Technologies/EntityComponentSystemSamples
There is no problem with code itself.
I had same problem and First of all u have to install "Hybrid Renderer" (Windeow=> Package Manager=> Advanced => Show preview pacages => Hybrid Renderer)
My code works fine. You can instantiate objects from entities and prefabs
public class ECSObjectSpawner : MonoBehaviour
{
public static ECSObjectSpawner instance;
private World _defaultWorld;
private EntityManager _entityManager;
public List<FromGameObject> fromGameObjects;
private Dictionary<string, Entity> _convertedFromGo;
public List<FromEntity> fromEntities;
private Dictionary<string, FromEntity> _generatedFromEntity;
private void Awake()
{
instance = instance ?? this;
_convertedFromGo = new Dictionary<string, Entity>();
_generatedFromEntity = fromEntities.ToDictionary(x => x.prefabName, x=>x);
}
void Start()
{
// setup references to World and EntityManager
_defaultWorld = World.DefaultGameObjectInjectionWorld;
_entityManager = _defaultWorld.EntityManager;
GameObjectConversionSettings settings = GameObjectConversionSettings.FromWorld(_defaultWorld, null);
_convertedFromGo = fromGameObjects.ToDictionary(x => x.prefabName, x=> GameObjectConversionUtility.ConvertGameObjectHierarchy(x.gameObjectPrefab, settings));
}
public void Instantiate(string key, float3 position, quaternion rotation)
{
if (_generatedFromEntity.TryGetValue(key, out FromEntity fromEntity))
{
InstantiateFromEnity(position, rotation, fromEntity);
return;
}
if (_convertedFromGo.TryGetValue(key, out Entity entity))
{
InstantiateFromGameObject(position, rotation, entity);
return;
}
}
private void InstantiateFromEnity(float3 position, quaternion rotation, FromEntity fromEntity)
{
EntityArchetype archetype = _entityManager.CreateArchetype(
typeof(Translation),
typeof(Rotation),
typeof(RenderMesh),
typeof(RenderBounds),
typeof(LocalToWorld)
);
Entity myEntity = _entityManager.CreateEntity(archetype);
_entityManager.AddComponentData(myEntity, new Translation
{
Value = position
});
_entityManager.AddComponentData(myEntity, new Rotation
{
Value = rotation
});
_entityManager.AddSharedComponentData(myEntity, new RenderMesh
{
mesh = fromEntity.unitMesh,
material = fromEntity.unitMaterial
});
}
private void InstantiateFromGameObject(float3 position, quaternion rotation, Entity entity)
{
Entity myEntity = _entityManager.Instantiate(entity);
_entityManager.SetComponentData(myEntity, new Translation
{
Value = position
});
_entityManager.SetComponentData(myEntity, new Rotation
{
Value = rotation
});
}
}
[System.Serializable]
public sealed class FromGameObject
{
public string prefabName;
public GameObject gameObjectPrefab;
}
[System.Serializable]
public sealed class FromEntity
{
public string prefabName;
public Mesh unitMesh;
public Material unitMaterial;
}

How to spawn an object using the FlyWeight Pattern

So I've been setting up this test to implement the flyweight pattern. It's where I create an object class and a factory to basically spawn the same kind of object with different properties, in this case, color, size, and shape. So I have a dropdown menu for each property and a button to create the object. I want to use the getobject function in the factory class to create the object, but I can't seem to create it right. I got the shape, but not the color or size. It has something to do with the parameters I set up for the function. I don't want to just do what I'm doing right now to spawn cubes and cylinders. That's just a test. If anyone could come up with a way around this, I appreciate it thank you.
public class FlyWeight : MonoBehaviour
{
public Button CreateButton;
List<string> colors = new List<string>() { "Choose Color", "Red", "Blue", "Green" };
List<string> shapes = new List<string>() { "Choose Shape", "Sphere", "Cube", "Cylinder" };
List<string> sizes = new List<string>() { "Choose Size", "Small", "Medium", "Large" };
public Dropdown Shapes;
public Dropdown Colors;
public Dropdown Sizes;
private void Start()
{
Button button = CreateButton.GetComponent<Button>();
Shapes.AddOptions(shapes);
Colors.AddOptions(colors);
Sizes.AddOptions(sizes);
}
public void TaskOnClick()
{
if (Shapes.value == 1)
{
var sphere= Factory.getObject(GameObject.CreatePrimitive(PrimitiveType.Sphere), getSize(), getColor());
}
else if (Shapes.value == 2)
{
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.GetComponent<Renderer>().material.color = getColor();
cube.transform.localScale = getSize();
}
else if (Shapes.value == 3)
{
var cylinder = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
cylinder.GetComponent<Renderer>().material.color = getColor();
cylinder.transform.localScale = getSize();
}
}
public Color getColor()
{
if (Colors.value == 1) { return Color.red; }
else if (Colors.value == 2) { return Color.blue; }
else if (Colors.value == 3) { return Color.green; }
else return Color.white;
}
public Vector3 getSize()
{
if (Sizes.value == 1) { return gameObject.transform.localScale = new Vector3(1, 1, 1); }
else if (Sizes.value == 2) { return gameObject.transform.localScale = new Vector3(2, 2, 2); }
else { return gameObject.transform.localScale = new Vector3(3, 3, 3); }
}
}
Object Class
public class Object
{
private Color color;
private Vector3 size;
private GameObject shape;
private int x, y;
public Object (GameObject shape, Vector3 size,Color color)
{
this.color = color;
this.size = size;
this.shape = shape;
}
public void setX(int x) { this.x = x; }
public void setY(int y) { this.y = y; }
}
Factory Class
public class Factory
{
private static List<Object> objects = new List<Object>();
public static Object getObject(GameObject shape,Vector3 size, Color color)
{
Object obj = null;
if (obj == null)
{
obj = new Object(shape, size, color);
objects.Add(obj);
}
return obj;
}
}

SharedPreferences in public class - can't find value

I've been struggling to find the solution to loading some SharedPreferences values into SensorEventListener. I keep on getting blank values, null or it just crashes from example code that I found on Stackoverflow.
Here are a few of my references:
Android - How to use SharedPreferences in non-Activity class?
Android: Using SharedPreferences in a Shake Listener Class
Here is the Shake Detection code from below:
Android: I want to shake it
I'm getting these values not from a different activity, and I'd like to load them from SharedPreferences into the public class ShakeEventListener and change the static values for MIN_FORCE, MIN_DIRECTION_CHANGE and MAX_TOTAL_DURATION_OF_SHAKE to the SharedPreferences values based on the stored values.
Example of my SharedPerferences code from Motion.java:
SharedPerferences for value: MIN_FORCE
SharedPreferences spa = getSharedPreferences("ForceStore", Activity.MODE_PRIVATE);
int ValueForce = spa.getInt("Force", 15);
SharedPerferences for value: MIN_DIRECTION_CHANGE
SharedPreferences spb = getSharedPreferences("DirectionStore", MODE_PRIVATE);
int ValueDirection = spb.getInt("Direction", 2);
SharedPerferences for value: MAX_TOTAL_DURATION_OF_SHAKE
SharedPreferences spc = getSharedPreferences("ShakeStore", MODE_PRIVATE);
int ValueShake = spc.getInt("Shake", 200);
Example code from MainActivity.java:
((ShakeEventListener) mSensorListener).setOnShakeListener(new ShakeEventListener.OnShakeListener() {
public void onShake() {
// My code here to react to the Motion detected
}
}
});
}
Example code of public class ShakeEventListener:
public class ShakeEventListener implements SensorEventListener {
private static final int MIN_FORCE = 15;
private static final int MIN_DIRECTION_CHANGE = 2;
/** Maximum pause between movements. */
private static final int MAX_PAUSE_BETHWEEN_DIRECTION_CHANGE = 200;
/** Maximum allowed time for shake gesture. */
private static final int MAX_TOTAL_DURATION_OF_SHAKE = 200;
/** Time when the gesture started. */
private long mFirstDirectionChangeTime = 0;
/** Time when the last movement started. */
private long mLastDirectionChangeTime;
/** How many movements are considered so far. */
private int mDirectionChangeCount = 0;
/** The last x position. */
private float lastX = 0;
/** The last y position. */
private float lastY = 0;
/** The last z position. */
private float lastZ = 0;
/** OnShakeListener that is called when shake is detected. */
private OnShakeListener mShakeListener;
public interface OnShakeListener {
void onShake();
}
public void setOnShakeListener(OnShakeListener listener) {
mShakeListener = listener;
}
#Override
public void onSensorChanged(SensorEvent se) {
// get sensor data
//float x = se.values[0];
//float y = se.values[1];
float z = se.values[2];
// calculate movement
//float totalMovement = Math.abs(x + y + z - lastX - lastY - lastZ);
float totalMovement = Math.abs(z - lastZ);
if (totalMovement > MIN_FORCE) {
// get time
long now = System.currentTimeMillis();
// store first movement time
if (mFirstDirectionChangeTime == 0) {
mFirstDirectionChangeTime = now;
mLastDirectionChangeTime = now;
}
// check if the last movement was not long ago
long lastChangeWasAgo = now - mLastDirectionChangeTime;
if (lastChangeWasAgo < MAX_PAUSE_BETHWEEN_DIRECTION_CHANGE) {
// store movement data
mLastDirectionChangeTime = now;
mDirectionChangeCount++;
// store last sensor data
//lastX = x;
//lastY = y;
lastZ = z;
// check how many movements are so far
if (mDirectionChangeCount >= MIN_DIRECTION_CHANGE) {
// check total duration
long totalDuration = now - mFirstDirectionChangeTime;
if (totalDuration < MAX_TOTAL_DURATION_OF_SHAKE) {
mShakeListener.onShake();
resetShakeParameters();
}
}
} else {
resetShakeParameters();
}
}
}
private void resetShakeParameters() {
mFirstDirectionChangeTime = 0;
mDirectionChangeCount = 0;
mLastDirectionChangeTime = 0;
// lastX = 0;
// lastY = 0;
lastZ = 0;
}
#Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}

Calling Method by using String instead of ObjectName - Processing in Eclipse

I am trying to combine multiple sketches I had, by having them as classes in a single sketch and go through them by pressing keys.
I'm not sure I'm following the right method but I'm basically turning them on and off by using a boolean for each. I have something like:
package combiner;
public class Combiner extends PApplet {
//...
ClassNameOne s1;
ClassNameTwo s2;
//...
ClassNameNine s9;
// AllSketches //
boolean[] sketches;
int totalSketches = 9;
String str_ts = String.valueOf(totalSketches);
char char_ts = str_ts.charAt(0);
public void setup() {
size(1920, 1080);
sketches = new boolean[totalSketches];
for (int i = 0; i < sketches.length; i++) {
sketches[i] = false;
}
s1 = new ClassNameOne(this);
s2 = new ClassNameTwo(this);
//...
s9 = new ClassNameNine(this);
}
public void draw() {
//drawingEachSketchIfItsBoolean==True
if (sketches[0] == true) {
s1.run();
} else if (sketches[1] == true) {
s2.run();
//....
}
}
public void keyPressed() {
if (key >= '1' && key <= char_ts) {
String str_key = Character.toString(key);
int KEY = Integer.parseInt(str_key);
for (int i = 0; i < sketches.length; i++) {
sketches[i] = false;
}
sketches[KEY - 1] = true;
//initializingEachClassIfKeyPressed
if (KEY == 0) {
s1.init();
} else if (KEY == 1) {
s2.init();
}
//....
}
}
As you can see each Class has an .init and a .run method (used to be my setup + draw).
I was wandering if somehow I can loop to .init or .run them without having to write it once for each, something like:
for(int i=0;i<sketches.length;i++){
if(sketches[i]==true){
String str = String.valueOf(i+1);
str="s"+str; //str becomes the Object's name
??? str.run(); ???
}
}
The cleanest solution would be to create an interface Sketch, which must be implemented in your sketch classes then:
Sketch[] sketches;
int activeSketch = 0;
void setup(){
sketches = new Sketch[2];
sketches[0] = new SketchRed();
sketches[1] = new SketchGreen();
sketches[activeSketch].init();
}
void draw(){
sketches[activeSketch].draw();
}
interface Sketch{
void init();
void draw();
}
class SketchRed implements Sketch{
void init(){}
void draw(){
fill(255, 0, 0);
ellipse(width/2, height/2, 30, 30);
}
}
class SketchGreen implements Sketch{
void init(){}
void draw(){
fill(0, 255, 0);
ellipse(width/2, height/2, 30, 30);
}
}
void keyPressed(){
activeSketch++;
if(activeSketch >= sketches.length){
activeSketch = 0;
}
sketches[activeSketch].init();
}
I am not sure if the whole idea of representing different sketches as classes in a new sketch is really that good, but in any case there seems to be a possibilty in Java for obtaining a class from a String! Look for Class.forName() as described here: http://docs.oracle.com/javase/tutorial/reflect/class/classNew.htm
Keep in mind that you will obtain a class from this and not an instance yet!