I have a main array in the program that the user gives the index of via textfield:
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class Main {
static JTextArea results = new JTextArea();
static int Gen = 0;
static JLabel l4 = new JLabel(" Generated: "+Gen);
static JFrame w = new JFrame("Final");
static JTextField t3 = new JTextField();
static String[] values = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L","M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0","1","2", "3", "4", "5", "6", "7", "8", "9"};
public static void main(String[] args){
JPanel a = new JPanel(new FlowLayout());
JLabel l3 = new JLabel("Size:");
t3.setPreferredSize(new Dimension( 100, 20));
JButton start = new JButton("Start!");
results.setToolTipText("This is where the generated keys will be displayed");
start.addActionListener(new startClicked());
a.add(l3);
a.add(t3);
a.add(start);
w.add(a, BorderLayout.NORTH);
w.add(l4, BorderLayout.SOUTH);
JScrollPane scroll = new JScrollPane(results);
w.add(scroll, BorderLayout.CENTER);
results.setEditable(false);
w.setLocationRelativeTo(null);
w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
w.setVisible(true);
w.setResizable(true);
w.setSize(new Dimension( 600, 400));
w.setMinimumSize(new Dimension(600, 400));
}
static class startClicked implements ActionListener{
public void actionPerformed(ActionEvent e){
if(t3.getText().isEmpty() != true){
compile();
}else{
JOptionPane.showMessageDialog(null, "No number");
}
}
}
public static void compile(){
}
public static cha开发者_运维百科r[] genNext(char[] s){
for(int i = 0; i<=s.length; i++){
if(s[i]=='Z'){
s[i] = 0;
incr(s[i+1]);
return s;
}
}
return null;
}
public static char incr(char c){
return c;
}
}
when a button is pressed it gets the number typed into the box as the array's index: so i.e : 5 then the array is [0,0,0,0,0]
The first or last 0 in the array(array[0] or array[4]) is then replaced by '0'-'9' then followed by 'a'-'z'.
So [0,0,0,0,0] will be [0,0,0,0,1] and when its done it will be [0,0,0,0,Z].
Now when that index is 'Z' the index previous will be 0 then repeats as previous but 'Z' gets reset back to 'A' then it repeats back to 'Z'
So this is what it will look like in a since:
Start [0,0,0,0,0] Finished [Z,Z,Z,Z,Z]
and all of the outcomes should be displayed in a textarea on a new line.
Any and all help is appreciated
**Solutions to this can be complex or simple, as long as
Maybe this might help:
long start = 0;
long stop = Long.parseLong("ZZZZZ", 36);
for (long i = start; i <= stop; ++i)
{
System.out.println(Long.toString(i, 36).toUpperCase());
}
精彩评论