finddlg.java

来自「程序的功能与微软的记事本功能差不多」· Java 代码 · 共 86 行

JAVA
86
字号
package jeason; 

import java.awt.*; 
import java.awt.event.*; 
import javax.swing.*; 

public class FindDlg extends JDialog{ 

private String findstr; 
private boolean flag=true; 

JLabel findText=new JLabel("查找内容"); 
JTextField strText=new JTextField(" "); 
JButton btnNext=new JButton( ); 
JButton btnUp=new JButton( ); 

FlowLayout flowLayout1=new FlowLayout(); 

FindDlg(Frame frame,String title, boolean modal){ 
super(frame,title,modal); 

this.setTitle("查找"); 
this.setSize(200,90); 
this.setModal(true); 

findText.setText(" 查找内容 "); 
findText.setSize(70,60); 

strText.setText(" "); 
strText.setSize(130,60); 

btnNext.setText("向下查找"); 
btnNext.setSize(100,40); 
btnNext.addActionListener(new btnNext_actionAdapter(this)); 

btnUp.setText("向上查找"); 
btnUp.setSize(100,40); 
btnUp.addActionListener(new btnUp_actionAdapter(this)); 

this.getContentPane().setLayout(flowLayout1); 
this.getContentPane().add(this.findText,flowLayout1); 
this.getContentPane().add(this.strText,flowLayout1); 
this.getContentPane().add(this.btnNext,flowLayout1); 
this.getContentPane().add(this.btnUp,flowLayout1); 
} 
FindDlg(){ 
this(null,"",false); 
} 

public void btnNext_actionPerformed(ActionEvent e){ 
this.findstr=this.strText.getText(); 
this.flag=true; 
this.dispose(); 
} 
public void btnUp_actionPerformed(ActionEvent e){ 
this.findstr=this.strText.getText(); 
this.flag=false; 
this.dispose(); 
} 
public String getFindStr(){ 
return this.findstr; 
} 
public boolean getFlag(){ 
return this.flag; 
} 
} 
class btnNext_actionAdapter implements java.awt.event.ActionListener{ 
FindDlg adaptee; 
btnNext_actionAdapter(FindDlg adaptee){ 
this.adaptee=adaptee; 
} 
public void actionPerformed(ActionEvent e){ 
adaptee.btnNext_actionPerformed(e); 
} 
} 

class btnUp_actionAdapter implements java.awt.event.ActionListener{ 
FindDlg adaptee; 
btnUp_actionAdapter(FindDlg adaptee){ 
this.adaptee=adaptee; 
} 
public void actionPerformed(ActionEvent e){ 
adaptee.btnUp_actionPerformed(e); 
} 
} 

⌨️ 快捷键说明

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