简体   繁体   中英

running JavaScript from Java?

very new to coding and decided to start a project of mine. I watched a video on how to get it set up and started but after tinkering with it a little, I realized it was Java, not JavaScript. (Hey, i'm a noob at this) and I wanted an easier way to implement new things. this is what my main script looks like.

public void onMessage(String Message){
if(message.equals("Apples"){
sendMessage("You said apples!")}
else { 
if(message.equals("Oranges" //any text 
){
    sendMessage("you said Oranges and" //what they put for any text
)
 ...

Is there a way to take the bit that says Oranges and replace it by calling a JS function from another file?

Java and javascript are two completely different things. Java is a full programming language while Javascript is used to make websites dynamic , so it works inside a webbrowser. You should figure what you want and make a choice.

As others said, you need to figure out what you want.

Nevertheless, it is possible to run Javascript in java. Check javax.script package and check the docs: http://docs.oracle.com/javase/6/docs/technotes/guides/scripting/programmer_guide/index.html#evalfile

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM