gpt4 book ai didi

java - 如何更改循环内的 JTextField 值

转载 作者:行者123 更新时间:2023-11-30 07:26:36 25 4
gpt4 key购买 nike

我的程序需要一些帮助。我正在尝试制作一个强力程序作为项目,但我不知道如何使循环值出现在 print() 方法中的 JTextField 中。我不仅仅需要循环的最终值。我知道这个问题已经被问了很多次,我已经尝试了一切,但就是行不通。请问有人可以帮助我吗?我将不胜感激!

public class BF  implements ActionListener {
private JPanel contentPane;
private JTextField password;
private JTextField length;
public JTextField generateField;
JRadioButton numbers;
JButton generate;
JLabel passwordfound;
JLabel timelabel;
int min;
int max;
int stringLength;
private int[] chars;
String n="";
char[] passCom;
JFrame frame;

public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
BF frame = new BF();

} catch (Exception e) {
e.printStackTrace();
}
}
});
}

public BF() {
frame = new JFrame ("Brute Force Attack Program");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(100, 100, 754, 665);

frame.setResizable(false);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
frame.setLocationRelativeTo(null);
frame.setContentPane(contentPane);
contentPane.setLayout(null);
try {
UIManager.setLookAndFeel(
"com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch(Exception e) {
}
backgroundPanel panel = new backgroundPanel();
panel.setBounds(0, 0, 749, 633);
contentPane.add(panel);
panel.setLayout(null);

generate = new JButton("Find Password");
generate.setFont(new Font("Tahoma", Font.BOLD, 15));
generate.setBounds(292, 401, 145, 35);
generate.addActionListener(this);
panel.add(generate);

generateField = new JTextField();
generateField.setForeground(Color.WHITE);
generateField.setFont(new Font("Tahoma", Font.BOLD, 24));
generateField.setEditable(false);
generateField.setBounds(315, 449, 186, 54);
generateField.setBackground(new Color(0,0,0,0));
generateField.setBorder(javax.swing.BorderFactory.createEmptyBorder());
panel.add(generateField);
generateField.setColumns(10);


frame.setVisible(true);


}
public void run(char min, char max, int len)

{
this.min = min;

this.max = max;

this.stringLength = len;

chars = new int[stringLength + 1];

Arrays.fill(chars, 1, chars.length, min);


while (chars[0] == 0&&!n.equals(password.getText()))

{


print();

increment();
n=String.valueOf(passCom);

}


}

public void increment()

{

for (int i = chars.length - 1; i >= 0; i--)

{

if (chars[i] < max)

{

chars[i]++; return;

}

chars[i] = min;

}

}

public void print()

{
int x=0;
for (int i = 1; i < chars.length; i++)

{
passCom[x]=(char)chars[i];
x++;
String txt = new String (passCom);
generateField.setText(txt);


}

}




@Override
public void actionPerformed(ActionEvent e) {

if (!password.getText().equals("") && e.getSource() == generate && !length.getText().equals("")&&numbers.isSelected()){
int count = Integer.parseInt(length.getText());
passCom = new char [count];
run('0','9',count);
}

}
}

最佳答案

For example, the string 123 has length 3 so the permutations can be 000,001,002 etc

那为什么t时刻只显示一个呢?

相反,我会使用 JTextArea 并将每个值附加到文本字段,以便所有值同时可见。如果一次显示一个值,没有人会记住所有值。

否则,您将使用 Swing Timer一次显示一个。

关于java - 如何更改循环内的 JTextField 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36744591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com