📄 diccreate.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class DicCreate extends JFrame implements ItemListener,ActionListener
{
JLabel passnumlabel,numlabel;
JComboBox passnumjcb;
JCheckBox numjcb[] = new JCheckBox[10];
JRadioButton choosejrb[] = new JRadioButton[10];
ButtonGroup choosebtg = new ButtonGroup();
JCheckBox bigletterjcb[] = new JCheckBox[26];
JCheckBox smallletterjcb[] =new JCheckBox[26];
JCheckBox[] otherchar =new JCheckBox[34];
JButton allselbutton,allselbutton2,allselbutton3,allselbutton4,savebutton;
JButton allremove,allremove2,allremove3,allremove4;
JButton ok,cancel;
boolean choosen = false;
SetPanel setpanel[] = new SetPanel[11];
String num[] = new String[10];
String letter[] = new String[52];
String otherchar2[] = new String[34];
String passnum[] = {"","6","7","8","9","10"};
JTextField savejtf;
int k;
int sum1=1;
public DicCreate(){
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
SwingUtilities.updateComponentTreeUI(DicCreate.this);
}
catch(Exception e)
{
e.printStackTrace();
}
Container container = getContentPane();
passnumlabel = new JLabel("密码位数:");
JPanel passnum = new JPanel();
passnum.setLayout(new FlowLayout(FlowLayout.LEFT));
passnum.add(passnumlabel);
for(int i=0;i<10;i++)
{
String numstr = String.valueOf(i+1);
choosejrb[i] = new JRadioButton(numstr);
choosebtg.add(choosejrb[i]);
passnum.add(choosejrb[i]);
}
choosejrb[0].setSelected(true);
numlabel = new JLabel("数字:");
allselbutton = new JButton("全选");
allremove = new JButton("清除");
allremove2 = new JButton("清除");
allremove3 = new JButton("清除");
allremove4 = new JButton("清除");
ok= new JButton("确定");
cancel= new JButton("取消");
JPanel numpanel = new JPanel();
numpanel.setLayout(new FlowLayout(FlowLayout.LEFT,8,5));
numpanel.add(numlabel);
numpanel.add(new JLabel(" "));
for(int i=0;i<10;i++)
{
String numstr = String.valueOf(i);
numjcb[i] = new JCheckBox(numstr);
numpanel.add(numjcb[i]);
}
numpanel.add(new JLabel(""));
numpanel.add(allselbutton);
numpanel.add(allremove);
JLabel letterlabel = new JLabel("字母:");
for(int i=0;i<26;i++)
{
String letterstr = String.valueOf((char)(65+i));
bigletterjcb[i] =new JCheckBox(letterstr);
}
for(int i=0;i<26;i++)
{
String letterstr = String.valueOf((char)(97+i));
smallletterjcb[i] =new JCheckBox(letterstr);
}
JPanel letterpanel1 = new JPanel();
letterpanel1.setLayout(new FlowLayout(FlowLayout.LEFT,7,5));
letterpanel1.add(letterlabel);
letterpanel1.add(new JLabel(" "));
for(int i=0;i<10;i++)
{
letterpanel1.add(bigletterjcb[i]);
}
letterpanel1.add(new JLabel(" "));
allselbutton2 = new JButton("全选");
letterpanel1.add(allselbutton2);
letterpanel1.add(allremove2);
JPanel letterpanel2 = new JPanel();
letterpanel2.setLayout(new FlowLayout(FlowLayout.LEFT,7,5));
letterpanel2.add(new JLabel(" "));
for(int i=10;i<20;i++)
{
letterpanel2.add(bigletterjcb[i]);
}
JPanel letterpanel3 = new JPanel(new FlowLayout(FlowLayout.LEFT,7,5));
letterpanel3.add(new JLabel(" "));
for(int i=20;i<26;i++)
{
letterpanel3.add(bigletterjcb[i]);
}
JPanel bigletterpanel = new JPanel();
bigletterpanel.setLayout(new BorderLayout());
bigletterpanel.add(letterpanel1,BorderLayout.NORTH);
bigletterpanel.add(letterpanel2,BorderLayout.CENTER);
bigletterpanel.add(letterpanel3,BorderLayout.SOUTH);
JPanel smallletterpanel1 = new JPanel();
allselbutton3 = new JButton("全选");
smallletterpanel1.setLayout(new FlowLayout(FlowLayout.LEFT,9,5));
smallletterpanel1.add(new JLabel(" "));
for(int i=0;i<10;i++)
{
smallletterpanel1.add(smallletterjcb[i]);
}
smallletterpanel1.add(new JLabel(" "));
smallletterpanel1.add(allselbutton3);
smallletterpanel1.add(allremove3);
JPanel smallletterpanel2 = new JPanel();
smallletterpanel2.setLayout(new FlowLayout(FlowLayout.LEFT,9,5));
smallletterpanel2.add(new JLabel(" "));
for(int i=10;i<20;i++)
{
smallletterpanel2.add(smallletterjcb[i]);
}
JPanel smallletterpanel3 = new JPanel();
smallletterpanel3.setLayout(new FlowLayout(FlowLayout.LEFT,9,5));
smallletterpanel3.add(new JLabel(" "));
for(int i=20;i<26;i++)
{
smallletterpanel3.add(smallletterjcb[i]);
}
JPanel smallletterpanel = new JPanel();
smallletterpanel.setLayout(new BorderLayout());
smallletterpanel.add(smallletterpanel1,BorderLayout.NORTH);
smallletterpanel.add(smallletterpanel2,BorderLayout.CENTER);
smallletterpanel.add(smallletterpanel3,BorderLayout.SOUTH);
JPanel letterpanel = new JPanel();
letterpanel.setLayout(new BorderLayout());
letterpanel.add(bigletterpanel,BorderLayout.NORTH);
letterpanel.add(smallletterpanel,BorderLayout.CENTER);
for(int i=0;i<otherchar.length;i++)
{
otherchar[i] = new JCheckBox();
}
JLabel othercharjlb = new JLabel("其它: ");
for(int i=1;i<=15;i++)
{
otherchar[i].setText(String.valueOf((char)(32+i)));
}
for(int i=16;i<=22;i++)
{
otherchar[i].setText(String.valueOf((char)(42+i)));
}
for(int i=23;i<=28;i++)
{
otherchar[i].setText(String.valueOf((char)(68+i)));
}
for(int i=29;i<=32;i++)
{
otherchar[i].setText(String.valueOf((char)(94+i)));
}
otherchar[33].setText("空格");
JPanel other1 = new JPanel(new FlowLayout(FlowLayout.LEFT,8,5));
JPanel other2 = new JPanel(new FlowLayout(FlowLayout.LEFT,8,5));
JPanel other3 = new JPanel(new FlowLayout(FlowLayout.LEFT,8,5));
JPanel other4 = new JPanel(new FlowLayout(FlowLayout.LEFT,8,5));
other1.add(othercharjlb);
for(int i=1;i<=10;i++)
{
other1.add(otherchar[i]);
}
allselbutton4 =new JButton("全选");
other1.add(new JLabel(" "));
other1.add(allselbutton4);
other1.add(allremove4);
other2.add(new JLabel(" "));
for(int i=11;i<=20;i++)
{
other2.add(otherchar[i]);
}
other3.add(new JLabel(" "));
for(int i=21;i<=30;i++)
{
other3.add(otherchar[i]);
}
other4.add(new JLabel(" "));
for(int i=31;i<=33;i++)
{
other4.add(otherchar[i]);
}
other4.add(new JLabel(" "));
other4.add(ok);
other4.add(cancel);
JPanel other2_3 =new JPanel();
other2_3.setLayout(new BorderLayout());
other2_3.add(other2,BorderLayout.NORTH);
other2_3.add(other3,BorderLayout.CENTER);
JPanel otherpanel = new JPanel(new BorderLayout());
otherpanel.add(other1,BorderLayout.NORTH);
otherpanel.add(other2_3,BorderLayout.CENTER);
otherpanel.add(other4,BorderLayout.SOUTH);
JPanel choosepanel = new JPanel();
choosepanel.setLayout(new BorderLayout());
choosepanel.add(numpanel,BorderLayout.NORTH);
choosepanel.add(letterpanel,BorderLayout.CENTER);
choosepanel.add(otherpanel,BorderLayout.SOUTH);
JPanel setpospanel = new JPanel(new GridLayout(2,5));
for(int i=1;i<11;i++)
{
setpanel[i] =new SetPanel(i);
setpospanel.add(setpanel[i]);
}
JPanel savefilejp = new JPanel(new FlowLayout(FlowLayout.CENTER,8,5));
JLabel savelabel = new JLabel("保存路径");
savejtf = new JTextField(20);
savejtf.setBackground(Color.WHITE);
savebutton = new JButton("生成字典");
savefilejp.add(savelabel);
savefilejp.add(savejtf);
savefilejp.add(savebutton);
JPanel choose_save = new JPanel(new BorderLayout());
choose_save.add(choosepanel,BorderLayout.NORTH);
choose_save.add(setpospanel,BorderLayout.CENTER);
choose_save.add(savefilejp,BorderLayout.SOUTH);
container.setLayout(new BorderLayout());
container.add(passnum,BorderLayout.CENTER);
container.add(choose_save,BorderLayout.SOUTH);
//passnumjcb.addItemListener(this);
allselbutton.addActionListener(this);
allselbutton2.addActionListener(this);
allselbutton3.addActionListener(this);
allselbutton4.addActionListener(this);
allremove.addActionListener(this);
allremove2.addActionListener(this);
allremove3.addActionListener(this);
allremove4.addActionListener(this);
ok.addActionListener(this);
cancel.addActionListener(this);
savebutton.addActionListener(this);
for(int i=1;i<11;i++)
{
setpanel[i].num1.addItemListener(this);
setpanel[i].letter1.addItemListener(this);
setpanel[i].otherchar1.addItemListener(this);
}
for(int i=0;i<10;i++)
{
choosejrb[i].addItemListener(this);
}
Setting(1);
this.setTitle("欢迎使用Super密码字典生成工具");
this.setSize(740,748);
this.setVisible(true);
}
public void itemStateChanged(ItemEvent e)
{
if(e.getSource() instanceof JRadioButton)
{
if(choosejrb[0].isSelected())
{
Setting(1);
sum1=1;
}
if(choosejrb[1].isSelected())
{
Setting(2);
sum1=2;
}
if(choosejrb[2].isSelected())
{
Setting(3);
sum1=3;
}
if(choosejrb[3].isSelected())
{
Setting(4);
sum1=4;
}
if(choosejrb[4].isSelected())
{
Setting(5);
sum1=5;
}
if(choosejrb[5].isSelected())
{
Setting(6);
sum1=6;
}
if(choosejrb[6].isSelected())
{
Setting(7);
sum1=7;
}
if(choosejrb[7].isSelected())
{
Setting(8);
sum1=8;
}
if(choosejrb[8].isSelected())
{
Setting(9);
sum1=9;
}
if(choosejrb[9].isSelected())
{
Setting(10);
sum1=10;
}
}
if((e.getSource()==setpanel[1].num1)||(e.getSource()==setpanel[2].num1)||(e.getSource()==setpanel[3].num1)
||(e.getSource()==setpanel[4].num1)||(e.getSource()==setpanel[5].num1)||(e.getSource()==setpanel[6].num1)
||(e.getSource()==setpanel[7].num1)||(e.getSource()==setpanel[8].num1)||(e.getSource()==setpanel[9].num1)
||(e.getSource()==setpanel[10].num1))
{
if(e.getStateChange()==2&&choosen==true)
{
for(int index=1;index<11;index++)
{ System.out.println("index:"+index);
if(e.getSource()==setpanel[index].num1)
{
Setnum2(index);
break;
}
}
}
}
if((e.getSource()==setpanel[1].letter1)||(e.getSource()==setpanel[2].letter1)||(e.getSource()==setpanel[3].letter1)
||(e.getSource()==setpanel[4].letter1)||(e.getSource()==setpanel[5].letter1)||(e.getSource()==setpanel[6].letter1)
||(e.getSource()==setpanel[7].letter1)||(e.getSource()==setpanel[8].letter1)||(e.getSource()==setpanel[9].letter1)
||(e.getSource()==setpanel[10].letter1))
{
if(e.getStateChange()==2&&choosen==true)
{
for(int index=1;index<11;index++)
{ System.out.println("index:"+index);
if(e.getSource()==setpanel[index].letter1)
{
Setletter2(index);
break;
}
}
}
}
if((e.getSource()==setpanel[1].otherchar1)||(e.getSource()==setpanel[2].otherchar1)||(e.getSource()==setpanel[3].otherchar1)
||(e.getSource()==setpanel[4].otherchar1)||(e.getSource()==setpanel[5].otherchar1)||(e.getSource()==setpanel[6].otherchar1)
||(e.getSource()==setpanel[7].otherchar1)||(e.getSource()==setpanel[8].otherchar1)||(e.getSource()==setpanel[9].otherchar1)
||(e.getSource()==setpanel[10].otherchar1))
{
if(e.getStateChange()==2&&choosen==true)
{
for(int index=1;index<11;index++)
{ System.out.println("index:"+index);
if(e.getSource()==setpanel[index].otherchar1)
{
Setotherchar2(index);
break;
}
}
}
}
}
public void Setnum2(int index)
{
setpanel[index].numindex2=0;
for(int i=0;i<10;i++)
{
if(num[setpanel[index].numindex2].equals(setpanel[index].num1.getItemAt(setpanel[index].num1.getSelectedIndex())))
break;
setpanel[index].numindex2++;
}
setpanel[index].num2.removeAllItems();
//setpanel[index].num2.addItem(new String(""));
for(int k=setpanel[index].numindex2;k<10;k++)
{
System.out.println(k);
if(num[k]==null) break;
setpanel[index].num2.addItem(num[k]);
}
}
public void Setletter2(int index)
{setpanel[index].letterindex2=0;
for(int i=0;i<52;i++)
{
if(letter[setpanel[index].letterindex2].equals(setpanel[index].letter1.getItemAt(setpanel[index].letter1.getSelectedIndex())))
break;
setpanel[index].letterindex2++;
}
setpanel[index].letter2.removeAllItems();
//setpanel[index].letter2.addItem(new String(""));
for(int k=setpanel[index].letterindex2;k<52;k++)
{
System.out.println(k);
if(letter[k]==null) break;
setpanel[index].letter2.addItem(letter[k]);
}
}
public void Setotherchar2(int index)
{ setpanel[index].othercharindex2=1;
for(int i=1;i<34;i++)
{
if(otherchar2[setpanel[index].othercharindex2].equals(setpanel[index].otherchar1.getItemAt(setpanel[index].otherchar1.getSelectedIndex())))
break;
setpanel[index].othercharindex2++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -