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

📄 example10_2.java

📁 很好
💻 JAVA
字号:
import java.awt.*;import java.applet.*;import java.awt.event.*;
//写一个按扭类的子类,增加一些新的功能:
class MyButton extends Button implements ActionListener,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];
     //将字符串拷贝到数组save:
     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 Example10_2 extends Applet implements ActionListener
{  MyButton mybutton;
   Button button;
   public void init()
   {  mybutton=new MyButton("加密",this); 
      button=new Button("解密");
      button.addActionListener(this);
      add(button); 
   }
   public void actionPerformed(ActionEvent e) //实现接口。
   {  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 + -