Java JFrame视图

绝地灬酷狼 2022-04-13 11:49 279阅读 0赞

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

将此段代码放置在main中

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

下面是一些视图

  1. public class JavaMD5 extends JPanel {
  2. /**
  3. *
  4. */
  5. private static final long serialVersionUID = 1L;
  6. private JTextField textField;
  7. private static TextArea textArea;
  8. private static JComboBox comboBox;
  9. /**
  10. * Create the panel.
  11. */
  12. public JavaMD5() {
  13. setBackground(UIManager.getColor("CheckBox.light"));
  14. setLayout(null);
  15. JLabel lblMd = new JLabel("MD5\u52A0\u5BC6\u5DE5\u5177");
  16. lblMd.setForeground(new Color(0, 0, 0));
  17. lblMd.setFont(new Font("微软雅黑", Font.PLAIN, 14));
  18. lblMd.setBounds(191, 10, 131, 15);
  19. add(lblMd);
  20. JLabel label = new JLabel("\u8F93\u5165\u52A0\u5BC6\u6587\u672C:");
  21. label.setForeground(new Color(0, 0, 0));
  22. label.setFont(new Font("微软雅黑", Font.PLAIN, 12));
  23. label.setBounds(32, 48, 84, 32);
  24. add(label);
  25. textField = new JTextField();
  26. textField.setEditable(false);
  27. textField.setBounds(126, 276, 282, 26);
  28. add(textField);
  29. textField.setColumns(10);
  30. JButton button = new JButton("\u52A0\u5BC6");
  31. button.addActionListener(new ActionListener() {
  32. public void actionPerformed(ActionEvent arg0) {
  33. // 加密事件
  34. String original = textArea.getText();
  35. if ((original.trim()).length() > 0) {
  36. try {
  37. MessageDigest md5 = MessageDigest.getInstance("MD5");
  38. md5.update(original.getBytes("utf-8"));
  39. switch (comboBox.getSelectedIndex()) {
  40. case 0:
  41. textField.setText(new BigInteger(1, md5.digest()).toString(16));
  42. break;
  43. case 1:
  44. textField.setText(new BigInteger(1, md5.digest()).toString(16).toUpperCase());
  45. break;
  46. case 2:
  47. textField.setText(new BigInteger(1, md5.digest()).toString(16).substring(8, 24));
  48. break;
  49. case 3:
  50. textField.setText(
  51. new BigInteger(1, md5.digest()).toString(16).substring(8, 24).toUpperCase());
  52. break;
  53. }
  54. } catch (NoSuchAlgorithmException e) {
  55. e.printStackTrace();
  56. } catch (UnsupportedEncodingException e1) {
  57. e1.printStackTrace();
  58. }
  59. } else {
  60. JOptionPane.showMessageDialog(null, "未输入加密文本", "加密失败", JOptionPane.ERROR_MESSAGE);
  61. }
  62. }
  63. });
  64. button.setForeground(new Color(255, 255, 255));
  65. button.setBackground(new Color(199, 21, 133));
  66. button.setFont(new Font("微软雅黑", Font.PLAIN, 12));
  67. button.setBounds(126, 184, 282, 32);
  68. add(button);
  69. JLabel label_1 = new JLabel("\u8F93\u51FA\u5BC6\u6587:");
  70. label_1.setForeground(new Color(0, 0, 0));
  71. label_1.setFont(new Font("微软雅黑", Font.PLAIN, 12));
  72. label_1.setBounds(56, 272, 60, 32);
  73. add(label_1);
  74. textArea = new TextArea();
  75. textArea.setBounds(126, 48, 277, 87);
  76. add(textArea);
  77. JButton button_1 = new JButton("\u590D\u5236\u5BC6\u6587");
  78. button_1.addActionListener(new ActionListener() {
  79. public void actionPerformed(ActionEvent e) {
  80. if (textField.getText().length() > 1) {
  81. Toolkit.getDefaultToolkit().getSystemClipboard()
  82. .setContents(new StringSelection(textField.getText()), null);
  83. JOptionPane.showMessageDialog(null, "复制md5加密值成功", "复制成功",JOptionPane.PLAIN_MESSAGE);
  84. } else {
  85. JOptionPane.showMessageDialog(null, "加密值不正确", "失败", JOptionPane.ERROR_MESSAGE);
  86. }
  87. }
  88. });
  89. button_1.setForeground(new Color(255, 255, 255));
  90. button_1.setBackground(new Color(199, 21, 133));
  91. button_1.setFont(new Font("微软雅黑", Font.PLAIN, 12));
  92. button_1.setBounds(126, 234, 282, 32);
  93. add(button_1);
  94. comboBox = new JComboBox();
  95. comboBox.setForeground(new Color(0, 0, 0));
  96. comboBox.setBackground(new Color(255, 255, 255));
  97. comboBox.setFont(new Font("微软雅黑", Font.PLAIN, 12));
  98. comboBox.setBounds(126, 153, 83, 21);
  99. comboBox.addItem("\u5c0f\u5199\u0033\u0032\u4f4d");
  100. comboBox.addItem("\u5927\u5199\u0033\u0032\u4f4d");
  101. comboBox.addItem("\u5c0f\u5199\u0031\u0036\u4f4d");
  102. comboBox.addItem("\u5927\u5199\u0031\u0036\u4f4d");
  103. add(comboBox);
  104. JLabel label_2 = new JLabel("\u9009\u62E9\u52A0\u5BC6\u65B9\u5F0F:");
  105. label_2.setForeground(new Color(0, 0, 0));
  106. label_2.setFont(new Font("微软雅黑", Font.PLAIN, 12));
  107. label_2.setBounds(32, 156, 78, 15);
  108. add(label_2);
  109. JButton button_2 = new JButton("\u8054\u7CFB\u4F5C\u8005");
  110. button_2.addActionListener(new ActionListener() {
  111. public void actionPerformed(ActionEvent e) {
  112. try {
  113. Desktop.getDesktop().browse(new URI(
  114. "http://sighttp.qq.com/authd?IDKEY=ee99f3848d706a45f68f4c927769f26f33daa84775ff3d41"));
  115. } catch (URISyntaxException e1) {
  116. // TODO Auto-generated catch block
  117. e1.printStackTrace();
  118. } catch (IOException e1) {
  119. // TODO Auto-generated catch block
  120. e1.printStackTrace();
  121. }
  122. }
  123. });
  124. button_2.setForeground(new Color(255, 255, 255));
  125. button_2.setBackground(new Color(199, 21, 133));
  126. button_2.setFont(new Font("微软雅黑", Font.PLAIN, 12));
  127. button_2.setBounds(126, 312, 282, 32);
  128. add(button_2);
  129. 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");
  130. label_3.setForeground(Color.RED);
  131. label_3.setFont(new Font("微软雅黑", Font.PLAIN, 12));
  132. label_3.setBounds(99, 354, 327, 15);
  133. add(label_3);
  134. }
  135. }

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

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

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwODgxNjgw_size_16_color_FFFFFF_t_70

发表评论

表情:
评论列表 (有 0 条评论,279人围观)

还没有评论,来说两句吧...

相关阅读