Solved

Can SOmeOne help me bout GUI???

Posted on 2002-03-26
2
281 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

738 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