Solved

Can SOmeOne help me bout GUI???

Posted on 2002-03-26
2
251 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
Comment Utility
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
Comment Utility
thanx for the help
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now