首页 > > 详细

辅导php设计、Haskell程序解析、辅导Java、Java辅导、解析R编程

//
public void mySearch(){

final JDialog findDialog=new JDialog(this,"",false);//false()
Container con=findDialog.getContentPane();//contentPane
con.setLayout(new FlowLayout(FlowLayout.LEFT));

JLabel searchContentLabel=new JLabel("(N) :");
JLabel replaceContentLabel=new JLabel("(P)  :");
final JTextField findText=new JTextField(30);
final JTextField replaceText=new JTextField(30);
final JCheckBox matchcase =new JCheckBox("(C)");
ButtonGroup bGroup=new ButtonGroup();
final JRadioButton up=new JRadioButton("(U)");
final JRadioButton down=new JRadioButton("(D)");
down.setSelected(true);
bGroup.add(up);
bGroup.add(down);
JButton searchNext=new JButton("(F)");
JButton replace=new JButton("(R)");
final JButton replaceAll=new JButton("(A)");
/*ButtonGroup(multiple-exclusion)。
ButtonGroup “”,。*/
/*JRadioButton,,。
ButtonGroup ,。
( ButtonGroup add JRadioButton 。)*/

//""
replace.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){

if(replaceText.getText().length() == 0 editArea.getSelectedText()!=null)
editArea.replaceSelection("");
if(replaceText.getText().length() > 0 editArea.getSelectedText()!= null)
editArea.replaceSelection(replaceText.getText());
}
});

//""
replaceAll.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){

editArea.setCaretPosition(0); //
int a=0,b=0,replaceCount=0;

if(findText.getText().length()==0)
{
JOptionPane.showMessageDialog(findDialog,"!","",JOptionPane.WARNING_MESSAGE);
findText.requestFocus(true);
return;
}
while( a > -1) {

int FindStartPos=editArea.getCaretPosition();
String str1, str2, str3, str4, strA, strB;
str1 = editArea.getText();
str2 = str1.toLowerCase();
str3 = findText.getText();
str4 = str3.toLowerCase();

if(matchcase.isSelected()) {
strA = str1;
strB = str3;
}
else {
strA = str2;
strB = str4;
}

if(up.isSelected()){
if(editArea.getSelectedText()==null){
a = strA.lastIndexOf(strB, FindStartPos-1);
}
else
{
a = strA.lastIndexOf(strB, FindStartPos-findText.getText().length()-1);
}
}
else if(down.isSelected())
{
if(editArea.getSelectedText()==null){
a = strA.indexOf(strB, FindStartPos);
}
else
{
a=strA.indexOf(strB,FindStartPos-findText.getText().length()+1);
}

}

if(a > -1) {
if(up.isSelected()){
editArea.setCaretPosition(a);
b = findText.getText().length();
editArea.select(a, a + b);
}
else if(down.isSelected()){
editArea.setCaretPosition(a);
b = findText.getText().length();
editArea.select(a, a + b);
}
}
else {
if(replaceCount==0){
JOptionPane.showMessageDialog(findDialog, "!", "",JOptionPane.INFORMATION_MESSAGE);
}
else
{
JOptionPane.showMessageDialog(findDialog,""+replaceCount+"!","",JOptionPane.INFORMATION_MESSAGE);
}
}

if(replaceText.getText().length() == 0 editArea.getSelectedText() != null){
editArea.replaceSelection("");
replaceCount++;
}

if(replaceText.getText().length() > 0 editArea.getSelectedText() != null)
{
editArea.replaceSelection(replaceText.getText());
replaceCount++;
}
}//end while
}
});

//""
searchNext.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

int a = 0, b =0;
int FindStartPos=editArea.getCaretPosition();
String str1, str2, str3, str4, strA, strB;
str1 = editArea.getText();
str2 = str1.toLowerCase();
str3 = findText.getText();
str4 = str3.toLowerCase();

//""CheckBox
if(matchcase.isSelected()) {
strA = str1;
strB = str3;
}
else {
strA = str2;
strB = str4;
}

if(up.isSelected()){

if(editArea.getSelectedText()==null){
a = strA.lastIndexOf(strB, FindStartPos-1);
}
else{
a = strA.lastIndexOf(strB, FindStartPos-findText.getText().length()-1);
}
}
else if(down.isSelected()){

if(editArea.getSelectedText()==null){
a = strA.indexOf(strB, FindStartPos);
}
else{
a=strA.indexOf(strB,FindStartPos-findText.getText().length()+1);
}

}

if(a > -1) {
if(up.isSelected()){
editArea.setCaretPosition(a);
b = findText.getText().length();
editArea.select(a, a + b);
}
else if(down.isSelected()){
editArea.setCaretPosition(a);
b = findText.getText().length();
editArea.select(a, a + b);
}
}
else {
JOptionPane.showMessageDialog(null, "!", "",JOptionPane.INFORMATION_MESSAGE);
}

}
});

//""
JButton cancel=new JButton("");
cancel.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
findDialog.dispose();
}
});
//""
JPanel bottomPanel=new JPanel();
JPanel centerPanel=new JPanel();
JPanel topPanel=new JPanel();
JPanel direction=new JPanel();
direction.setBorder(BorderFactory.createTitledBorder(""));
direction.add(up);
direction.add(down);

JPanel replacePanel=new JPanel();
replacePanel.setLayout(new GridLayout(2,1));
replacePanel.add(replace);
replacePanel.add(replaceAll);
topPanel.add(searchContentLabel);
topPanel.add(findText);
topPanel.add(searchNext);
centerPanel.add(replaceContentLabel);
centerPanel.add(replaceText);
centerPanel.add(replacePanel);
bottomPanel.add(matchcase);
bottomPanel.add(direction);
bottomPanel.add(cancel);
con.add(topPanel);
con.add(centerPanel);
con.add(bottomPanel);

//""、()、
findDialog.setSize(530,270);
findDialog.setResizable(false);
findDialog.setLocation(230,280);
findDialog.setVisible(true);
}
//ActionListenerpublic void actionPerformed(ActionEvent e)
public void actionPerformed(ActionEvent e)
{
//
if(e.getSource()==fileMenu_New||e.getSource()==newButton)
{
editArea.requestFocus();
String currentValue=editArea.getText();
boolean isTextChange=(currentValue.equals(oldValue))?false:true;

if(isTextChange){

int saveChoose=JOptionPane.showConfirmDialog(this,"。?","",JOptionPane.YES_NO_CANCEL_OPTION);

if(saveChoose==JOptionPane.YES_OPTION)
{
String str=null;

JFileChooser fileChooser=new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setApproveButtonText("");
fileChooser.setDialogTitle("");

int result=fileChooser.showSaveDialog(this);

if(result==JFileChooser.CANCEL_OPTION){
statusLabel.setText("");
return;
}

File saveFileName=fileChooser.getSelectedFile();

if(saveFileName==null||saveFileName.getName().equals(""))
JOptionPane.showMessageDialog(this,"","",JOptionPane.ERROR_MESSAGE);
else {
try{
FileWriter fw=new FileWriter(saveFileName);
BufferedWriter bfw=new BufferedWriter(fw);
bfw.write(editArea.getText(),0,editArea.getText().length());
bfw.flush();
fw.close();

isNewFile=false;
currentFile=saveFileName;
ldValue=editArea.getText();

this.setTitle(saveFileName.getName()+" - ");
statusLabel.setText(" :"+saveFileName.getAbsoluteFile());
}

catch(IOException ioException){
}
}
}

else if(saveChoose==JOptionPane.NO_OPTION){
editArea.replaceRange("", 0, editArea.getText().length());
statusLabel.setText(" ");
this.setTitle(" - ");
isNewFile=true;
undo.discardAllEdits(); //""""
editMenu_Undo.setEnabled(false);
popupMenu_Undo.setEnabled(false);
undoButton.setEnabled(false);
editMenu_Redo.setEnabled(false);
popupMenu_Redo.setEnabled(false);
redoButton.setEnabled(false);
ldValue=editArea.getText();
}

else if(saveChoose==JOptionPane.CANCEL_OPTION)
{
return;
}
}

else
{
editArea.replaceRange("", 0, editArea.getText().length());
statusLabel.setText(" ");
this.setTitle(" - ");
isNewFile=true;
undo.discardAllEdits();
editMenu_Undo.setEnabled(false);
popupMenu_Undo.setEnabled(false);
undoButton.setEnabled(false);
editMenu_Redo.setEnabled(false);
popupMenu_Redo.setEnabled(false);
redoButton.setEnabled(false);
ldValue=editArea.getText();
}
}//

//
else if(e.getSource()==fileMenu_Open||e.getSource()==openButton)
{
editArea.requestFocus();
String currentValue=editArea.getText();
boolean isTextChange=(currentValue.equals(oldValue))?false:true;

if(isTextChange){

int saveChoose=JOptionPane.showConfirmDialog(this,"。?","",JOptionPane.YES_NO_CANCEL_OPTION);

if(saveChoose==JOptionPane.YES_OPTION)
{
String str=null;

JFileChooser fileChooser=new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setApproveButtonText("");
fileChooser.setDialogTitle("");

int result=fileChooser.showSaveDialog(this);

if(result==JFileChooser.CANCEL_OPTION){
statusLabel.setText("");
return;
}

File saveFileName=fileChooser.getSelectedFile();

if(saveFileName==null||saveFileName.getName().equals(""))
JOptionPane.showMessageDialog(this,"","",JOptionPane.ERROR_MESSAGE);
else {
try{
FileWriter fw=new FileWriter(saveFileName);
BufferedWriter bfw=new BufferedWriter(fw);
bfw.write(editArea.getText(),0,editArea.getText().length());
bfw.flush();
fw.close();

isNewFile=false;
currentFile=saveFileName;
ldValue=editArea.getText();

this.setTitle(saveFileName.getName()+" - ");
statusLabel.setText(":"+saveFileName.getAbsoluteFile());
}
catch(IOException ioException){
}
}
}
else if(saveChoose==JOptionPane.NO_OPTION){
String str=null;

JFileChooser fileChooser=new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setApproveButtonText("");
fileChooser.setDialogTitle("");

int result=fileChooser.showOpenDialog(this);

if(result==JFileChooser.CANCEL_OPTION){
statusLabel.setText("");
return;
}

File fileName=fileChooser.getSelectedFile();

if(fileName==null||fileName.getName().equals(""))
JOptionPane.showMessageDialog(this,"","",JOptionPane.ERROR_MESSAGE);
else {

try{
FileReader fr=new FileReader(fileName);
BufferedReader bfr=new BufferedReader(fr);

editArea.setText("");

while((str=bfr.readLine())!=null){//,
editArea.append(str+"\15\12");
}//end while

this.setTitle(fileName.getName()+" - ");
statusLabel.setText(" :"+fileName.getAbsoluteFile());

fr.close();
isNewFile=false;
currentFile=fileName;
ldValue=editArea.getText();
}
catch(IOException ioException){
}
}
}
else{
return;
}
}

else{
String str=null;

JFileChooser fileChooser=new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setApproveButtonText("");
fileChooser.setDialogTitle("");

int result=fileChooser.showOpenDialog(this);

if(result==JFileChooser.CANCEL_OPTION){
statusLabel.setText(" ");
return;
}

File fileName=fileChooser.getSelectedFile();

if(fileName==null||fileName.getName().equals(""))
JOptionPane.showMessageDialog(this,"","",JOptionPane.ERROR_MESSAGE);
else {
try{
FileReader fr=new FileReader(fileName);
BufferedReader bfr=new BufferedReader(fr);

editArea.setText("");

while((str=bfr.readLine())!=null){//,
editArea.append(str+"\15\12");
}//end while

this.setTitle(fileName.getName()+" - ");
statusLabel.setText(" :"+fileName.getAbsoluteFile());

fr.close();
isNewFile=false;
currentFile=fileName;
ldValue=editArea.getText();
}
catch(IOException ioException){
}
}

}
}//""

//
else if(e.getSource()==fileMenu_Save||e.getSource()==saveButton)
{
editArea.requestFocus();
if(isNewFile){

String str=null;

JFileChooser fileChooser=new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setApproveButtonText("");
fileChooser.setDialogTitle("");

int result=fileChooser.showSaveDialog(this);

if(result==JFileChooser.CANCEL_OPTION){
statusLabel.setText(" ");
return;
}
File saveFileName=fileChooser.getSelectedFile();

if(saveFileName==null||saveFileName.getName().equals(""))
JOptionPane.showMessageDialog(this,"","",JOptionPane.ERROR_MESSAGE);
else {
try{
FileWriter fw=new FileWriter(saveFileName);
BufferedWriter bfw=new BufferedWriter(fw);
bfw.write(editArea.getText(),0,editArea.getText().length());
bfw.flush();
fw.close();

isNewFile=false;
currentFile=saveFileName;
ldValue=editArea.getText();

this.setTitle(saveFileName.getName()+" - ");
statusLabel.setText(" :"+saveFileName.getAbsoluteFile());
}
catch(IOException ioException){
}
}
}
else
{
try{
FileWriter fw=new FileWriter(currentFile);
BufferedWriter bfw=new BufferedWriter(fw);
bfw.write(editArea.getText(),0,editArea.getText().length());
bfw.flush();
fw.close();
}
catch(IOException ioException){
}
}
}//""

//
else if(e.getSource()==fileMenu_SaveAs||e.getSource()==saveAsButton)
{
editArea.requestFocus();
String str=null;

JFileChooser fileChooser=new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setApproveButtonText("");
fileChooser.setDialogTitle("");

int result=fileChooser.showSaveDialog(this);

if(result==JFileChooser.CANCEL_OPTION){
statusLabel.setText(" ");
return;
}
File saveFileName=fileChooser.getSelectedFile();

if(saveFileName==null||saveFileName.getName().equals(""))
JOptionPane.showMessageDialog(this,"","",JOptionPane.ERROR_MESSAGE);
else {
try{
FileWriter fw=new FileWriter(saveFileName);
BufferedWriter bfw=new BufferedWriter(fw);
bfw.write(editArea.getText(),0,editArea.getText().length());
bfw.flush();
fw.close();
ldValue=editArea.getText();

this.setTitle(saveFileName.getName()+" - ");
statusLabel.setText(" :"+saveFileName.getAbsoluteFile());
}
catch(IOException ioException){
}
}

}//""

//
else if(e.getSource()==fileMenu_PageSetup){
editArea.requestFocus();
JOptionPane.showMessageDialog(this,",!","",JOptionPane.WARNING_MESSAGE);
}

//
else if(e.getSource()==fileMenu_Print||e.getSource()==printButton){
editArea.requestFocus();
JOptionPane.showMessageDialog(this,",!","",JOptionPane.WARNING_MESSAGE);
}

//
else if(e.getSource()==fileMenu_Exit){
int exitChoose=JOptionPane.showConfirmDialog(this,"?","",JOptionPane.OK_CANCEL_OPTION);
if(exitChoose==JOptionPane.OK_OPTION){
System.exit(0);
}
else{
return;
}
}

//
else if(e.getSource()==editMenu_Undo||e.getSource()==popupMenu_Undo||e.getSource()==undoButton)
{
editArea.requestFocus();
if(undo.canUndo()) {
try {
undo.undo();
editMenu_Redo.setEnabled(true);
popupMenu_Redo.setEnabled(true);
redoButton.setEnabled(true);
}
catch(CannotUndoException ex) {
System.out.println("Unable to undo: " + ex);
ex.printStackTrace();
}

if(!undo.canUndo()){
editMenu_Undo.setEnabled(false);
popupMenu_Undo.setEnabled(false);
undoButton.setEnabled(false);

editMenu_Redo.setEnabled(true);
popupMenu_Redo.setEnabled(true);
redoButton.setEnabled(true);
}
}
}

//
else if(e.getSource()==editMenu_Redo||e.getSource()==popupMenu_Redo||e.getSource()==redoButton)
{
editArea.requestFocus();
if(undo.canRedo()) {
try {
undo.redo();
editMenu_Undo.setEnabled(true);
popupMenu_Undo.setEnabled(true);
undoButton.setEnabled(true);
}
catch(CannotRedoException ex) {
System.out.println("Unable to redo: " + ex);
ex.printStackTrace();
}

if(!undo.canRedo()){
editMenu_Redo.setEnabled(false);
popupMenu_Redo.setEnabled(false);
redoButton.setEnabled(false);

editMenu_Undo.setEnabled(true);
popupMenu_Undo.setEnabled(true);
undoButton.setEnabled(true);
}
}
}

//
else if(e.getSource()==editMenu_Cut||e.getSource()==popupMenu_Cut||e.getSource()==cutButton)
{
editArea.requestFocus();
String text=editArea.getSelectedText();
StringSelection selection=new StringSelection(text);
clipBoard.setContents(selection,null);
editArea.replaceRange("",editArea.getSelectionStart(),editArea.getSelectionEnd());
checkMenuItemEnabled(); //、、、
}

//
else if(e.getSource()==editMenu_Copy||e.getSource()==popupMenu_Copy||e.getSource()==copyButton)
{
editArea.requestFocus();
String text=editArea.getSelectedText();
StringSelection selection=new StringSelection(text);
clipBoard.setContents(selection,null);
checkMenuItemEnabled(); //、、、
}

//
else if(e.getSource()==editMenu_Paste||e.getSource()==popupMenu_Paste||e.getSource()==pasteButton)
{
editArea.requestFocus();
Transferable contents=clipBoard.getContents(this);
if(contents==null) return;
String text;
text="";

try{
text=(String)contents.getTransferData(DataFlavor.stringFlavor);
}
catch(Exception exception){
}

editArea.replaceRange(text,editArea.getSelectionStart(),editArea.getSelectionEnd());
checkMenuItemEnabled(); //、、、
}

//
else if(e.getSource()==editMenu_Delete||e.getSource()==popupMenu_Delete||e.getSource()==deleteButton)
{
editArea.requestFocus();
editArea.replaceRange("",editArea.getSelectionStart(),editArea.getSelectionEnd());
checkMenuItemEnabled(); //、、、
}

//
else if(e.getSource()==editMenu_Find||e.getSource()==searchButton)
{
editArea.requestFocus();
if(e.getSource()==searchButton){
editArea.requestFocus();
editArea.setCaretPosition(0);
}
mySearch();
}

//(,)
else if(e.getSource()==editMenu_FindNext)
{
mySearch();
}

//()
else if(e.getSource()==editMenu_Replace)
{
mySearch();
}

//
else if(e.getSource()==editMenu_GoTo)
{
final JDialog gotoDialog=new JDialog(this,"");
JLabel gotoLabel=new JLabel("(L):");
final JTextField linenum=new JTextField(20);
linenum.setText("1");
linenum.selectAll();

JButton kButton=new JButton("");
okButton.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){
int totalLine = editArea.getLineCount();
int[] lineNumber = new int[totalLine + 1];
String s = editArea.getText();
int pos = 0, t = 0;

while(true) {
pos = s.indexOf('\12', pos);
if(pos == -1)
break;
lineNumber[t++] = pos++;
}

int gt = 1;
try {
gt = Integer.parseInt(linenum.getText());
}
catch(NumberFormatException efe) {
JOptionPane.showMessageDialog(null, "!", "",JOptionPane.WARNING_MESSAGE);
linenum.requestFocus(true);
return;
}

if(gt = totalLine) {
if(gt CSDN"+
""+
"https://blog.csdn.net/"
);
JEditorPane editPane=new JEditorPane("text/html",helpTopicsStr);
editPane.setEditable(false);

editPane.addHyperlinkListener(new HyperlinkListener(){
public void hyperlinkUpdate(HyperlinkEvent hle){

if (hle.getEventType()==HyperlinkEvent.EventType.ACTIVATED)
{
try
{
Process process = Runtime.getRuntime().exec("cmd.exe /c start http://blog.csdn.net/");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
});

JFrame. helpTopicsFrame=new JFrame("");
helpTopicsFrame.setContentPane(new JScrollPane(editPane));
helpTopicsFrame.setSize(250,200);
helpTopicsFrame.setLocation(300,300);
helpTopicsFrame.setVisible(true);
}
 

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!