文件分隔符
This commit is contained in:
parent
215c8cf03f
commit
066827381e
@ -58,8 +58,8 @@ import javax.swing.JPanel;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
//设置编码格式 Encoder.java static final String DEFAULT_BYTE_MODE_ENCODING ="UTF-8"
|
||||
//设置图片大小本文件中
|
||||
//设置编码格式 Encoder.java static final String DEFAULT_BYTE_MODE_ENCODING ="UTF-8"
|
||||
//设置图片大小本文件中
|
||||
public final class GUIRunner extends JFrame implements ActionListener {
|
||||
|
||||
private final JLabel imageLabel;
|
||||
@ -75,17 +75,17 @@ public final class GUIRunner extends JFrame implements ActionListener {
|
||||
textArea.setEditable(false);
|
||||
// textArea.setLineWrap(true);
|
||||
// textArea.setMaximumSize(new Dimension(400, 200));
|
||||
label2=new JLabel("请输入要编码信息:");
|
||||
label2=new JLabel("请输入要编码信息:");
|
||||
textArea2 =new TextArea();
|
||||
// Button
|
||||
sel_button = new JButton("选择图片");
|
||||
sel_button = new JButton("选择图片");
|
||||
sel_button.addActionListener(this);
|
||||
generate_button=new JButton("生成二维码");
|
||||
generate_button=new JButton("生成二维码");
|
||||
generate_button.addActionListener(this);
|
||||
Container panel = new JPanel(new GridLayout(2,1));
|
||||
//panel.setLayout(new FlowLayout());//new GridLayout(2,1)
|
||||
panel.add(imageLabel);//一行一列
|
||||
JPanel panel2=new JPanel(new GridLayout(4,1));//2行一列
|
||||
panel.add(imageLabel);//一行一列
|
||||
JPanel panel2=new JPanel(new GridLayout(4,1));//2行一列
|
||||
panel2.add(textArea);
|
||||
panel2.add(label2);
|
||||
panel2.add(textArea2);
|
||||
@ -94,7 +94,7 @@ public final class GUIRunner extends JFrame implements ActionListener {
|
||||
panel3.add(generate_button);
|
||||
panel2.add(panel3);
|
||||
panel.add(panel2);
|
||||
setTitle("二维码编码解码程序_Powered by Zxing (C)xuenhua");
|
||||
setTitle("二维码编码解码程序_Powered by Zxing (C)xuenhua");
|
||||
setSize(420, 420);
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
setContentPane(panel);
|
||||
@ -112,7 +112,7 @@ public final class GUIRunner extends JFrame implements ActionListener {
|
||||
fileChooser.showOpenDialog(this);
|
||||
File file = fileChooser.getSelectedFile();
|
||||
Icon imageIcon = new ImageIcon(file.toURI().toURL());
|
||||
if(imageIcon.getIconWidth()>200){//转换尺寸
|
||||
if(imageIcon.getIconWidth()>200){//转换尺寸
|
||||
Image image=null;
|
||||
try {
|
||||
image = ImageIO.read(file);
|
||||
@ -155,10 +155,10 @@ public final class GUIRunner extends JFrame implements ActionListener {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
if(e.getActionCommand()=="选择图片"){
|
||||
if(e.getActionCommand()=="选择图片"){
|
||||
chooseImage();
|
||||
}
|
||||
if(e.getActionCommand()=="生成二维码"){
|
||||
if(e.getActionCommand()=="生成二维码"){
|
||||
BitMatrix bitMatrix;
|
||||
String str=textArea2.getText();
|
||||
String user_dir=System.getProperty("user.dir");
|
||||
@ -167,16 +167,16 @@ public final class GUIRunner extends JFrame implements ActionListener {
|
||||
String timestamp=sfd.format(new Date());
|
||||
|
||||
|
||||
String path=user_dir+"\\qr-"+timestamp+ ".png";
|
||||
String path=user_dir+File.separator+"qr-"+timestamp+ ".png";
|
||||
try {
|
||||
bitMatrix = new MultiFormatWriter().encode
|
||||
(str, BarcodeFormat.QR_CODE, 200, 200);//图片大小
|
||||
(str, BarcodeFormat.QR_CODE, 200, 200);//图片大小
|
||||
File file = new File(path);
|
||||
if(!file.exists()) {
|
||||
file.createNewFile();
|
||||
}
|
||||
MatrixToImageWriter.writeToFile(bitMatrix, "png", file);
|
||||
textArea.setText("二维码生成成功\n"+path);
|
||||
textArea.setText("二维码生成成功\n"+path);
|
||||
} catch (IOException eIO) {
|
||||
eIO.printStackTrace();
|
||||
} catch (WriterException e1) {
|
||||
|
Loading…
Reference in New Issue
Block a user