带界面的AES算法JAVA实现

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

界面效果:窗口操作界面源代码importjava.awt.BorderLayout;importjava.awt.Container;importjava.awt.FlowLayout;importjava.awt.GridLayout;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.WindowAdapter;importjava.awt.event.WindowEvent;importjava.io.File;importjavax.swing.ButtonGroup;importjavax.swing.JButton;importjavax.swing.JFileChooser;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JOptionPane;importjavax.swing.JPanel;importjavax.swing.JRadioButton;importjavax.swing.JTextField;importjavax.swing.SwingConstants;publicclassAESFrameextendsJFrameimplementsActionListener{privateJLabelsourceLabel,aimLabel,keyLabel;privateJTextFieldsourceText,aimText,keyText;privateJButtonencryptBt,decryptBt,clearBt,exitBt,selectSourceBt,selectAimBt;privateJRadioButton[]methodRadioButtons=newJRadioButton[2];privateButtonGroupmethodGroup=newButtonGroup();publicstaticvoidmain(String[]args){newAESFrame(AES加密解密工具By:***);}publicAESFrame(Stringtitle){super(title);//初始化组件keyLabel=newJLabel(密钥,SwingConstants.RIGHT);sourceLabel=newJLabel(源文件,SwingConstants.RIGHT);aimLabel=newJLabel(目标文件,SwingConstants.RIGHT);keyText=newJTextField(20);sourceText=newJTextField(20);aimText=newJTextField(20);encryptBt=newJButton(加密);decryptBt=newJButton(解密);clearBt=newJButton(清空);exitBt=newJButton(退出);selectSourceBt=newJButton(浏览);selectAimBt=newJButton(浏览);methodRadioButtons[0]=newJRadioButton(文件);methodRadioButtons[1]=newJRadioButton(字符串);methodGroup.add(methodRadioButtons[0]);methodGroup.add(methodRadioButtons[1]);methodRadioButtons[0].setSelected(true);//划分面板Containerc=this.getContentPane();c.setLayout(newBorderLayout());JPanelcenterPanel=newJPanel();JPanelnorthPanel=newJPanel();JPanelsouthPanel=newJPanel();JPaneleastPanel=newJPanel();JPanelwestPanel=newJPanel();c.add(eastPanel,BorderLayout.EAST);c.add(westPanel,BorderLayout.WEST);northPanel.setLayout(newGridLayout(1,3));JPanelnorthLeftPanel=newJPanel();JPanelnorthCenterPanel=newJPanel();JPanelnorthRightPanel=newJPanel();northCenterPanel.setLayout(newFlowLayout());northCenterPanel.add(methodRadioButtons[0]);northCenterPanel.add(methodRadioButtons[1]);northPanel.add(northLeftPanel);northPanel.add(northCenterPanel);northPanel.add(northRightPanel);c.add(northPanel,BorderLayout.NORTH);southPanel.setLayout(newGridLayout(1,2));JPanelsouthLeftPanel=newJPanel(newFlowLayout());JPanelsouthRightPanel=newJPanel(newFlowLayout());southLeftPanel.add(encryptBt);southLeftPanel.add(decryptBt);southRightPanel.add(clearBt);southRightPanel.add(exitBt);southPanel.add(southLeftPanel);southPanel.add(southRightPanel);c.add(southPanel,BorderLayout.SOUTH);centerPanel.setLayout(newBorderLayout());JPanelcenterEastPanel=newJPanel(newGridLayout(3,1));JPanelcenterWestPanel=newJPanel(newGridLayout(3,1));JPanelcenterCenterPanel=newJPanel(newGridLayout(3,1));JPanelcenterSouthPanel=newJPanel();JPanelcenterNorthPanel=newJPanel();JPanelpanel1=newJPanel(newFlowLayout());JPanelpanel2=newJPanel(newFlowLayout());JPanelpanel3=newJPanel(newFlowLayout());JPanelpanel4=newJPanel(newFlowLayout());JPanelpanel5=newJPanel(newFlowLayout());JPanelpanel6=newJPanel(newFlowLayout());JPanelpanel7=newJPanel(newFlowLayout());JPanelpanel8=newJPanel(newFlowLayout());JPanelpanel9=newJPanel(newFlowLayout());panel1.add(sourceLabel);panel2.add(sourceText);panel3.add(selectSourceBt);panel4.add(aimLabel);panel5.add(aimText);panel6.add(selectAimBt);panel7.add(keyLabel);panel8.add(keyText);centerWestPanel.add(panel1);centerWestPanel.add(panel4);centerWestPanel.add(panel7);centerCenterPanel.add(panel2);centerCenterPanel.add(panel5);centerCenterPanel.add(panel8);centerEastPanel.add(panel3);centerEastPanel.add(panel6);centerEastPanel.add(panel9);centerPanel.add(centerEastPanel,BorderLayout.EAST);centerPanel.add(centerWestPanel,BorderLayout.WEST);centerPanel.add(centerCenterPanel,BorderLayout.CENTER);centerPanel.add(centerSouthPanel,BorderLayout.SOUTH);centerPanel.add(centerNorthPanel,BorderLayout.NORTH);c.add(centerPanel,BorderLayout.CENTER);//加入按钮监听encryptBt.addActionListener(this);decryptBt.addActionListener(this);clearBt.addActionListener(this);exitBt.addActionListener(this);selectSourceBt.addActionListener(this);selectAimBt.addActionListener(this);methodRadioButtons[0].addActionListener(this);methodRadioButtons[1].addActionListener(this);//设置关闭按钮//createanonymousinnerclassforwindowsclosingeventthis.addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEventevent){//invokeexitinouterclassSystem.exit(0);}});pack();//设置界面大小setSize(400,300);setLocation(0,0);setVisible(true);}@OverridepublicvoidactionPerformed(ActionEvente){//TODOAuto-generatedmethodstubif(e.getSource().equals(methodRadioButtons[0])){sourceLabel.setText(源文件);aimLabel.setText(目标文件);selectSourceBt.setEnabled(true);selectAimBt.setEnabled(true);clear();}if(e.getSource().equals(methodRadioButtons[1])){sourceLabel.setText(源字符串);aimLabel.setText(目标字符串);selectSourceBt.setEnabled(false);selectAimBt.setEnabled(false);clear();}if(e.getSource().equals(selectSourceBt)

1 / 19
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功