GIT : https://gitee.com/iseekun99/word_frequency_count
16012112 | 曲梦 |
16012115 | 白惠民 |
16012119 | 胡文媛 |
16012121 | 齐洪飞 |
团队编程的过程性照片
wf 词频统计的主要代码
import javax.swing.*; import java.awt.*; import java.io.BufferedReader; import java.io.FileReader; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.TreeMap; public class wf { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new FileReader("F:\\16012119\\daima.txt")); List<String> lists = new ArrayList<String>();String readLine = null;while((readLine = br.readLine()) != null){ String[] wordsArr1 = readLine.split("[^a-zA-Z]"); for (String word : wordsArr1) { if(word.length() != 0){ lists.add(word); } } } br.close(); Map<String, Integer> wordsCount = new TreeMap<String,Integer>();for (String li : lists) { if(wordsCount.get(li) != null){ wordsCount.put(li,wordsCount.get(li) + 1); }else{ wordsCount.put(li,1); } } SortMap(wordsCount); } public static void SortMap(Map<String,Integer> oldmap){ ArrayList<Map.Entry<String,Integer>> list = new ArrayList<Map.Entry<String,Integer>>(oldmap.entrySet()); Collections.sort(list,new Comparator<Map.Entry<String,Integer>>(){ public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) { return o2.getValue() - o1.getValue(); } }); for(int i = 0; i<list.size(); i++){ System.out.println("单词是"+list.get(i).getKey()+ ",个数为"+list.get(i).getValue()+"个"); }/*JFrame window1 = new JFrame("词频统计");Container con = window1.getContentPane();con.setBackground(Color.white);window1.setBounds(60,100,800,508);window1.setVisible(true);window1.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);*//*window2.setVisible(true);window2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); */} }
Login
import java.awt.*; import javax.swing.*; public class Login extends JFrame{ JPanel jp1,jp2,jp3;//面板 JLabel jlb1,jlb2;//标签 JButton jb1,jb2;//按钮 JTextField jtf;//文本 JPasswordField jpf;//密码 public static void main(String[] args) { Login win=new Login(); } public Login(){ jp1=new JPanel(); jp2=new JPanel(); jp3=new JPanel(); //标签jlb1=new JLabel("用户名"); jlb2=new JLabel("密 码"); //按钮 jb1=new JButton("登录"); jb2=new JButton("注册"); //文本框 jtf=new JTextField(10); //密码框 jpf=new JPasswordField(10); this.setLayout(new GridLayout(3, 1));//网格式布局 //加入各个组件 jp1.add(jlb1); jp1.add(jtf); jp2.add(jlb2); jp2.add(jpf); jp3.add(jb1); jp3.add(jb2); //加入到JFrame this.add(jp1); this.add(jp2); this.add(jp3); //设置窗体 this.setTitle("用户登录");//窗体标签 this.setSize(300, 150);//窗体大小 this.setLocationRelativeTo(null);//在屏幕中间显示(居中显示) this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//退出关闭JFrame this.setVisible(true);//显示窗体 this.setResizable(false); } }
Menu
import javax.swing.JButton; import javax.swing.JFrame; import java.awt.BorderLayout; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane;public class Menu extends JFrame implements ActionListener{public static void main(String[] args) {Menu mb = new Menu();}private JButton jb;public Menu(){JFrame frm = new JFrame("词频统计");// 创建布局管理器实例border,水平间隔为5,垂直间隔为7,BorderLayout border = new BorderLayout(8, 0);// 设置frm的页面布局为border frm.setLayout(border);frm.setSize(300, 100);JButton b1 = new JButton("开始游戏");JButton b2 = new JButton("游戏菜单");frm.add(b1, BorderLayout.NORTH);frm.add(b2, BorderLayout.SOUTH);b1.addActionListener(this);//加入事件监听 frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frm.setVisible(true);}public void actionPerformed(ActionEvent e) {this.dispose();new Frm();} }
Frm
import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import java.awt.BorderLayout; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;public class Frm extends JFrame implements ActionListener{private JButton jb;public Frm(){this.setSize(300, 100);this.setLocation(400, 500);jb=new JButton("词频统计");this.add(jb);jb.addActionListener(this);//加入事件监听this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(true);}public void actionPerformed(ActionEvent e) {this.dispose();new Login();}}
本次实训让我们每个人都体会到了团队的力量,相信这一次的实训经历会成为我们以后的无论生活还是学习上的重要经验