import java.awt.*; import java.io.*; import javax.swing.*; public class diyiti1 { private JFrame frame; public static void main(String[] args) { diyiti1 that=new diyiti1(); that.go(); } public void go(){ int counta=0,countb=0,countc=0,countd=0,counte=0; JButton tapple,tbanana,tcat,tdog,tegg; FileInputStream a; String oldStr = ""; try { a = new FileInputStream("E:\\a.txt"); InputStreamReader br = new InputStreamReader(a); BufferedReader reader = new BufferedReader(br); String line = null; while((line = reader.readLine())!=null){ oldStr += line; } } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } char array[]=new char[oldStr.length()]; for(int j=0;j<5;j++) array[j]=oldStr.charAt(j); for(String c:){ switch(c){ case "apple":counta++;break; case "banana":countb++;break; case "cat":countc++;break; case "dog":countd++;break; case "egg":counte++;break; default:System.out.print("Wrong!"); } } frame=new JFrame("统计"); Container content=frame.getContentPane(); content.setLayout(null); tapple=new JButton("apple的个数"+counta); tbanana=new JButton("banana的个数"+countb); tcat=new JButton("cat的个数"+countc); tdog=new JButton("dog的个数"+countd); tegg=new JButton("egg的个数"+counte); //显示 tapple.setBounds(1,0,counta*100,20); tbanana.setBounds(1,20,countb*100,20); tcat.setBounds(1,40,countc*100,20); tdog.setBounds(1,60,countd*100,20); tegg.setBounds(1,80,counte*100,20); //图像 tapple.setBackground(Color.yellow); tbanana.setBackground(Color.red); tcat.setBackground(Color.blue); tdog.setBackground(Color.green); tegg.setBackground(Color.white); //botton颜色 content.add(tapple); content.add(tbanana); content.add(tcat); content.add(tdog); content.add(tegg); // frame.setSize(300,200); frame.setVisible(true); } }
- 粉丝: 0
- 资源: 2
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助