在Android上运行标准Java代码 [英] Running a standard Java code on Android
本文介绍了在Android上运行标准Java代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Android上运行我的Java代码。但我对活动并不熟悉。如何在活动上调用WordPuzzle?
I want to run my Java code on Android. But I'm not familiar with Activities. How can I call WordPuzzle on an Activity?
Android活动:
Android activity:
public class Puzzle extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
Java代码:
public class WordPuzzle {.....
public Set<String> findWords(char[][] puzzle, Set<String> words) {.....
private int findMinimumWordLength(Set<String> words) {.....
private Set<String> findPossibleWords(char[][] puzzle, int minimumWordLength) {.....
public void main(String args[]) {
WordPuzzle program = new WordPuzzle();
char[][] puzzle = {
{'F','Y','Y','H','N','R','D'},
{'R','L','J','C','I','N','U'},
{'A','A','W','A','A','H','R'},
{'N','T','K','L','P','N','E'},
{'C','I','L','F','S','A','P'},
{'E','O','G','O','T','P','N'},
{'H','P','O','L','A','N','D'}
};
Set<String> words = new HashSet<String>();
words.add("FRANCE");
words.add("POLAND");
words.add("JAPAN");
words.add("HOLLAND");
Set<String> wordsFound = program.findWords(puzzle, words);
for(String word : wordsFound) {
System.out.println(word);
}
}
}
}
推荐答案
public class Puzzle extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WordPuzzle wp = new WordPuzzle(); // you need to make main() a static function to avoid this
String args[] = {""};
wp.main(args);
}
但我不认为 System.out.println( )
将起作用,至少不在用户可以查看的位置。
将layout.main更改为 TextView
并将输出放在那里
but i dont think System.out.println()
will work, at least not where the user could view it.
Change layout.main to a TextView
and put your output there maybe
这篇关于在Android上运行标准Java代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文