⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 etian.java

📁 txt文本格式处理器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
           exit.setBounds(150,285,75,25);
           opent.setBounds(20,30,170,25);
           llt.setBounds(20,80,250,25);
           zst.setBounds(125,180,35,25);
           ts.setBounds(10,220,280,25);
           meigel.setBounds(97,180,50,25);
           fengel.setBounds(165,180,45,25);
           bq.setBounds(0,320,300,50);          //300*50
           txtwz.setBounds(25,11,95,25);
           fgwjwz.setBounds(25,61,195,25);
           wjmt.setBounds(100,140,150,25);
           wjml.setBounds(15,140,85,25);
           bh.setBounds(250,140,35,25);
           //添加组件
           c.add(openb);
           c.add(fengeb);
           c.add(exit);
           c.add(llt);
           c.add(ts);
           c.add(opent);
           c.add(zst);
           c.add(fengel);
           c.add(meigel);
           c.add(bq);
           c.add(txtwz);
           c.add(fgwjwz);
           c.add(wjmt);
           c.add(wjml);
           c.add(bh);
           
           opent.setEditable(false);    //设置打开文件文本框为不可编辑
           llt.setEditable(false);      //设置保存文件文本框为不可编辑
           
           openb.addActionListener(new ActionListener(){
     	    	  public void actionPerformed(ActionEvent e){
     	    	      JFileChooser fs=new JFileChooser();//选择文件对话框
     	    	  	  fs.setSelectedFile(file);          
     	    	  	  int rv=fs.showOpenDialog(txt.this);
     	    	  	  file=fs.getSelectedFile();       //选择文件
     	    	  	  
     	    	  	  String zz=file.getPath();//获取文件路径
     	    	  	  
     	    	  	  opent.setText(zz);       //显示打开文件路径
     	    	  	  String zx=zz.substring(0,zz.length()-4);  
   	    	     	  llt.setText(zx+"\\");    //显示分割文件保存路径
   	    	     	  ts.setText("准备就绪");
     	    	      }
     	    	  });
     	    	  
     	   fengeb.addActionListener(new ActionListener(){
     	    	  public void actionPerformed(ActionEvent e){
     	    	  	  ts.setText("正在分割");
     	    	  	  wjm=wjmt.getText();
     	    	  	  int temp=2000;
     	    	      try{
     	    	    	  String jss=zst.getText();
     	    	          temp=Integer.parseInt(jss);
     	    	          }catch(Exception xc)
     	    	              {JOptionPane.showMessageDialog(null,"分割字数错误");}
     	    	      try{  
     	    	          file=new File(llt.getText());
     	    	          file.mkdir();       //创建分割文件保存目录
     	    	          File input=new File(opent.getText());
     	    	      	  File output=new File(llt.getText()+wjm+1+".txt");
     	    	      	  FileReader in=new FileReader(input);
     	    	      	  FileWriter out=new FileWriter(output);
     	    	      	  int c,js=0;
     	    	      	  int a=2;
     	    	      	  while((c=in.read())!=-1){
     	    	      	  	  out.write(c);
     	    	      	  	  js++;
     	    	      	  	  if(js==temp){
     	    	      	  	  	  out.close();
     	    	      	  	  	  js=0;
     	    	      	  	  	  output=new File(llt.getText()+wjm+a+".txt");
     	    	      	  	  	  out=new FileWriter(output);
     	    	      	  	  	  a++;
     	    	      	  	  }
     	    	      	  }
     	    	      	  in.close();out.close();
     	    	      	  JOptionPane.showMessageDialog(null,"文件分割完成");
     	    	      	  ts.setText("文件分割完毕!");
     	    	      }catch(Exception ex){JOptionPane.showMessageDialog(null,"文件分割失败");}
     	    	     }
     	    	  });
     	   
     	   exit.addActionListener(new ActionListener(){
     	    	  public void actionPerformed(ActionEvent e){
     	    	      setVisible(false);
     	    	      }
     	    	  });
     	    	  
     	    //关闭按钮事件处理	  
     	    this.addWindowListener(new WindowAdapter(){
     	    	public void windowClosing(WindowEvent e){
     	    		    
     	    	}
     	    });
           
           setBounds(370,200,300,405); //确定窗口位置大小
           setVisible(true);   //设置窗口可见
           c.setBackground(new Color(128,200,240)); //设置窗口背景色
           setResizable(false);   //固定窗口大小
           setIconImage(Toolkit.getDefaultToolkit().createImage("image\\txt.png"));  //设置窗口图标 
   }
}     


//生成TXT to HTML 窗口
class txttohtml extends JFrame {
       Container        c;
	   JButton          openb;   //打开按钮
	   JButton          zh;      //转换按钮
	   JButton          allzh;   //全部转换按钮
	   JButton          sc;      //删除按钮
	   JButton          allsc;   //全部删除按钮
	   JButton          exit;    //退出按钮
	   JLabel           bq;     //版权图片
	   JLabel           jt       =new JLabel(new ImageIcon("image\\jt.jpg"));
	   List             lb;      //列表
	   File file=null;
	   FileDialog fd;
	   int jty=0,jta=0;   
	   public txttohtml(String ss){
	   	   super(ss);
	   	   c=getContentPane();
	       openb=new JButton("打开");
	       zh   =new JButton("转换");
	       allzh=new JButton("全部转换");
	       sc   =new JButton("删除");
	       allsc=new JButton("全部删除");
	       exit =new JButton("退出");
	       bq   =new JLabel(new ImageIcon("image\\t2h.jpg"));//版权图片
	       jt   =new JLabel(new ImageIcon("image\\jt.jpg"));
	       lb   =new List(23,false);
	       
	       c.setLayout(null); //自定义布局
	           
	         //设置各组件的位置大小
     	   openb.setBounds(280,75,95,25);
    	   zh.setBounds(280,210,95,25);
    	   allzh.setBounds(280,250,95,25);
    	   exit.setBounds(280,400,95,25);
    	   bq.setBounds(0,0,400,70);            //图片大小400*70
    	   jt.setBounds(3,74,16,10);
     	   sc.setBounds(280,110,95,25);
    	   allsc.setBounds(280,145,95,25);
	       lb.setBounds(20,70,250,370);
     	    
     	       //添加组件
     	   c.add(openb);
    	   c.add(zh);
    	   c.add(allzh);
    	   c.add(sc);
    	   c.add(allsc);
    	   c.add(exit);
    	   c.add(bq);
     	   c.add(lb);
     	   c.add(jt);
     	      
     	   openb.addActionListener(new ActionListener(){
     	      public void actionPerformed(ActionEvent e){
     	    	  	  JFileChooser fs=new JFileChooser();//选择文件对话框
     	    	  	  fs.setSelectedFile(file);          
     	    	  	  int rv=fs.showOpenDialog(txttohtml.this);
     	    	  	  file=fs.getSelectedFile();       //选择文件
     	    	  	  
     	    	  	  String zz=file.getPath();//获取文件路径
     	    	  	  lb.add(zz);             //将文件路径添加到列表中
     	    	      openb.setText("添加");  //将"打开"按钮文字改为"添加"
     	    	      jta++;
     	    	      jty=74+18*jta;
     	    	      jt.setBounds(3,jty-18,16,10); 
     	    	  
     	    	      }
     	    	  });
     	     //删除按钮事件处理	  
     	    sc.addActionListener(new ActionListener(){
     	    	  public void actionPerformed(ActionEvent e){
     	    	      int aa=-1;
     	    	       aa=lb.getSelectedIndex();
     	    	       if(aa==-1)
     	    	          JOptionPane.showMessageDialog(null,"未选取文件!");
     	    	       else{
                          lb.remove(aa);
                          jta--;
                          jty=74+18*jta;
     	    	          jt.setBounds(3,jty-18,16,10); }
     	    	      }
     	    	  });
     	    //全部删除按钮事件处理	  
     	    allsc.addActionListener(new ActionListener(){
     	    	  public void actionPerformed(ActionEvent e){
     	    	      lb.removeAll();
     	    	      jt.setBounds(3,74,16,10);
     	    	      }
     	    	  });
     	     //转换按钮事件处理代码
     	     zh.addActionListener(new ActionListener(){
     	    	  public void actionPerformed(ActionEvent e){
     	    	      String zz=lb.getSelectedItem();
     	    	      int xx=0,xxx=0;
     	    	      if(zz==null)
     	    	          JOptionPane.showMessageDialog(null,"未选取文件!");
     	    	      else{
     	    	      	  try{
     	    	      	  	  File input=new File(zz);  
     	    	      	  	  FileReader in=new FileReader(input); //文件读入流
     	    	      	  	  int c;
     	    	      	  	  String wjm=input.getName();      //获取文件名
     	    	      	  	  char[] wjmc=new char[wjm.length()];
     	    	      	  	  char[] zzc=new char[zz.length()];
     	    	      	  	  wjmc=wjm.toCharArray();
     	    	      	  	  zzc=zz.toCharArray();
     	    	      	  	  for(int a=0;a<zz.length();a++){
     	    	      	  	  	  if(zzc[a]=='.'){
     	    	      	  	  	  	  xxx=a;break;
     	    	      	  	      } }
     	    	      	  	  wjmc=wjm.toCharArray();
     	    	      	  	  for(int a=0;a<wjm.length();a++){
     	    	      	  	  	  if(wjmc[a]=='.'){
     	    	      	  	  	  	  xx=a;break;
     	    	      	  	      } }
                              String zx=wjm.substring(0,xx);
                              String zxx=zz.substring(0,xxx);
                              
                              File output=new File(zxx+".html");
                              FileWriter out=new FileWriter(output);
                              
     	    	      	  	  out.write("<HTML>\n<Head>\n<title>"+zx+"</title>\n</head>\n<body>");
     	    	      	  	  out.write("<p>");
     	    	      	  	  while((c=in.read())!=-1){
     	    	      	  	      if(c=='\n'){ out.write("<Br>");continue;} //if    	    	      	  	      
     	    	      	  	      	  out.write(c); //写入文件
     	    	      	  	      } //while
     	    	      	  	      out.write("</p></body></HTML>");
     	    	      	  	  in.close(); out.close();  //关闭文件
     	    	      	  	  JOptionPane.showMessageDialog(null,"文件转换成功");
     	    	      	  	}//try
     	    	      	  	catch(IOException eee){
     	    	      	  	  	         JOptionPane.showMessageDialog(null,"文件转换失败");
     	    	      	  	          }
     	    	        }//if-else
     	    	      }
     	    	  });
     	    	  
     	      //全部转换按钮事件处理代码
    	     allzh.addActionListener(new ActionListener(){
     	      	  public void actionPerformed(ActionEvent e){
     	    	      int x=lb.getItemCount();
     	    	      int a=0;
     	    	      for(a=0;a<x;a++){
     	    	      	  lb.select(a);
     	    	      	  String zz=lb.getSelectedItem();
     	    	      	  int xx=0,xxx=0;
     	    	      	   try{
     	    	      	  	  File input=new File(zz); 
     	    	      	  	  FileReader in=new FileReader(input);  //打开一个文件读入流
     	    	      	  	  
     	    	      	  	  String wjm=input.getName();    //获取文件名
     	    	      	  	  char[] wjmc=new char[wjm.length()]; //定义一个字符数组
     	    	      	  	  wjmc=wjm.toCharArray();   //将文件保存在数组中
     	    	      	  	  for(int ax=0;ax<wjm.length();ax++){
     	    	      	  	  	  if(wjmc[ax]=='.'){
     	    	      	  	  	  	  xxx=ax;
     	    	      	  	  	  	  break;
     	    	      	  	      } }
     	    	      	  	  String zx=wjm.substring(0,xxx);  
     	    	      	  	   
     	    	      	  	  char[] zzca=new char[zz.length()];
     	    	      	  	  zzca=zz.toCharArray();
     	    	      	  	  for(int ax=0;ax<zz.length();ax++){
     	    	      	  	  	  if(zzca[ax]=='.'){
     	    	      	  	  	  	  xx=ax;
     	    	      	  	  	  	  break;
     	    	      	  	      } }
                              String zxx=zz.substring(0,xx);  //文件写入流
     	    	      	  	  
     	    	      	  	  File output=new File(zxx+".html");
     	    	      	  	  FileWriter out=new FileWriter(output);
     	    	      	  	  int c;
     	    	      	  	  
     	    	      	  	      out.write("<HTML>\n<Head>\n<title>"+zx+"</title>\n</head>\n<body>");
     	    	      	  	      out.write("<p>");
     	    	      	  	      while((c=in.read())!=-1){
     	    	      	  	      	  if(c=='\n'){ out.write("<Br>");continue;
     	    	      	  	      	  } //if
     	    	      	  	      	  out.write(c);
     	    	      	  	      } //while
     	    	      	  	      out.write("</body></HTML>");
     	    	      	  	  in.close(); out.close();
     	    	      	  	}//try
     	    	      	  	catch(IOException eee){
     	    	      	  	  	         JOptionPane.showMessageDialog(null,"文件转换失败");
     	    	      	  	          }
     	    	         
     	    	        }JOptionPane.showMessageDialog(null,"文件转换完毕!");
     	    	      }
     	    	  });
     	    	  
     	       //退出按钮事件处理代码
     	      exit.addActionListener(new ActionListener(){
     	    	  public void actionPerformed(ActionEvent e){
     	    	        setVisible(false);
     	    	      }
     	    	  });
     	    	  
     	    	//关闭按钮事件处理	  
     	    this.addWindowListener(new WindowAdapter(){
     	    	public void windowClosing(WindowEvent e){
     	    		 
     	    	}
     	    });
     	      
     	       setBounds(310,150,400,480); //确定窗口位置大小
               setVisible(true);   //设置窗口可见
	           c.setBackground(new Color(128,200,240)); //设置窗口背景色
	           setResizable(false);   //固定窗口大小
	           setIconImage(Toolkit.getDefaultToolkit().createImage("image\\t2h.png"));  //设置窗口图标 
	  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -