Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old May 16th, 2004, 01:29 PM
Jimmy Scythe Jimmy Scythe is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 4 Jimmy Scythe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question What's wrong with this applet?

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

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > What's wrong with this applet?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT