Fetch the repository succeeded.
This action will force synchronization from wts286010056/JAVABASE, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
package cn.edu.shengda;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
class WordPolice implements ActionListener {
JTextField showText;
HashMap<String,String> hashtable;
WordPolice() {
hashtable=new HashMap<String,String>();
hashtable.put("grandness", "伟大");
hashtable.put("swim", "游泳");
}
public void setJTextField(JTextField showText) {
this.showText=showText;
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() instanceof JButton){
System.out.println("按钮被点击");
}else{
String englishWord=e.getActionCommand();
if (hashtable.containsKey(englishWord)) {
String chineseWord = hashtable.get(englishWord);
showText.setText(chineseWord);
} else {
showText.setText("没有此单词");
}
}
}
}
class WindowWord extends JFrame {
JTextField inputText,showText;
WordPolice police; //监视器
WindowWord() {
setLayout(new FlowLayout());
inputText=new JTextField(6);
showText=new JTextField(6);
add(inputText);
add(showText);
for(int i=0;i<10;i++){
JButton button=new JButton("按钮"+i);
button.addActionListener(police);
add(button);
}
police=new WordPolice();
police.setJTextField(showText);
inputText.addActionListener(police);
setBounds(100,100,400,280);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
public class Example15_7 {
public static void main(String args[]) {
WindowWord win=new WindowWord();
win.setTitle("英-汉小字典");
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。