Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Exception occurred during event dispatching

Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've writtten an applet for secure registration, but unfortunatley i get these following errors upon input:
Exception occurred during event dispatching:
at PasswordEntry2.actionPerformed(Compiled Code)
at java.awt.Button.processActionEvent(
at java.awt.Button.processEvent(
at java.awt.Component.dispatchEventImpl(Compiled Code)
at java.awt.Component.dispatchEvent(Compiled Code)
at java.awt.EventQueue.dispatchEvent(Compiled Code)
it opens up the link fine but does none of my crypto stuff, i've pasted the file nad am sorry if it's very big, but i'm fairly new to applets and this forum.
import java.math.BigInteger;
import java.lang.Character.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

public class PasswordEntry2 extends Applet
implements ActionListener {
private TextField usernameField;
private TextField passwordField;
private TextField emailField;
private Button sendButton;
private TextArea resultsArea;
private TextField hostField;
private TextField portField,statusField, uriField;
private BigInteger gk,Pgak;
URL currentPage;
public void init() {
gk = new BigInteger("0");
Pgak = new BigInteger("0");
this.setFont( new Font( "TimesRoman", Font.PLAIN, 14));
usernameField = new TextField(20);
usernameField.addActionListener( this);

this.setFont( new Font( "TimesRoman", Font.PLAIN, 14));
passwordField = new TextField(20);
passwordField.setEchoChar( '*');
passwordField.addActionListener( this);
this.setFont( new Font( "TimesRoman", Font.PLAIN, 14));
emailField = new TextField(20);
emailField.addActionListener( this);
this.setFont( new Font( "TimesRoman", Font.PLAIN, 14));
statusField = new TextField(25);
statusField.setText("password status");
statusField.addActionListener( this);
sendButton = new Button("Submit Data");
String resultsMessage = " confirmation of registration will appear here deedum";
resultsArea = new TextArea();
resultsArea.setFont(new Font("Monospaced", Font.PLAIN, 14));

this.add( usernameField);
this.add( passwordField);
this.add( emailField);
} // End init.

public void actionPerformed(ActionEvent event) {
try {
URL userUrl = new URL("";);
catch (Exception e) {
System.out.println(" Something happened with the web page opening ");

try {
// here are the connection parameters
String protocol = currentPage.getProtocol();
String host = currentPage.getHost();
String uri = "/cgi-bin/";
String portString = String.valueOf(currentPage.getPort());
int port;
try {
port = Integer.parseInt(portString);
catch(NumberFormatException nfe) {
port = -1; // I.e., default port of 80
// Here we must encrypt the password to get the ElGamal numbers
//String password = passwordField.getTextField().getText();
String password = passwordField.getText();
System.out.println( "past Elencrypt Pgak value in "+Pgak.toString());
System.out.println( "encoded version is " +URLEncoder.encode(Pgak.toString()) );
// NB this has set the values of gk and Pgak
URL dataURL = new URL(protocol, host, port, uri);
URLConnection connection = dataURL.openConnection();
// Make sure browser doesn't cache this URL.
// Tell browser to allow me to send data to server.
ByteArrayOutputStream byteStream =
new ByteArrayOutputStream(512); // Grows if necessary
// Stream that writes into buffer
PrintWriter out = new PrintWriter(byteStream, true);
System.out.println(" the parameter value of gk is "+URLEncoder.encode(gk.toString()) );
System.out.println(" the parameter value of Pgak is "+URLEncoder.encode(Pgak.toString()) );
String postData =
"userName=" + encodedValue(usernameField) +
"&gk=" + URLEncoder.encode(gk.toString()) +
"&Pgak=" + URLEncoder.encode(Pgak.toString()) +
"&emailAddress=" + encodedValue(emailField);
statusField.setText( "setting up parameters");
// Write POST data into local buffer
out.flush(); // Flush since above used print, not println
// POST requests are required to have Content-Length
String lengthString =
("Content-Length", lengthString);
// Netscape sets the Content-Type to multipart/form-data
// by default. So, if you want to send regular form data,
// you need to set it to
// application/x-www-form-urlencoded, which is the
// default for Internet Explorer. If you send
// serialized POST data with an ObjectOutputStream,
// the Content-Type is irrelevant, so you could
// omit this step.
("Content-Type", "application/x-www-form-urlencoded");
// Write POST data to real output stream
// let them know the passwords been sent
statusField.setText( "checking for server acknowledgement");
/* now we should confirm that the password has been successfully stored
We must snd something back form the perl script to this effect
The input Buffer willl pick it up and display it in the
Status field for us
//System.out.println( "about to set up input stream reader");
BufferedReader in =
new BufferedReader(new InputStreamReader
//System.out.println( "past input stream reader");
String line;
String linefeed = "\n";
statusField.setText( "");
while((line = in.readLine()) != null) {
// resultsArea.append(linefeed);
} catch(IOException ioe) {
// Print debug info in Java Console
System.out.println("IOException: " + ioe);
statusField.setText("Password sent");

private String encodedValue(TextField field) {
String rawValue = field.getText();

private void Elencrypt(String password)
/* let's set up the two values gk and Pgak here
They are private members so are accessible from the method
// Firstly our encryption data
BigInteger g = new BigInteger("3");
BigInteger ga = new BigInteger("27");
BigInteger n = new BigInteger("1331656851383141126634824735487135481");
BigInteger k = new BigInteger("2");
// ******************* to be changed to random *****************
BigInteger gak = new BigInteger("0");
BigInteger P = new BigInteger("0");
System.out.println( " P value in encrypt is "+P);
System.out.println( " Pgak value in encrypt is "+Pgak);
private BigInteger toNumber(String phrase)
toNumber encodes a phrase to its number equivalent
Constraints: phrase should be at most 10 characters
This needs to corrspond with the undo on the server
// Step 1 String to char array
int phraseLength = phrase.length();
char[] charArray = phrase.toCharArray();
// Step2 phrase to num equiv array eg tom -> 14,23,12
int count=0;
BigInteger P = new BigInteger("0");
BigInteger base = new BigInteger("256");
BigInteger basePow = new BigInteger("1");
BigInteger BigNumEquiv = new BigInteger("1");
int asciival = 0;
asciival=(int)charArray[count]; // determines the ascii value of a char
BigNumEquiv = new BigInteger(""+asciival); // changes int to String
System.out.println( " ascii value is "+BigNumEquiv);
return P;
} // end class PasswordEntry.
thanks for any help
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you were to surround the code with the [code] and [/code] UBB tags, then any formatting would be preserved and the code would be easier to follow. Note that you can edit your own post by clicking on the icon that looks like a piece of paper with a pencil - you don't have to repost your code.
It was the best of times. It was the worst of times. It was a tiny ad.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic