Note that there are some explanatory texts on larger screens.

plurals
  1. POLooping JFrame window
    primarykey
    data
    text
    <p>I am writing an encryption program that lets the user enter a message and have it coded into a matrix, or have a set of matrices decoded. I have finished the core, and decided it would be more user friendly as a series of JFrame popup windows. I'm havind one last problem with the program, and that is in the decode method. The way it should work, is that the user enters how many matrices that make up the coded message, and the user input loops in a set of 3 inputs that many times in order to decode the message matrix by matrix. The problem i have is i am kind of lost on how to loop my user input JFrame like i did with my sample code. Here is the JFrame where the user enters how many matrices:</p> <pre><code>package matrix_with_GUI; import javax.swing.* ; import java.awt.event.* ; import java.awt.* ; public class DecodeMenu2 extends JFrame implements ActionListener{ private JButton action1 = new JButton (""); private JPanel pane = new JPanel(); private JLabel lbl; private TextField slot1 = new TextField(2); private double[][] junk = new double[3][3]; private String message = ""; public void DecodeMenu2(double[][] code){ junk = code; JPanel pane=new JPanel(); setTitle ("Start Menu") ; JFrame frame = new JFrame(""); setVisible(true); setSize (600, 150) ; setLocationRelativeTo (null) ; frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE) ; action1 = new JButton("Continue"); lbl = new JLabel (" How Many Matrices make up your coded message? (Every set of numbers in brackets is 1 matrix) "); setLayout(new FlowLayout()); add (lbl) ; add(slot1); add(action1, BorderLayout.CENTER); action1.addActionListener (this); } @Override public void actionPerformed(ActionEvent e) { int size = Integer.parseInt(slot1.getText()); DecodeCore x = new DecodeCore(); for(int count = size; count &gt; 0; count--){ x.DecodeCore(junk); message += x.getMessage(); } DecodePrint y = new DecodePrint(); y.DecodePrint(message); this.dispose(); } } </code></pre> <p>Here is the code that should loop with each click of the continue button, until "size" is reached:</p> <pre><code>package matrix_with_GUI; import javax.swing.* ; import java.awt.event.* ; import java.awt.* ; public class DecodeCore extends JFrame implements ActionListener{ private JButton action1 = new JButton (""); private JPanel pane = new JPanel(); private JLabel lbl; private TextField slot1 = new TextField(5); private TextField slot2 = new TextField(5); private TextField slot3 = new TextField(5); private String message = ""; private double[][] inverseCode = new double[3][3]; public void DecodeCore(double[][] code){ inverseCode = code; JPanel pane=new JPanel(); setTitle ("Start Menu") ; JFrame frame = new JFrame(""); setVisible(true); setSize (380, 150) ; setLocationRelativeTo (null) ; frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE) ; action1 = new JButton("Continue"); lbl = new JLabel (" Begin entering your Coded Message, one matrix at a time. "); setLayout(new FlowLayout()); add (lbl) ; add(slot1); add(slot2); add(slot3); add(action1, BorderLayout.CENTER); action1.addActionListener (this); } @Override public void actionPerformed(ActionEvent e) { int sum = 0, count = 0; int[] matrix = new int[3]; int[] entry = new int[3]; entry[0] = Integer.parseInt(slot1.getText()); entry[1] = Integer.parseInt(slot2.getText()); entry[3] = Integer.parseInt(slot3.getText()); for (int col = 0 ; col &lt; 3 ; col++ ){ for (int row = 0 ; row &lt; 3 ; row++ ){ sum += entry[row]*inverseCode[row][col]; } matrix[col] = sum; sum = 0; } while(count &lt; 3){ matrix[count] = Math.round(matrix[count] + 32); message += Character.toString((char) matrix[count]); count++; } count = 0; } public String getMessage(){ return message; } } </code></pre> <p>Sorry for the long post.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload