我需要创建一个后缀查找器。以下是我编写的代码。我必须导入整个单词词典,不知道已经排序或未排序的单词以及它将使用哪种数据结构/文件类型。另外,将具有通过过滤后缀关键字来查找单词然后显示到列表的功能。
package hamqafia;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javafx.scene.text.Text;
import javax.swing.JButton;
import javax.swing.JFrame;
import static javax.swing.JFrame.EXIT_ON_CLOSE;
import javax.swing.JTextField;
/**
*
* @author Zeeshan
*/
public class HamQafia {
private static JTextField text;
private static JFrame frame;
private static JButton findBtn;
DataStructure Dictionary_of_all_words;
public static void main(String[] args) {
// TODO code application logic here
//String[] words = {"Runner, Stealth, Gunner, male, Butter, Old, sar, gold"};
windowMaker();
}
private static void windowMaker(){
//Initializing and painting GUI components
frame = new JFrame();
text = new JTextField(20);
findBtn = new JButton("Find");
findBtn.setSize(200,200);
findBtn.setVisible(true);
frame.setSize(600, 600);
frame.setLayout(new FlowLayout());
frame.setVisible(true);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.add(text);
frame.add(findBtn);
//Click Action
findBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String postFix = text.getText().toString();
finder(postFix);
}
});
}
private static void finder(String postFix){
//Find method to search the words from entire dictionary an show them in the list.
// For example:
// postFix = ry
//Output: cry, fry, try, dry
}
}
答案 0 :(得分:0)
您可以创建String类型的数组,并存储整个英语单词词典,以逗号分隔。是的,字典应采用有序格式,以便快速查找。 这是取景器功能的一些粗略构想
private static void finder(String postFix){
for(int i=0, i<dictionaryArray.length; i++){
if(dictionaryArray[i] == postFix){
ListView.add(dictionaryArray[i]);
}
}
//Find method to search the words from entire dictionary an show them in the list.
// For example:
// postFix = ry
//Output: cry, fry, try, dry
}