In Java, I would like to be able to load a method from a file. This way the user has a way to customize the method. The user could make a txt file, type a normal Java method into it, then load it into the program. I know of Reflection, but I am not aware of a way to read methods like this. The program would execute it just like it was a method built in. Is there anyway to do this?
I would like to do this so the user can customize the calculculations that create values for displaying stuff on the screen. Here is my existing method:
void setScale() {
int windowDiagonal = (int) Math.sqrt(comp.getWidth() * comp.getWidth() + comp.getHeight() * comp.getHeight());
double scale = windowDiagonal / 2500.0;
placeWidth = (int) (comp.getWidth()/2.5);//(int) (800 * scale);
arrowLineSize = (int) (20*scale);
lineSize = (int) (10*scale);
arrowSize = (int) (40*scale);
arrowHeight = (int) (100 * scale);
arrowNameGap = (int) (10 * scale);
roundRaceGap = (int) (50 * scale);
roundRaceLineGap = (int) (30 * scale);
leftLightGap = (int) (20 * scale);
lightSize = (int) (200 * scale);
lightTextGap = (int) (20 * scale);
lightToGapRatio = 5;// (int) (5 * scale);// TODO Maybe???
lineWinnerGap = (int) (10 * scale);
nameTimeGap = (int) (10 * scale);
//Bottom
lineNextUpGap = (int) (10 * scale);
nextUpNextUpTitleGap = (int) (10 * scale);
nextUpTitleNextUpGap = (int) (10 * scale);
nextUpAfterNextUpGap = (int) (10 * scale);
afterNextUpBottomGap = (int) (100 * scale);
titleRoundRaceGap = (int) (20 * scale);
topTitleGap = (int) (20 * scale);
winnerArrowGap = (int) (40 * scale);
comp.setFont(new Font("Arial", Font.BOLD, (int) (60 * scale))); //$NON-NLS-1$
}
The problem is, what if the user wants to make placeWidth, say half of the screen. What if they want it to be half of the height divided by the width? Since this would be an advanced feature of the program, I don't want to go around making text fields and radio buttons for all the different things it could do. Instead one could change the code that calculates the values so they have more freedom.