?? findframe.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 + -