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

📄 tryexample10_2.java

📁 不错的教程 适合中高级人员的使用
💻 JAVA
字号:
import java.applet.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;

class MyButton extends Button implements TextListener
{
	TextArea text1,text2;
	char save[];

	MyButton(String s,Container con)
	{
		super(s);
		text1=new TextArea(6,12);
		text2=new TextArea(6,12);
		text2.setEditable(false);
		text1.addTextListener(this);
		//this.addActionListener(this);
		con.add(text1);con.add(text2);con.add(this);
	}
   public void textValueChanged(TextEvent e)
	{
	   String s=text1.getText();
	   StringBuffer strbuffer=new StringBuffer(s);
	   String temp=new String(strbuffer.reverse());
	   text2.setText(temp);
   }
  /* public void actionPerformed(ActionEvent e)
	{
	   text2.setText(null);
	   String s=text1.getText();
	   int length=s.length();
	   save=new char[length];

	   s.getChars(0,length,save,0);
	   for(int i=0;i<save.length;i++)
		{
		   save[i]=(char) (save[i]^'你');
		}
		String temp=new String(save);
		text2.setText(temp);
   }*/
}

public class TryExample10_2 extends Applet implements ActionListener
{
	MyButton mybutton;
	Button button;

	public void init()
	{
		mybutton=new MyButton("加密",this);
		button=new Button("解密");
		button.addActionListener(this);
		mybutton.addActionListener(this);
		add(mybutton);add(button);
	}
	public void actionPerformed(ActionEvent e)
    {
		if(e.getSource()==mybutton)
		{text2.setText(null);
	   String s=text1.getText();
	   int length=s.length();
	   save=new char[length];

	   s.getChars(0,length,save,0);
	   for(int i=0;i<save.length;i++)
		{
		   save[i]=(char) (save[i]^'你');
		}
		String temp=new String(save);
		text2.setText(temp);}
		else{
		for(int i=0;i<mybutton.save.length;i++)
		{
			mybutton.save[i]=(char) (mybutton.save[i]^'你');
		}
		String temp=new String(mybutton.save);
		mybutton.text2.setText(temp);
		}
	}
}

⌨️ 快捷键说明

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