📄 jiamijiemi.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JiaMiJieMi extends JFrame
{
private JButton calculateJButton,calculateJButton1;
private JLabel textJLabel,pictureJLabel,yuanshuJLabel,jiamiJLabel,jiemishuJLabel,jiemiJLabel;
private JTextField yuanshuJTextField,jiemishuJTextField,jiamiResultJTextField,jiemiResultJTextField;
public JiaMiJieMi()
{
createUserInterface();
}
//创建一个contentpane容器颜色为粉色
public void createUserInterface()
{ Container c = getContentPane();
c.setBackground( Color.pink);
c.setLayout( null );
//创建并添加一个Jlabel1();
textJLabel = new JLabel();
textJLabel.setText( "数据加密" );
textJLabel.setLocation( 300, 100 ); //设置Jlabel1坐标
textJLabel.setSize( 550, 50 ); //设置Jlabel1的大小
textJLabel.setFont( new Font( "SansSerif", Font.PLAIN, 26 ) ); //设置Jlabel1中文本的字体属性
textJLabel.setHorizontalAlignment( JLabel.CENTER ); //设置Jlabel1中文字居中
c.add( textJLabel );
textJLabel = new JLabel();
textJLabel.setText( "数据解密" );
textJLabel.setLocation( 300, 300 ); //设置Jlabel1坐标
textJLabel.setSize( 550, 50 ); //设置Jlabel1的大小
textJLabel.setFont( new Font( "SansSerif", Font.PLAIN, 26 ) ); //设置Jlabel1中文本的字体属性
textJLabel.setHorizontalAlignment( JLabel.CENTER ); //设置Jlabel1中文字居中
c.add( textJLabel );
Icon icon=new ImageIcon ("椰风.jpg");
pictureJLabel=new JLabel (icon);
pictureJLabel.setBounds(0,0,475,600);
c.add(pictureJLabel);
yuanshuJLabel = new JLabel();
yuanshuJLabel.setText( "数 据:" ); //设置文本内容为“数据:”
yuanshuJLabel.setBounds( 500, 170, 130, 21 );//设置Jlabel的坐标和大小
c.add( yuanshuJLabel );
jiemishuJLabel = new JLabel();
jiemishuJLabel.setText( "解密数据:" ); //设置文本内容为“数据:”
jiemishuJLabel.setBounds( 500, 370, 130, 21 );//设置Jlabel的坐标和大小
c.add( jiemishuJLabel );
//创建JtextField
yuanshuJTextField = new JTextField();
yuanshuJTextField.setText( "" );
yuanshuJTextField.setBounds(550, 170, 70, 21 );//设置JtextField坐标和大小
yuanshuJTextField.setHorizontalAlignment( JTextField.RIGHT );//设置整个标签右对齐
c.add(yuanshuJTextField );
yuanshuJTextField.addKeyListener(//设置监听方式
new KeyAdapter()
{
//设置监听方式为键盘输入事件
public void keyPressed( KeyEvent event )
{
yuanshuJTextFieldKeyPressed( event );
}
}
);
jiemishuJTextField = new JTextField();
jiemishuJTextField.setText( "" );
jiemishuJTextField.setBounds(560, 370, 70, 21 );//设置JtextField坐标和大小
jiemishuJTextField.setHorizontalAlignment( JTextField.RIGHT );//设置整个标签右对齐
c.add(jiemishuJTextField );
jiamiJLabel = new JLabel();
jiamiJLabel.setText( "加 密:" );
jiamiJLabel.setBounds( 500, 170, 100, 110 );
c.add( jiamiJLabel );
jiemiJLabel = new JLabel();
jiemiJLabel.setText( "解 密:" );
jiemiJLabel.setBounds( 500, 370, 100, 110 );
c.add( jiemiJLabel );
jiamiResultJTextField = new JTextField();
jiamiResultJTextField.setBounds( 550, 216, 70, 20 );
jiamiResultJTextField.setHorizontalAlignment(
JTextField.RIGHT );
jiamiResultJTextField.setEditable( false );
c.add( jiamiResultJTextField );
jiemiResultJTextField = new JTextField();
jiemiResultJTextField.setBounds( 560, 417, 70, 20 );
jiemiResultJTextField.setHorizontalAlignment(
JTextField.RIGHT );
jiemiResultJTextField.setEditable( false );
c.add( jiemiResultJTextField );
calculateJButton = new JButton();
calculateJButton.setText( "加密" );
calculateJButton.setBounds( 540, 250, 90, 30 );
c.add( calculateJButton );
calculateJButton1 = new JButton();
calculateJButton1.setText( "解密" );
calculateJButton1.setBounds( 550, 450, 90, 30 );
c.add( calculateJButton1 );
calculateJButton1.addActionListener(
new ActionListener()
{
public void actionPerformed( ActionEvent event )
{
calculateJButtonActionPerformed1( event );
}
}
);
calculateJButton.addActionListener(
new ActionListener()
{
public void actionPerformed( ActionEvent event )
{
calculateJButtonActionPerformed( event );
}
}
);
setTitle( "加密解密程序" );
setSize( 700, 550);
setVisible( true );
}
//加密主程序;
private void calculateJButtonActionPerformed( ActionEvent event )
{
int yshu,jshu,n,n1=0,n2=0,n3=0,n4=0;
yshu = Integer.parseInt( yuanshuJTextField.getText() );
n=yshu;
for(int i=3;i>=0;i--)
{n=yshu/(int)Math.pow(10,i);
switch(i+1)
{case 4: n4=(n+7)%10;break;
case 3: n3=(n+7)%10;break;
case 2: n2=(n+7)%10;break;
case 1: n1=(n+7)%10;break;
}
jshu=n2*1000+n1*100+n4*10+n3;
jiamiResultJTextField.setText( String.valueOf( jshu ) );
}
}
private void calculateJButtonActionPerformed1( ActionEvent event )
{
int yshu;
int jshu;
int n,n1=0,n2=0,n3=0,n4=0;
yshu = Integer.parseInt( jiemishuJTextField.getText() );
n=yshu;
for(int i=3;i>=0;i--)
{n=yshu/(int)Math.pow(10,i);
switch(i+1)
{case 4: n4=(n+3)%10;break;
case 3: n3=(n+3)%10;break;
case 2: n2=(n+3)%10;break;
case 1: n1=(n+3)%10;break;
}
jshu=n2*1000+n1*100+n4*10+n3;
jiemiResultJTextField.setText( String.valueOf( jshu ) );
}
}
private void yuanshuJTextFieldKeyPressed( KeyEvent event )
{
jiamiResultJTextField.setText( "" );
}
public static void main( String[] args )
{
JiaMiJieMi application = new JiaMiJieMi();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -