Solved

Can SOmeOne help me bout GUI???

Posted on 2002-03-26
2
268 Views
Last Modified: 2010-03-31
Can someone help me to put this coding into a GUI. Just a simple GUI. The GUI will display the n, d, e value in three different JTextField by click on the generate button. Pls can someone help me

import java.math.BigInteger;
import java.security.SecureRandom;

class kop
{
  public BigInteger n, d, e;

  public kop()
  {
    SecureRandom r = new SecureRandom();
    BigInteger p = new BigInteger(20 / 2, 100, r);
    System.out.println(p);
    BigInteger q = new BigInteger(20 / 2, 100, r);
    System.out.println(q);
    n = p.multiply(q);
    BigInteger m = p.subtract(BigInteger.ONE).multiply(q.subtract(BigInteger.ONE));
    e = new BigInteger("3");
    while(m.gcd(e).intValue() > 1) e = e.add(new BigInteger("2"));
    d = e.modInverse(m);
  }
 
  public static void main(String [] args)
  {
    kop t = new kop();
    System.out.println("n = " + t.n);
    System.out.println("e = " + t.e);
    System.out.println("d = " + t.d);
  }
}
0
Comment
Question by:lskoong
2 Comments
 
LVL 9

Accepted Solution

by:
Venci75 earned 300 total points
ID: 6896361
try this:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.math.*;
import java.security.*;
public class RndGUI extends JFrame {
  JTextField jTextField1 = new JTextField();
  JTextField jTextField2 = new JTextField();
  FlowLayout flowLayout1 = new FlowLayout();
  JTextField jTextField3 = new JTextField();
  JLabel jLabel1 = new JLabel();
  JLabel jLabel2 = new JLabel();
  JLabel jLabel3 = new JLabel();
  JButton jButton1 = new JButton();

  public RndGUI() {
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  private void jbInit() throws Exception {
    this.getContentPane().setLayout(flowLayout1);
    jTextField2.setColumns(8);
    jTextField3.setColumns(8);
    jLabel1.setText("n=");
    jLabel2.setText("e=");
    jLabel3.setText("d=");
    jTextField1.setColumns(8);
    jButton1.setText("Generate");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButton1_actionPerformed(e);
      }
    });
    this.getContentPane().add(jLabel1, null);
    this.getContentPane().add(jTextField1, null);
    this.getContentPane().add(jLabel2, null);
    this.getContentPane().add(jTextField2, null);
    this.getContentPane().add(jLabel3, null);
    this.getContentPane().add(jTextField3, null);
    this.getContentPane().add(jButton1, null);
    this.setSize(350, 100);
  }

  void jButton1_actionPerformed(ActionEvent ev) {
   BigInteger n, d, e;
   SecureRandom r = new SecureRandom();
   BigInteger p = new BigInteger(20 / 2, 100, r);
//   System.out.println(p);
   BigInteger q = new BigInteger(20 / 2, 100, r);
//   System.out.println(q);
   n = p.multiply(q);
   BigInteger m = p.subtract(BigInteger.ONE).multiply(q.subtract(BigInteger.ONE));
   e = new BigInteger("3");
   while(m.gcd(e).intValue() > 1) e = e.add(new BigInteger("2"));
   d = e.modInverse(m);
   jTextField1.setText(n.toString());
   jTextField2.setText(e.toString());
   jTextField3.setText(d.toString());
  }

  public static void main(String[] arg) {
      RndGUI f = new RndGUI();
      f.show();
  }
}
0
 

Author Comment

by:lskoong
ID: 6897120
thanx for the help
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Cipher Configuration on Apache HTTPD 4 62
servlet doXXX methods 3 49
configure dependency in POM for new database 3 25
Android development question 2 37
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question