Solved

Can SOmeOne help me bout GUI???

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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…

920 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

13 Experts available now in Live!

Get 1:1 Help Now