Java JFrame视图

这是我用java+可视化工具(Eclipse)写的,具体底层不再解释,代码直接演示使用方法

 

将此段代码放置在main中

JFrame jframe = new JFrame("MD5加密工具");//里面是名字
jframe.getContentPane().add(new JavaMD5());//添加视图
jframe.setSize(460, 450);// 窗口大小
jframe.setResizable(false);//设置为不可调整大小
jframe.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);//设置关闭方式
jframe.setVisible(true);//设置为显示

 

下面是一些视图

public class JavaMD5 extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JTextField textField;
	private static TextArea textArea;
	private static JComboBox comboBox;

	/**
	 * Create the panel.
	 */
	public JavaMD5() {
		setBackground(UIManager.getColor("CheckBox.light"));
		setLayout(null);

		JLabel lblMd = new JLabel("MD5\u52A0\u5BC6\u5DE5\u5177");
		lblMd.setForeground(new Color(0, 0, 0));
		lblMd.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		lblMd.setBounds(191, 10, 131, 15);
		add(lblMd);

		JLabel label = new JLabel("\u8F93\u5165\u52A0\u5BC6\u6587\u672C:");
		label.setForeground(new Color(0, 0, 0));
		label.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		label.setBounds(32, 48, 84, 32);
		add(label);

		textField = new JTextField();
		textField.setEditable(false);
		textField.setBounds(126, 276, 282, 26);
		add(textField);
		textField.setColumns(10);

		JButton button = new JButton("\u52A0\u5BC6");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				// 加密事件
				String original = textArea.getText();

				if ((original.trim()).length() > 0) {
					try {
						MessageDigest md5 = MessageDigest.getInstance("MD5");
						md5.update(original.getBytes("utf-8"));

						switch (comboBox.getSelectedIndex()) {
						case 0:
							textField.setText(new BigInteger(1, md5.digest()).toString(16));
							break;
						case 1:
							textField.setText(new BigInteger(1, md5.digest()).toString(16).toUpperCase());
							break;
						case 2:
							textField.setText(new BigInteger(1, md5.digest()).toString(16).substring(8, 24));
							break;
						case 3:
							textField.setText(
									new BigInteger(1, md5.digest()).toString(16).substring(8, 24).toUpperCase());
							break;
						}

					} catch (NoSuchAlgorithmException e) {
						e.printStackTrace();
					} catch (UnsupportedEncodingException e1) {
						e1.printStackTrace();
					}
				} else {
					JOptionPane.showMessageDialog(null, "未输入加密文本", "加密失败", JOptionPane.ERROR_MESSAGE);
				}

			}
		});
		button.setForeground(new Color(255, 255, 255));
		button.setBackground(new Color(199, 21, 133));
		button.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		button.setBounds(126, 184, 282, 32);
		add(button);

		JLabel label_1 = new JLabel("\u8F93\u51FA\u5BC6\u6587:");
		label_1.setForeground(new Color(0, 0, 0));
		label_1.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		label_1.setBounds(56, 272, 60, 32);
		add(label_1);

		textArea = new TextArea();
		textArea.setBounds(126, 48, 277, 87);
		add(textArea);

		JButton button_1 = new JButton("\u590D\u5236\u5BC6\u6587");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				

				if (textField.getText().length() > 1) {
					Toolkit.getDefaultToolkit().getSystemClipboard()
							.setContents(new StringSelection(textField.getText()), null);
					JOptionPane.showMessageDialog(null, "复制md5加密值成功", "复制成功",JOptionPane.PLAIN_MESSAGE);
				} else {
					JOptionPane.showMessageDialog(null, "加密值不正确", "失败", JOptionPane.ERROR_MESSAGE);
				}

			}
		});
		button_1.setForeground(new Color(255, 255, 255));
		button_1.setBackground(new Color(199, 21, 133));
		button_1.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		button_1.setBounds(126, 234, 282, 32);
		add(button_1);

		comboBox = new JComboBox();
		comboBox.setForeground(new Color(0, 0, 0));
		comboBox.setBackground(new Color(255, 255, 255));
		comboBox.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		comboBox.setBounds(126, 153, 83, 21);
		comboBox.addItem("\u5c0f\u5199\u0033\u0032\u4f4d");
		comboBox.addItem("\u5927\u5199\u0033\u0032\u4f4d");
		comboBox.addItem("\u5c0f\u5199\u0031\u0036\u4f4d");
		comboBox.addItem("\u5927\u5199\u0031\u0036\u4f4d");
		add(comboBox);

		JLabel label_2 = new JLabel("\u9009\u62E9\u52A0\u5BC6\u65B9\u5F0F:");
		label_2.setForeground(new Color(0, 0, 0));
		label_2.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		label_2.setBounds(32, 156, 78, 15);
		add(label_2);

		JButton button_2 = new JButton("\u8054\u7CFB\u4F5C\u8005");
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					Desktop.getDesktop().browse(new URI(
							"http://sighttp.qq.com/authd?IDKEY=ee99f3848d706a45f68f4c927769f26f33daa84775ff3d41"));
				} catch (URISyntaxException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		button_2.setForeground(new Color(255, 255, 255));
		button_2.setBackground(new Color(199, 21, 133));
		button_2.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		button_2.setBounds(126, 312, 282, 32);
		add(button_2);
		
		JLabel label_3 = new JLabel("\u6700\u597D\u4E0D\u8981\u8F93\u5165\u7279\u6B8A\u5B57\u7B26\uFF0C\u53EF\u80FD\u4F1A\u5BFC\u81F4\u52A0\u5BC6\u7ED3\u679C\u9519\u8BEF\uFF0C\u5982\u201C#\u201D");
		label_3.setForeground(Color.RED);
		label_3.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		label_3.setBounds(99, 354, 327, 15);
		add(label_3);

	}
}

 

之后进行导出,双击jar包即可运行,呐,直接可以看到》》》导出jar教程

下载此jar(免费)======》 点击下载

Java JFrame视图_第1张图片

 

 

你可能感兴趣的:(使用教程)