java多线程    Java入门    vsftp    ftp    linux配置    centos    FRP教程    HBase    Html5缓存    webp    zabbix    分布式    neo4j图数据库    

java awt 例子

这段程序本来是一个图片分切程序外壳,图片分切程序为特定场合使用的小程序,对大家没什么用,特发布awt界面部分,希望对需要的朋友有所帮助

package com.buzz.img;

 

import java.awt.Component;

import java.awt.Container;

import java.awt.FlowLayout;

import java.awt.GridLayout;

import java.awt.Rectangle;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import java.io.File;

 

import javax.swing.JButton;

import javax.swing.JFileChooser;

import javax.swing.JFrame;

import javax.swing.JOptionPane;

import javax.swing.JTextField;

import javax.swing.SwingConstants;

 

public class ImageFace extends JFrame {

JButton b;

JButton bDO;// 处理按钮

JTextField tf;

 

public ImageFace() {

// -------------------- 关闭监听----------

addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

// int a = JOptionPane.showConfirmDialog(null, "确定关闭吗?", "温馨提示",

// JOptionPane.YES_NO_OPTION);

// if (a == 0) {

System.exit(0); // 关闭

// }

}

});

 

// --------------------

// setSize(100, 100);

// setVisible(true);

}

 

// 制造选择文件夹

public void SelectOne() {

String dir = ""; // 缺省路径

Component parent = null; // Dialog上级组件

JFileChooser chooser = new JFileChooser(dir);

javax.swing.filechooser.FileFilter dirFilter = new javax.swing.filechooser.FileFilter() {

public boolean accept(File f) {

return f.isDirectory();

}

 

public String getDescription() {

return "";

}

};

chooser.setFileFilter(dirFilter);

chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

if (chooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {

dir = chooser.getSelectedFile().getAbsolutePath();

// System.out.println(dir);

tf.setText(dir);

}

}

 

// 具体事务

public void SwingTest() {

 

this.setTitle("图片批量处理工具");

Container c = getContentPane();

c.setLayout(null);

 

b = new JButton(" 选择 ");

b.setBounds(new Rectangle(0, 0, 500, 42));

c.add(b);

 

bDO = new JButton(" 生成缩小图 ");

this.add(bDO);

 

tf = new JTextField(20);

this.add(tf);

 

this.setLayout(new FlowLayout());

this.setBounds(200, 200, 300, 100);

this.setVisible(true);

 

b.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

SelectOne();

}

});

 

bDO.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

 

if (tf.getText().equals("")) {

tf.setText("请选择文件夹");

}

 

try {

tf.setText(ImgQie.suo(tf.getText())); // 一段后台工作程序。你可以替换任意自己写的程序

} catch (Exception ex) {

tf.setText("ERROR:" + ex.getMessage());

}

}

});

 

// b.addActionListener(new ActionListener() {

// public void actionPerformed(ActionEvent e) {

// String s = JOptionPane.showInputDialog("请输入:", "1");

// tf.setText(s);

// }

// });

 

}

 

public static void main(String[] args) {

ImageFace st = new ImageFace();

st.SwingTest();

}

 

}


This entry was posted in JAVA and tagged . Bookmark the permalink.
月小升QQ 2651044202, 技术交流QQ群 178491360
首发地址:月小升博客https://java-er.com/blog/java-awt/
无特殊说明,文章均为月小升原创,欢迎转载,转载请注明本文地址,谢谢
您的评论是我写作的动力.

Leave a Reply