Java学习期末项目词典项目完整源码Word格式.docx
《Java学习期末项目词典项目完整源码Word格式.docx》由会员分享,可在线阅读,更多相关《Java学习期末项目词典项目完整源码Word格式.docx(35页珍藏版)》请在冰豆网上搜索。
this.list=list;
publicDictionary(){
super();
publicDictionary(Wordword){
publicWordaddWord(Wordword){//1、增加单词
list.add(word);
//输出新增加的单词
returnword;
publicWordsearchWord(Stringstr){//2、查找单词
//if(input_ce!
=null)不需要判空
for(intj=0;
j<
list.size();
j++)
if((str.equals(((Word)list.get(j)).getcWord()))||((Word)list.get(j)).geteWord().equalsIgnoreCase(str))
return(Word)list.get(j);
returnnull;
}
publicStringsysoAllWrod(){//3、输出全部单词
List<
list=getList();
for(Wordword:
list)
returnword.toString();
}
publicbooleandeleWord(StringDeleword){//4、删除单词
//if(input_ce!
{for(intj=0;
if((Deleword.equals(((Word)list.get(j)).getcWord()))||((Word)list.get(j)).geteWord().equalsIgnoreCase(Deleword))
{
list.remove(list.get(j));
returntrue;
}
}
returnfalse;
publicvoidclearWord(){//5、清空单词
list.clear();
publicvoidchangeWord(inti,Stringcword,Stringeword){//6、修改单词
this.list.get(i).setcWord(cword);
this.list.get(i).seteWord(eword);
publicvoidchioceWord(inti,Wordword)
{
((Word)list).setcWord(word.getcWord());
((Word)list).seteWord(word.geteWord());
}
Swing类源代码
importjava.awt.*;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.awt.event.KeyEvent;
importjava.awt.event.KeyListener;
importjava.io.IOException;
importjavax.swing.*;
publicclassSwing{
Dictionarydictionary=newDictionary();
Toolstools=newTools();
privatestaticJFramejf;
privatestaticJFramejf_creat_add;
privatestaticJFramejf_creat_dele;
privatestaticJFramejf_creat_clear;
privatestaticFontfont;
privatestaticFontfont_2;
privatestaticJTextFieldtxtArea_1;
privatestaticJTextAreatxtArea_2;
privatestaticJTextFieldtextFieldCword;
privatestaticJTextFieldtextFieldEword;
privatestaticJTextFieldtextFieldDele;
privatestaticLabellabel_2;
privatestaticJButtonbutton_1;
privatestaticJButtonbutton_2;
privatestaticJButtonbutton_3;
privatestaticJButtonbutton_4;
privatestaticJButtonbutton_5;
privatestaticJButtonbutton_6;
privatestaticJButtonbutton_7;
privatestaticJButtonbutton_8;
privatestaticJButtonbutton_9;
privatestaticJButtonbutton_10;
privatestaticJButtonbutton_clear_ok;
privatestaticJButtonbutton_clear_no;
publicvoidCreateJFrame(Stringtitle)throwsIOException{
tools.ReadertoFile(dictionary.getList(),"
d:
/Java词典文件/文件/dic.txt"
);
jf=newJFrame(title);
//Containercontainer=jf.getContentPane();
//获取一个容器
ImageIconic=newImageIcon("
D:
\\Java词典文件\\图片\\词典背景.png"
JLabellabel=newJLabel(ic);
label.setHorizontalAlignment(SwingConstants.CENTER);
//居中
//label.setIcon(ic);
//把标签的大小位置设置为图片刚好填充整个面
label.setBounds(0,0,ic.getIconWidth(),ic.getIconHeight());
//添加图片到frame的第二层
jf.getLayeredPane().add(label,newInteger(Integer.MIN_VALUE));
//获取frame的最上层面板为了设置其背景颜色(JPanel有设置透明的方法)
JPaneljp=(JPanel)jf.getContentPane();
jp.setOpaque(false);
//设置透明
//弹窗
//JOptionPane.showMessageDialog(null,"
<
html>
B>
fontsize='
15'
>
欢迎使用英汉词典!
/font>
/B>
/html>
"
//container.setBackground(Color.white);
//背景颜色
//jf.setLayout(newBorderLayout());
//边界布局
BorderLayoutbl_1=newBorderLayout();
FlowLayoutfl_1=newFlowLayout();
//流布局
FlowLayoutfl_2=newFlowLayout();
FlowLayoutfl_3=newFlowLayout(1,20,10);
JPanelcontent_1=newJPanel(bl_1);
JPanelcontent_2=newJPanel(fl_1);
JPanelcontent_3=newJPanel(fl_2);
JPanelcontent_4=newJPanel(fl_3);
jf.setContentPane(content_1);
content_1.setOpaque(false);
content_2.setOpaque(false);
content_3.setOpaque(false);
content_4.setOpaque(false);
font=newFont("
宋体"
Font.BOLD,15);
font_2=newFont("
Font.BOLD,25);
txtArea_1=newJTextField("
20);
txtArea_2=newJTextArea(11,32);
label_2=newLabel("
请输入:
button_1=newJButton("
查询"
);
button_2=newJButton("
添加单词"
button_3=newJButton("
删除单词"
button_4=newJButton("
全部单词"
button_5=newJButton("
清空单词"
button_6=newJButton("
退出"
label_2.setFont(font);
txtArea_1.setOpaque(false);
txtArea_2.setOpaque(false);
//结果文本框透明显示
JScrollPanejspane=newJScrollPane(txtArea_2);
//带滚动条的面板
jspane.setOpaque(false);
//透明
jspane.getViewport().setOpaque(false);
//txtArea_1.setLineWrap(false);
//自动换行
//txtArea_2.setLineWrap(true);
txtArea_2.setEditable(false);
//不允许编辑
txtArea_1.setFont(font_2);
txtArea_2.setFont(font_2);
txtArea_2.setForeground(Color.white);
//文本域字体颜色
content_1.add(BorderLayout.NORTH,content_2);
content_1.add(BorderLayout.CENTER,content_3);
content_1.add(BorderLayout.SOUTH,content_4);
content_2.add(label_2);
content_2.add(txtArea_1);
content_2.add(button_1);
content_3.add(jspane);
content_4.add(button_2);
content_4.add(button_3);
content_4.add(button_4);
content_4.add(button_5);
content_4.add(button_6);
//txtArea.setBackground(Color.white);
/*jf.setLayout(newFlowLayout(0,20,13));
container.add(label_2);
container.add(txtArea_1);
container.add(button_1);
container.add(jspane);
container.add(button_2);
container.add(button_3);
container.add(button_4);
container.add(button_5);
container.add(button_6);
*/
jf.setResizable(false);
//不允许改变窗口大小
jf.setSize(578,465);
jf.setVisible(true);
//使窗体可见
jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
//关闭方式
//按钮1查询
publicvoidActionButton_1(){
button_1.addActionListener(newbutton_1Action());
classbutton_1ActionimplementsActionListener{
publicvoidactionPerformed(ActionEventarg0){
dictionary.searchWord(txtArea_1.getText());
if(dictionary.searchWord(txtArea_1.getText())!
=null){
Stringserchstring=dictionary.searchWord(txtArea_1.getText()).getcWord()+"
--"
+dictionary.searchWord(txtArea_1.getText()).geteWord();
txtArea_2.setText(serchstring);
elsetxtArea_2.setText("
没有此单词!
);
//dictionary.searchWord(txtArea_2.getText()).getcWord()+dictionary.searchWord(txtArea_2.getText()).geteWord()
publicvoidActionTxtArea_1_Mouse(){
//单击文本框
txtArea_1.addMouseListener(newjava.awt.event.MouseAdapter(){
publicvoidmouseClicked(java.awt.event.MouseEvente){
txtArea_1.setText("
});
//监听文本框按键操作
txtArea_1.addKeyListener(newKeyListener(){
publicvoidkeyTyped(KeyEvente){
//TODOAuto-generatedmethodstub
if(e.getSource()==txtArea_1)
{
dictionary.searchWord(txtArea_1.getText());
if(dictionary.searchWord(txtArea_1.getText())!
Stringserchstring=dictionary.searchWord(txtArea_1.getText()).getcWord()+"
txtArea_2.setText(serchstring);
}
elsetxtArea_2.setText("
}
publicvoidkeyReleased(KeyEvente){
publicvoidkeyPressed(KeyEvente){
}});
//按钮2新建弹窗增加单词
publicvoidActionButton_2(){
button_2.addActionListener(newbutton_2Action());
classbutton_2ActionimplementsActionListener{
publicvoidactionPerformed(ActionEventarg0){
ActionButton_6_Quit();
CreatJFrame_Add();
ActionButton_7();
ActionButton_8();
//删除单词
publicvoidActionButton_3(){
button_3.addActionListener(newbutton_3Action());
classbutton_3ActionimplementsActionListener{
publicvoidactionPerformed(ActionEventarg0){
CreatJFrame_Dele();
ActionButton_9();
ActionButton_10();
//显示全部单词
publicvoidActionButton_4(){
button_4.addActionListener(newbutton_4Action());
classbutton_4ActionimplementsActionListener{
publicvoidactionPerformed(ActionEventarg0){
Stringstr=newString();
StringBuffersBuffer=newStringBuffer();
for(intj=0;
dictionary.list.size();
j++){
str=dictionary.getList().get(j).toString();
//.getcWord()+"
+dictionary.getList().get(j).geteWord();
sBuffer.append(str+"
\n"
}
if(sBuffer.toString().length()!
=0){
txtArea_2.setText(sBuffer.toString());
词典内没有单词!
}
//清空单词
publicvoidActionButton_5(){
button_5.addActionListener(newbutton_5Action());
classbutton_5ActionimplementsActionListener{
publicvoidactionPerformed(ActionEventarg0){
CreatJFrame_Clear();
ActionButton_clear_no();
ActionButton_clear_ok();
}
//添加单词确认按钮
publicv