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

📄 findframe.java

📁 用java编写的一个记事本程序,具有和windows Notepad相似的功能
💻 JAVA
字号:
import java.awt.datatransfer.*;
import java.io.*;
import java.awt.datatransfer.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.event.*;
import java.awt.*;
class FindFrame extends Frame implements ActionListener,ItemListener
{

	Panel r,r_1,r_2,v_1,v_2,r_3;
	Button findButton,cancel;
	Box baseBox,H1,H2,V1,H3;
	Label content;
	TextField text;
	Checkbox type,up,down;
	CheckboxGroup Direction; 
	Image im;
	
	int tempstart=0;
	int end=0;
	int start=0;
	String tempstring="";
	String s,string;
	String rstring;
	FindFrame()
	{
	   super("查找对话框");
	   Color c=new Color(236,233,216);
	   this.setBackground(c);
	   im=Toolkit.getDefaultToolkit().getImage("d:\\1.1.jpg");
	   this.setIconImage(im);
       H1=Box.createHorizontalBox();
       content=new Label("查找内容");
       text=new TextField(10);
       H1.add(content);
       H1.add(Box.createHorizontalStrut(1));
       H1.add(text);
      
       Direction=new CheckboxGroup();
       type=new Checkbox("不区分大小写");
       type.addItemListener(this);
       up=new Checkbox("向上",false,Direction);
       down=new Checkbox("向下",true,Direction);
       up.addItemListener(this);
       down.addItemListener(this);
       r_2=new Panel();
       r_2.setLayout(new GridLayout(1,2));
       r_2.add(up);
       r_2.add(down);
       
       H2=Box.createHorizontalBox();
       H2.add(type);
       H2.add(Box.createHorizontalStrut(1));
       H2.add(r_2);
       
        H3=Box.createHorizontalBox();
       findButton=new Button("查找下一个");
       
       cancel=new Button("取消");
       findButton.addActionListener(this);
       cancel.addActionListener(this);

       r_3=new Panel();
       r_3.setLayout(new GridLayout(1,2));
       r_3.add(findButton);
       r_3.add(cancel);
       
       
       V1=Box.createVerticalBox();
       V1.add(H1);
       V1.add(Box.createVerticalStrut(1));
       V1.add(H2);
       V1.add(Box.createVerticalStrut(1));
       V1.add(r_3);
       

       add(V1,BorderLayout.CENTER);
        rstring=MyFrame.text.getText();
       
       
       
       

       this.setVisible(true);
       this.setBounds(300,300,300,120);
       validate();
 
	   addWindowListener(new WindowAdapter()
 	  {
 		public void windowClosing(WindowEvent e)
 		{
 			dispose();
 		}
 	});
		
	}

public void actionPerformed(ActionEvent e1)
{
	
  s=text.getText();
  string=MyFrame.text.getText();
	if(e1.getSource()==findButton)
	{
        if(down.getState()==true)
        {
        	down();
        }
	    if(up.getState()==true)
	    {
	    	up();
	    }


		
	}
	if(e1.getSource()==cancel)
	{
		dispose();
	}
}

public void down()
{
	System.out.println("");
	System.out.println("down");
 if(text.getText()!=null  )
	{
       if(end<=string.length()-1 )
       {
        if(type.getState()==true)
         {
 
		  start=tempstring.indexOf(s,tempstart);
		  
		 }
	   else
	   {

		  start=string.indexOf(s,tempstart);
		  
		}

		end=start+s.length();

        
		System.out.println("运算前的start:"+start);
		System.out.println("运算前的end:"+end);  
	    MyFrame.text.setSelectionStart(start);
	    MyFrame.text.setSelectionEnd(end);
	    if((end)<=string.length()-1)
		{
			tempstart=end;
		}
		if(end>string.length()-1)
		{
			tempstart=end;
		}


        System.out.println("运算后的start:"+start);
		System.out.println("tempstart:"+tempstart); 
		}    

		 
	}
}


public void up()
{
	System.out.println("");
 System.out.println("up");
 if(text.getText()!=null  )
	{
       if(start>=0)
       {
        if(type.getState()==true)
         {
		  start=tempstring.lastIndexOf(s,start);
		 }
	   else
	   {
		  start=rstring.lastIndexOf(s,start);
		}
		end=start+s.length();
		System.out.println("运算前的start:"+start);
		System.out.println("运算前的end:"+end); 
		if(start>=0)
		{ 
	    MyFrame.text.setSelectionStart(start);
	    MyFrame.text.setSelectionEnd(end);
	    
		  if(type.getState()==false)
		  {
		  rstring=string.substring(0,start);
		  tempstart=start;
		  }	
		  if(type.getState()==true)
		  {
		  rstring=tempstring.substring(0,start);
		  tempstart=start;
		  }
		 }
		if(start<0)
		{
			start=0;
			tempstart=0;
		}
       

        System.out.println("运算后的start:"+start);
		System.out.println("tempstart:"+tempstart); 
		}    

		 
	}	
		
	
}
public void itemStateChanged(ItemEvent ie)
{
	  String s=text.getText();
      String string=MyFrame.text.getText();
      String ups=s.toUpperCase();
      String lows=s.toLowerCase();   
	if(ie.getItemSelectable()==type)
	{
       if(s.equals(ups))
       {
       	 tempstring=string.toUpperCase();
       }
       if(s.equals(lows))
       {
       	 tempstring=string.toLowerCase();
       }
		
	}
	if(ie.getItemSelectable()==up)
	{
		
	}
	if(ie.getItemSelectable()==down)
	{
		
	}
}	
}
	

⌨️ 快捷键说明

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