package com; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Cursor; import java.awt.Font; import java.awt.SystemColor; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.File; import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingConstants; import javax.swing.border.EmptyBorder; import javax.swing.filechooser.FileNameExtensionFilter; /** * 二维码生成器 * @author cyw * */ @SuppressWarnings("serial") public class Mainframe extends JFrame { private JPanel contentPane, panel; private static JFileChooser filechooser = new JFileChooser(); private JTextField textField; private JButton button,button_1,btnlogo; private JLabel label; private String impath,filename; private JButton btnlogo_1; public Mainframe() { // TODO Auto-generated constructor stub setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize( 360, 347); setResizable(false); setTitle("二维码"); setLocationRelativeTo(null); init(); setVisible(true); } private void init() { // TODO Auto-generated method stub contentPane = new JPanel(); contentPane.setBackground(new Color(51, 153, 255)); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); textField = new JTextField(); textField.setBounds(14, 10, 140, 25); contentPane.add(textField); textField.setColumns(10); textField.addKeyListener(new key()); button = new JButton("\u786E\u5B9A"); button.setBounds(160, 11, 64, 23); contentPane.add(button); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub String text = textField.getText().trim(); if(text.equals("")){ JOptionPane.showMessageDialog(null, "请输入内容","提示",JOptionPane.ERROR_MESSAGE); textField.requestFocus(); } else{ if(impath == null || impath.equals("")) try { QRCodeUtil.encode(text, panel); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } else { try { QRCodeUtil.encode1(text, impath, true, panel); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } }); panel = new JPanel(); panel.setBackground(Color.WHITE); panel.setBounds(80, 45, 200, 200); contentPane.add(panel); panel.setLayout(new BorderLayout(0, 0)); label = new JLabel("\u4E8C\u7EF4\u7801\u533A\u57DF"); label.setForeground(SystemColor.textHighlight); label.setHorizontalAlignment(SwingConstants.CENTER); label.setFont(new Font("华文楷体", Font.BOLD, 34)); panel.add(label, BorderLayout.CENTER); JLabel lblCopyright = new JLabel("Copyright \u00A9 2016 cyw"); lblCopyright.setHorizontalAlignment(SwingConstants.CENTER); lblCopyright.setFont(new Font("宋体", Font.PLAIN, 16)); lblCopyright.setForeground(Color.BLACK); lblCopyright.setBounds(10, 294, 353, 25); contentPane.add(lblCopyright); button_1 = new JButton("保存二维码"); button_1.setForeground(Color.YELLOW); button_1.setFont(new Font("宋体", Font.BOLD, 16)); button_1.setBounds(96, 274, 173, 23); button_1.setContentAreaFilled(false); button_1.setBorder(null); button_1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub QRCodeUtil.Save(); textField.requestFocus(); } }); button_1.addMouseListener(new mouse()); contentPane.add(button_1); btnlogo = new JButton("\u63D2\u5165LOGO"); btnlogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub filechooser.setFileFilter(new FileNameExtensionFilter("jpg/png", new String[] { "jpg","png"})); filechooser.setCurrentDirectory(new File("D:\\")); filechooser.setDialogTitle("放入LOGO"); int i = filechooser.showOpenDialog(null); if(i == 0){ impath = filechooser.getSelectedFile()+""; filename = filechooser.getSelectedFile().getName(); btnlogo_1.setText("LOGO:"+ filename); if(textField.getText().trim() != null && !(textField.getText().trim().equals(""))) button.doClick(); textField.requestFocus(); } } }); btnlogo.setBounds(234, 11, 110, 23); contentPane.add(btnlogo); btnlogo_1 = new JButton("LOGO:null"); btnlogo_1.setForeground(Color.GREEN); btnlogo_1.setFont(new Font("宋体", Font.BOLD, 16)); btnlogo_1.setContentAreaFilled(false); btnlogo_1.setBorder(null); btnlogo_1.setBounds(0, 245, 363, 23); btnlogo_1.addMouseListener(new mouse()); btnlogo_1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(btnlogo_1.getText().equals("删除LOGO")){ if(filename != null && !filename.equals("")){ JOptionPane.showMessageDialog(null, "<html><font color=red>删除成功!</font></html>","提醒",JOptionPane.PLAIN_MESSAGE); impath = null; filename = null; if(textField.getText().trim() != null && !(textField.getText().trim().equals(""))){ button.doClick(); } textField.requestFocus(); } } } }); contentPane.add(btnlogo_1); //鼠标变手指装 button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); button_1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnlogo.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnlogo_1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } public static void main(String[] args) { new Mainframe(); } class key extends KeyAdapter { @Override public void keyTyped(KeyEvent e) { // TODO Auto-generated method stub int key = e.getKeyChar(); if (key == KeyEvent.VK_ENTER) button.doClick(); } } class mouse extends MouseAdapter{ @Override public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub if(e.getSource() == button_1) button_1.setForeground(new Color(204, 0, 255)); if(e.getSource() == btnlogo_1){ btnlogo_1.setForeground(new Color(204, 0, 255)); btnlogo_1.setText("删除LOGO"); } } @Override public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub if(e.getSource() == button_1) button_1.setForeground(Color.YELLOW); if(e.getSource() == btnlogo_1){ btnlogo_1.setForeground(Color.GREEN); btnlogo_1.setText("LOGO:"+filename); } } } }

luo110012 LV9
2023年5月17日
尹恒yingying LV18
2021年10月31日
sdasdsad LV1
2021年9月26日
sky_hui LV6
2021年8月13日
wyx065747 LV67
2021年7月9日
13043860zj LV16
2021年6月21日
yiangeee LV9
2021年1月14日
jweblogic LV1
2020年10月29日
498215790 LV1
2020年6月3日
IraqiHa LV6
2020年5月1日

GANBINWEI
1月10日
暂无贡献等级
daunjianhui LV1
2024年12月3日
微信网友_6625333836959744
2023年8月28日
暂无贡献等级
luo110012 LV9
2023年5月17日
啦啦啦7719 LV15
2023年5月15日
haoyifan
2023年3月23日
暂无贡献等级
微信网友_6370360544677888
2023年3月1日
暂无贡献等级
微信网友_5992582549164032 LV6
2023年2月16日
mthouse
2022年11月25日
暂无贡献等级
flygrass LV12
2022年9月16日