|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
It's me again. I finally got the console ROT13 program to work and decided to convert it into an applet with some AWT capablities. Here's the soucecode:
import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.util.Arrays; import java.lang.String; public class ROT13let extends java.applet.Applet implements ActionListener{ TextArea textarea1; Button button1; public void init() { textarea1=new TextArea("",5,20); add(textarea1); button1= new Button("ROT13"); add(button1); button1.addActionListener(this); } public void actionPerformed(ActionEvent e){ char[] Alpha = {'a','b','c','d','e','f','g','h','i','j','k','l',' m','n','o','p','q','r','s','t','u','v','w','x','y' ,'z',' ','A','B','C','D','E','F','G','H','I','J','K','L', 'M','N','O','P','Q','R','S','T','U','V','W','X','Y ','Z'}; char[] Rev = {'z','y','x','w','v','u','t','s','r','q','p','o',' n','m','l','k','j','i','h','g','f','e','d','c','b' ,'a',' ','Z','Y','X','W','V','U','T','S','R','Q','P','O', 'N','M','L','K','J','I','H','G','F','E','D','C','B ','A'}; String NewLine= new String(); char[] temp; int check=0; int i=0; int a,b; int x; if(e.getSource()== button1){ NewLine=textarea1.getText(); x=NewLine.length(); StringBuffer Encrypted= new StringBuffer(x+1); temp=new char[x+1]; NewLine.getChars(0,x,temp,0); for(i=0;i<=x;i++){ } a= temp[i]; for(check=0;check <= 52;check++){ b=Alpha[check]; if(a==b){ temp[i]= Rev[check]; check = 52; } } for(i=0;i<=x;i++){ Encrypted.append(temp[i]); } NewLine = Encrypted.toString(); textarea1.append(NewLine); } } } __________________________________________________ __________________________________________________ ___________ All of this compiled just fine. However, when I went to test the build I got this: java.lang.ArrayIndexOutOfBoundsException: 31 at ROT13let.actionPerformed(ROT13let.java:54) at java.awt.Button.processActionEvent(Button.java:382 ) at java.awt.Button.processEvent(Button.java:350) at java.awt.Component.dispatchEventImpl(Component.jav a:3615) at java.awt.Component.dispatchEvent(Component.java:34 77) at java.awt.EventQueue.dispatchEvent(EventQueue.java: 456) at java.awt.EventDispatchThread.pumpOneEventForHierar chy(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:151) at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:145) at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:137) at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:100) Since it was and ArrayIndexOutOfBoundsException I figured that it must be something to do with the Encrypted StringBuffer. I've tweaked that variable over and over again and this hasn't gone away. The only thing I can think of is I'm doing something verboten with the eventListener. If anyone can tell be what I'm doing wrong here I would be most grateful (again). Also, is there anyway I can just write char[] temp to the text area? All this converting between types seems really sloppy to me. Thanx, Jimmy Scythe |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > What's wrong with this applet? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|