Solved

Can SOmeOne help me bout GUI???

Posted on 2002-03-26
2
286 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This video teaches viewers about errors in exception handling.
Suggested Courses

617 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