一个采用Java Socket编程实现的C/S模式的记单词软件

源代码在线查看: user2.java

软件大小: 966 K
上传用户: leaveyourjam
关键词: Socket Java 编程实现 模式
下载地址: 免注册下载 普通下载 VIP

相关代码

				package clientport;
				
				import java.awt.event.ActionEvent;
				import java.awt.event.ActionListener;
				import java.util.Vector;
				import javax.swing.JFrame;
				import javax.swing.JTextArea;
				import javax.swing.JTextField;
				
				public class user2 extends JFrame implements ActionListener {
				    private Vector changevector;
				    private ClientPort st;
				    private javax.swing.JButton QUIT;
				    private java.awt.Button button1;
				    private javax.swing.JTextArea explain;
				    private javax.swing.JButton jButton1;
				    private javax.swing.JButton jButton2;
				    private javax.swing.JButton jButton3;
				    private javax.swing.JButton jButton4;
				    private javax.swing.JComboBox jComboBox2;
				    private javax.swing.JScrollPane jScrollPane1;
				    private javax.swing.JScrollPane jScrollPane2;
				    private java.awt.Panel panel1;
				    private javax.swing.JTextField word;
				    private javax.swing.JComboBox wordc;
				    private javax.swing.JTextArea wordlist;
				    private javax.swing.JLabel jLabel1;
				    private javax.swing.JLabel jLabel2;
				    private javax.swing.JLabel jLabel3;
				    private javax.swing.JComboBox jComboBox1;
				    private int state;
				    private String wordtype;
				   
				    public user2(ClientPort str) {     
				        super("系统管理员界面");
				        st = str; 
				        state = 0;
				        word = new javax.swing.JTextField();
				        jScrollPane1 = new javax.swing.JScrollPane();
				        wordlist = new javax.swing.JTextArea();
				        jButton1 = new javax.swing.JButton();
				        QUIT = new javax.swing.JButton();
				        jComboBox2 = new javax.swing.JComboBox();
				        jScrollPane2 = new javax.swing.JScrollPane();
				        explain = new javax.swing.JTextArea();
				        button1 = new java.awt.Button();
				        panel1 = new java.awt.Panel();
				        wordc = new javax.swing.JComboBox();
				        jButton2 = new javax.swing.JButton();
				        jButton4 = new javax.swing.JButton();
				        jButton3 = new javax.swing.JButton();
				         jLabel1 = new javax.swing.JLabel();
				        jLabel2 = new javax.swing.JLabel();
				        jComboBox1 = new javax.swing.JComboBox();
				        jLabel3 = new javax.swing.JLabel();
				        changevector = new Vector();
				        this.setBounds(150,200,600,360);
				         wordtype = "n";
				        /////////////////创建窗体中的组件////////////////////////
				        
				        jButton1.addActionListener(this);
				        jButton2.addActionListener(this);
				        jButton3.addActionListener(this);
				        jButton4.addActionListener(this);
				        QUIT.addActionListener(this);
				        jComboBox2.addActionListener(this);
				        wordc.addActionListener(this);
				        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);//完成事件监听添加
				
				        wordlist.setColumns(20);
				        wordlist.setRows(5);
				        jScrollPane1.setViewportView(wordlist);
				        jButton1.setText("\u56de\u5230\u4e0a\u4e00\u7ea7");
				        QUIT.setText("\u9000\u51fa");
				        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] {"\u64cd\u4f5c\u7c7b\u578b","\u5220\u9664\u5355\u8bcd", "\u5f55\u5165\u65b0\u8bcd" }));
				        explain.setColumns(20);
				        explain.setRows(5);
				        jScrollPane2.setViewportView(explain);
				        button1.setBackground(new java.awt.Color(236, 233, 216));
				        button1.setEnabled(false);
				        javax.swing.GroupLayout panel1Layout = new javax.swing.GroupLayout(panel1);
				        panel1.setLayout(panel1Layout);
				        panel1Layout.setHorizontalGroup(
				                panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				                .addGap(0, 181, Short.MAX_VALUE)
				                );
				        panel1Layout.setVerticalGroup(
				                panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				                .addGap(0, 109, Short.MAX_VALUE)
				                );
				        wordc.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "noun.", "vt.", "vi.", "adj.", "adv.", "prep.", "pron.", "conj.", "num.", "inter.", "non." }));
				        jButton2.setText("\u786e\u8ba4\u64cd\u4f5c");
				        jButton4.setText("\u53d6\u6d88\u64cd\u4f5c");
				        jButton3.setText("\u4fee\u6539\u5bc6\u7801");
				        jLabel1.setText("\u5df2\u5f55\u5165\u5355\u8bcd\uff1a");
				        jLabel2.setText("\u5f55\u5165\u4e2d\u6587\u91ca\u4e49\uff1a");
				        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] {"CET4\u5355\u8bcd\u5e93", "CET6\u5355\u8bcd\u5e93" }));
				        jLabel3.setText("\u5355\u8bcd\u7ea7\u522b");
				        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
				        getContentPane().setLayout(layout);
				        layout.setHorizontalGroup(
				                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				                .addGroup(layout.createSequentialGroup()
				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				                .addGroup(layout.createSequentialGroup()
				                .addComponent(word, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
				                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
				                .addComponent(wordc, 0, 0, Short.MAX_VALUE))
				                .addGroup(layout.createSequentialGroup()
				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
				                .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
				                .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 155, Short.MAX_VALUE))
				                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
				                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				                .addGroup(layout.createSequentialGroup()
				                .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
				                .addGap(88, 88, 88))
				                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
				                .addGroup(layout.createSequentialGroup()
				                .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
				                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
				                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)))
				                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				                .addGroup(layout.createSequentialGroup()
				                .addComponent(jButton1)
				                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
				                .addComponent(QUIT))
				                .addGroup(layout.createSequentialGroup()
				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				                .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
				                .addComponent(jButton2))
				                .addGap(16, 16, 16)
				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
				                .addComponent(jButton3)
				                .addComponent(jButton4)))
				                .addComponent(panel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
				                .addComponent(button1, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE))
				                .addContainerGap())
				                );
				        layout.setVerticalGroup(
				                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				                .addGroup(layout.createSequentialGroup()
				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
				                .addComponent(word, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
				                .addComponent(wordc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
				                .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
				                .addComponent(jButton3)
				                .addComponent(jLabel3)
				                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
				                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 6, Short.MAX_VALUE)
				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
				                .addComponent(jLabel2)
				                .addComponent(jLabel1))
				                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
				                .addGroup(layout.createSequentialGroup()
				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
				                .addComponent(jButton2)
				                .addComponent(jButton4))
				                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
				                .addComponent(button1, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
				                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
				                .addComponent(panel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
				                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
				                .addComponent(jButton1)
				                .addComponent(QUIT)))
				                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE)
				                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE))
				                .addContainerGap(35, Short.MAX_VALUE))
				                );
				    }
				    public JTextField getTextfield(){
				        return word;
				    }
				    public JTextArea getwordlist(){
				        return wordlist;
				    }
				    public JTextArea getworexplan(){
				        return explain;
				    }
				    public int getstate(){
				        return state;
				    }
				    public String getString(){
				        return word.getText().trim();
				    }
				    public Vector getVector(){
				        return changevector;
				    }
				    public void actionPerformed(ActionEvent e) {
				        String worddegree1 = "5";
				        int worddegree = 5;
				       
				        if(e.getSource()==jButton1){
				            st.getLogin().setVisible(true);
				            this.setVisible(false);}
				        
				        if(e.getSource()==jButton2){//点击确认操作,网络将所作修改传至数据库
				            String sent= null;
				        for(int i = 0; i				                word words = (word)changevector.get(i);
				               sent = sent + words.getWordName()+" "+ words.getWordtype()+ " " +words.getWordmeanse()+" "+ words.getWorddegree() + " "+words.gettype()+" ";
				        }
				            st.SentMessage("121"+ sent +" ");
				        }
				        if(e.getSource()==jButton3){
				           st.getPassword().setVisible(true);
				        }
				        if(e.getSource()==jButton4){
				            wordc.setSelectedIndex(0);
				            changevector.removeAllElements();
				            word.setText(null);
				            wordlist.setText(null);
				            explain.setText(null);
				        }
				        if(jComboBox1.getSelectedIndex()==0)
				           worddegree1 = "4";
				        if(jComboBox1.getSelectedIndex()==1)
				           worddegree1 = "6";
				        if(jComboBox2.getSelectedIndex()==1){
				            String Deletword = "120"+word.getText().trim()+" "+ wordtype +" ";
				            System.out.println(Deletword);
				            st.SentMessage(Deletword);
				            //wordlist.append(word.getText()+"     删除");
				            state = jComboBox2.getSelectedIndex();
				            jComboBox2.setSelectedIndex(0);
				            changevector.add(new word(word.getText().trim(),wordtype,worddegree1,"a",1));
				        }                
				        if(jComboBox2.getSelectedIndex()==2){
				            String Deletword = "120"+word.getText().trim()+" "+ worddegree1 +" ";
				            st.SentMessage(Deletword);
				            //wordlist.append(word.getText()+"     录入");
				            state = jComboBox2.getSelectedIndex();
				            jComboBox2.setSelectedIndex(0);
				            changevector.add(new word(word.getText().trim(),wordtype,worddegree1,word.getText().trim(),2));
				        }           
				        if(wordc.getSelectedIndex()==0)
				             wordtype ="n";
				        if(wordc.getSelectedIndex()==1)
				             wordtype = "vt";
				        if(wordc.getSelectedIndex()==2)
				             wordtype = "vi";
				        if(wordc.getSelectedIndex()==3)
				             wordtype = "a";
				        if(wordc.getSelectedIndex()==4)
				             wordtype ="ad";
				        if(wordc.getSelectedIndex()==5)
				             wordtype ="prep";
				        if(wordc.getSelectedIndex()==6)
				             wordtype = "pron";
				        if(wordc.getSelectedIndex()==7)
				             wordtype = "conj";
				        if(wordc.getSelectedIndex()==8)
				             wordtype ="num";
				        if(wordc.getSelectedIndex()==9)
				             wordtype ="inter";
				        if(wordc.getSelectedIndex()==10)
				             wordtype = "non" ;
				        if(e.getSource()==QUIT){
				        System.exit(0);
				        //如果有信息改动,网络和数据库保存对相关信息的操作}
				           
				    }
				    
				}
				    
				}
							

相关资源