java0004——迷你小项目--英汉小字典

本文介绍了一个使用Java编写的迷你英汉小字典项目,涵盖了流程图解析、代码设计思路以及需要注意的问题,如Scanner的next()与nextLine()方法的区别,以及父类与子类命名的注意事项。提供了Word、dictionaryFunction、LookUpDictionary和dictionaryDemo四个关键类的代码示例。
摘要由CSDN通过智能技术生成
  1. 流程图
  • 代码思路流程图
    在这里插入图片描述
  • 代码设计流程图
    在这里插入图片描述
  1. 注意的问题
  • Scanner next()与nextline()的区别 :
    一句话 nextline()可以输入空格、tab等特殊的字符,而且还可以避免在连续输入多个字符串的时候出现输入问题
  • 父类与子类在这里尽量不要重名
  1. 代码
  • Word.java
package MyDictionary;

public class Word {
    
	String eWord;
	String cWord;

	public String geteWord() {
    
		return eWord;
	}

	public void seteWord(String eWord) {
    
		this.eWord = eWord;
	}

	public String getcWord() {
    
		return cWord;
	}

	public void setcWord(String cWord) {
    
		this.cWord = cWord;
	}

	public Word(String eWord, String cWord) {
    
		this.eWord = eWord;
		this.cWord = cWord;
	}

	public Word() {
    
		this.eWord = null;
		this.cWord = null;
	}

	public String toString() {
    
		return (this.eWord + "===" + this.cWord);
	}
}
  • dictionaryFuction .java
package MyDictionary;
public class dictionaryFuction {
    
	Word[] words;
	int count;

	public dictionaryFuction() {
    
		// TODO Auto-generated constructor stub
		words = new Word[100];
		count = 0;
	}

	// 添加单词
	public boolean add(Word word) {
    
		if (count < 100) {
    
			this.words[this.count++] = word;
			return true;
		} else
			return false;
	}

	// 查询单词
	public Word searchWord(String word) {
    
		for (int i = 0; i < count; i++) {
    
			if (this.words[i].
package shiyan; import java.awt.*; import java.awt.event.*; import java.sql.*; import javax.swing.*; public class AddWin extends JFrame implements ActionListener { private static MySqlUtils mySqlUtils = new MySqlUtils(); JTextField 添加汉语解释_文本条, 添加英语单词_文本条; JButton addbtn, cancelbtn; Connection Con = null; Statement Stmt = null; public AddWin() { super("添加单词"); this.setBounds(250, 250, 250, 200); this.setVisible(true); JPanel p1 = new JPanel(); p1.add(new Label("输入要添加的单词:")); 添加英语单词_文本条 = new JTextField(20); p1.add(添加英语单词_文本条); p1.add(new Label("输入添加的单词的解释:")); 添加汉语解释_文本条 = new JTextField(20); p1.add(添加汉语解释_文本条); addbtn = new JButton("提交"); cancelbtn = new JButton("取消"); p1.add(addbtn); p1.add(cancelbtn); this.add(p1); addbtn.addActionListener(this); cancelbtn.addActionListener(this); this.validate(); } public void actionPerformed(ActionEvent e) { if (e.getSource() == addbtn) { if (添加英语单词_文本条.getText().equals("") || 添加汉语解释_文本条.getText().equals("")) { JOptionPane.showMessageDialog(this, "添加的单词或解释不能为空~", "警告", JOptionPane.WARNING_MESSAGE); } else { try { Word word = new Word(); word.setEnglish(添加英语单词_文本条.getText().toString()); word.setChinese(添加汉语解释_文本条.getText().toString()); mySqlUtils.insert(word); 添加英语单词_文本条.setText(""); 添加汉语解释_文本条.setText(""); } catch (Exception ee) { } } } else if (e.getSource() == cancelbtn) { dispose(); } } }
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值