⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fieldframe.java

📁 reed-solomon编码的java实现
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;

import field;

/**
 * Galois field frame.
 *
 * An frame for working and calculating in GF(2^k).
 *
 * @author Benjamin Barras
 * @version 1.10, 13/02/99
 * @email benjamin.barras@epfl.ch * */

public class fieldFrame extends Frame
  implements WindowListener,ActionListener
{
  Button buttonQuit;
  Button buttonSum;
  Button buttonMult;
  Button buttonDiv;
  Button buttonPower;
  Button buttonAlpha;
  Button buttonpolynomial;

  TextField textFieldSum1;
  TextField textFieldSum2;
  TextField textFieldSum;
  TextField textFieldMult1;
  TextField textFieldMult2;
  TextField textFieldMult;
  TextField textFieldDiv1;
  TextField textFieldDiv2;
  TextField textFieldDiv;
  TextField textFieldNumber;
  TextField textFieldPower;
  TextField textFieldPower1;
  TextField textFieldPower2;
  TextField textFieldAlpha;
  TextField textFieldAlpha1;
  TextField textFieldpolynomial;

  field gf;

  public fieldFrame(int k, int p)
  {
    String str= new String("");

    gf = new field();

    gf.generate(k,p);
    setFont(new Font("Helvetica",Font.PLAIN,14));
    str= "Galois Field : GF(2^k) with ";
    str= str+ " k = " + Integer.toString(gf.k,10);
    str= str+ " and " + Integer.toString(gf.q,10) + " elements.";
    setTitle(str);

    Panel row1 = new Panel(); 
    Panel row2 = new Panel(); 
    Panel row3 = new Panel(); 
    Panel row4 = new Panel(); 
    Panel row5 = new Panel(); 
    Panel row6 = new Panel(); 
    Panel row7 = new Panel(); 
    Panel row8 = new Panel(); 

    textFieldSum1 = new TextField(10);
    textFieldSum2 = new TextField(10);
    textFieldSum = new TextField(10);
    textFieldMult1 = new TextField(10);
    textFieldMult2 = new TextField(10);
    textFieldMult = new TextField(10);
    textFieldDiv1 = new TextField(10);
    textFieldDiv2 = new TextField(10);
    textFieldDiv = new TextField(10);
    textFieldPower1 = new TextField(10);
    textFieldPower2 = new TextField(10);
    textFieldPower = new TextField(10);
    textFieldAlpha1 = new TextField(10);
    textFieldAlpha = new TextField(10);
    textFieldNumber = new TextField(10);
    textFieldpolynomial = new TextField(50);

    textFieldSum1.setBackground(Color.white);
    textFieldSum2.setBackground(Color.white);
    textFieldSum.setBackground(Color.white);
    textFieldMult1.setBackground(Color.white);
    textFieldMult2.setBackground(Color.white);
    textFieldMult.setBackground(Color.white);
    textFieldDiv1.setBackground(Color.white);
    textFieldDiv2.setBackground(Color.white);
    textFieldDiv.setBackground(Color.white);
    textFieldPower1.setBackground(Color.white);
    textFieldPower2.setBackground(Color.white);
    textFieldPower.setBackground(Color.white);
    textFieldAlpha1.setBackground(Color.white);
    textFieldAlpha.setBackground(Color.white);
    textFieldNumber.setBackground(Color.white);
    textFieldpolynomial.setBackground(Color.white);

    buttonSum = new Button(" = ");
    buttonMult = new Button(" = ");
    buttonDiv = new Button(" = ");
    buttonPower = new Button(" = ");
    buttonAlpha = new Button(" = a^ ");
    buttonpolynomial = new Button(" GF(2^k) ");
    buttonQuit = new Button("Quit");

    buttonSum.addActionListener(this);
    buttonMult.addActionListener(this);
    buttonDiv.addActionListener(this);
    buttonPower.addActionListener(this);
    buttonAlpha.addActionListener(this);
    buttonpolynomial.addActionListener(this);
    buttonQuit.addActionListener(this);

    setLayout(new GridLayout(8,1,10,10));
    row1.setLayout(new FlowLayout());
    row2.setLayout(new FlowLayout());
    row3.setLayout(new FlowLayout());
    row4.setLayout(new FlowLayout());
    row5.setLayout(new FlowLayout());
    row6.setLayout(new FlowLayout());
    row7.setLayout(new FlowLayout());
    row8.setLayout(new FlowLayout());

    str = gf.polynomialToString(gf.primitive,"X");
    str = "Primitive polynomial P(X) = " + str + " with P(alpha) = 0";
    str = str + " (notation : alpha = a)";
    row1.add(new Label(str));

    row2.add(textFieldSum1);
    row2.add(new Label(" + "));
    row2.add(textFieldSum2);
    row2.add(buttonSum);
    row2.add(textFieldSum);

    row3.add(textFieldMult1);
    row3.add(new Label(" * "));
    row3.add(textFieldMult2);
    row3.add(buttonMult);
    row3.add(textFieldMult);

    row4.add(textFieldDiv1);
    row4.add(new Label(" / "));
    row4.add(textFieldDiv2);
    row4.add(buttonDiv);
    row4.add(textFieldDiv);

    row5.add(textFieldPower1);
    row5.add(new Label(" ^ "));
    row5.add(textFieldPower2);
    row5.add(buttonPower);
    row5.add(textFieldPower);

    row6.add(textFieldAlpha1);
    row6.add(buttonAlpha);
    row6.add(textFieldAlpha);

    row7.add(textFieldNumber);
    row7.add(buttonpolynomial);
    row7.add(textFieldpolynomial);

    row8.add(buttonQuit);

    add(row1);
    add(row2);
    add(row3);
    add(row4);
    add(row5);
    add(row6);
    add(row7);
    add(row8);
    pack();
    show();
  }
  
  public void windowClosing(WindowEvent event)
  {
  }
  
  public void windowClosed(WindowEvent event)
  {
  }
  
  public void windowDeiconified(WindowEvent event)
  {
  }
  
  public void windowIconified(WindowEvent event)
  {
  }
  
  public void windowActivated(WindowEvent event)
  {
  }
  
  public void windowDeactivated(WindowEvent event)
  {
  }
  
  public void windowOpened(WindowEvent event)
  {
  }
  
  public void actionPerformed(ActionEvent evt)

  {
    int a,b,r;
    String str;

    Object source = evt.getSource();
    if (source == buttonQuit) 
    { 
      dispose();
    }
    if (source == buttonSum) 
    {
      str = textFieldSum1.getText();
      a = Integer.parseInt(str,10); a = gf.inField(a);
      str = textFieldSum2.getText();
      b = Integer.parseInt(str,10); b = gf.inField(b);
      r = gf.add(a,b);
      str = Integer.toString(r,10);
      textFieldSum.setText(str);
    }
    if (source == buttonMult) 
    {
      str = textFieldMult1.getText();
      a = Integer.parseInt(str,10); a = gf.inField(a);
      str = textFieldMult2.getText();
      b = Integer.parseInt(str,10); b = gf.inField(b);
      r = gf.mul(a,b);
      str = Integer.toString(r,10);
      textFieldMult.setText(str);
    }
    if (source == buttonDiv) 
    { 
      str = textFieldDiv1.getText();
      a = Integer.parseInt(str,10); a = gf.inField(a);
      str = textFieldDiv2.getText();
      b = Integer.parseInt(str,10); b = gf.inField(b);
      r = gf.div(a,b);
      str = Integer.toString(r,10);
      textFieldDiv.setText(str);
    }
    if (source == buttonPower) 
    {
      str = textFieldPower1.getText();
      a = Integer.parseInt(str,10); a = gf.inField(a);
      str = textFieldPower2.getText();
      b = Integer.parseInt(str,10); b = b % gf.n;
      r = gf.pow(a,b);
      str = Integer.toString(r,10);
      textFieldPower.setText(str);
    }
    if (source == buttonAlpha) 
    {
      str = textFieldAlpha1.getText();
      a = Integer.parseInt(str,10); a = gf.inField(a);
      r = gf.getPowerOfElement(a);
      str = Integer.toString(r,10);
      textFieldAlpha.setText(str);
    }
    if (source == buttonpolynomial) 
    { 
      str = textFieldNumber.getText();
      a = Integer.parseInt(str,10);
      str = gf.polynomialToString(a,"a");
      textFieldpolynomial.setText(str);
    }
 }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -