基于JAVA SE的舌像半自动提取系统界面搭建
package StudyTEST; import java.io.*; import javax.swing.*; import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class Tongue_Extract { /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { Tongue_Extract window = new Tongue_Extract(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the application. */ public Tongue_Extract (){ initialize(); } /** * Initialize the contents of the frame. */ private void initialize() { frame = new JFrame(); frame.setBounds(650,160,680,740); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(null); JPanel panel = new JPanel(); panel.setBounds(10, 10, 635, 138); frame.getContentPane().add(panel); JLabel lblNewLabel = new JLabel(""); lblNewLabel.setIcon(new ImageIcon("C:\\Users\\201801033013\\eclipse-workspace\\EducationPractice\\src\\JT}@X6)4_2T}X}5ZG_Q@UAP.png")); panel.add(lblNewLabel); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(32, 204, 598, 420); frame.getContentPane().add(scrollPane); JPanel panel_1 = new JPanel(); panel_1.setBackground(Color.GRAY); panel_1.setForeground(Color.GRAY); scrollPane.setViewportView(panel_1); JLabel lblNewLabel_1 = new JLabel("\u820C\u50CFPNG:"); lblNewLabel_1.setBounds(22, 169, 61, 25); frame.getContentPane().add(lblNewLabel_1); textField = new JTextField(); textField.setBounds(104, 171, 330, 21); frame.getContentPane().add(textField); textField.setColumns(10); //6个按钮 JButton btnNewButton = new JButton("\u52A0\u8F7D"); btnNewButton.setBounds(511, 170, 93, 23); frame.getContentPane().add(btnNewButton); JButton btnNewButton_1 = new JButton("\u6E05\u695A\u6700\u540E\u7ED3\u70B9"); btnNewButton_1.setEnabled(false); btnNewButton_1.setBounds(119, 645, 120, 23); frame.getContentPane().add(btnNewButton_1); JButton btnNewButton_2 = new JButton("\u5168\u90E8\u6E05\u9664"); btnNewButton_2.setEnabled(false); btnNewButton_2.setBounds(249, 645, 93, 23); frame.getContentPane().add(btnNewButton_2); JButton btnNewButton_3 = new JButton("\u63D0\u53D6\u820C\u50CF"); btnNewButton_3.setEnabled(false); btnNewButton_3.setBounds(368, 645, 93, 23); frame.getContentPane().add(btnNewButton_3); JButton btnNewButton_4 = new JButton("\u7ED3\u675F"); btnNewButton_4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); btnNewButton_4.setBounds(523, 645, 93, 23); frame.getContentPane().add(btnNewButton_4); JCheckBox chckbxNewCheckBox = new JCheckBox("\u51C6\u5907\u63D0\u53D6"); chckbxNewCheckBox.setEnabled(false); chckbxNewCheckBox.setBounds(10, 645, 103, 23); frame.getContentPane().add(chckbxNewCheckBox); label = new JLabel(); panel_1.add(label); chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub int result = chooser.showOpenDialog(null); if(result == JFileChooser.APPROVE_OPTION) { String fileName = chooser.getCurrentDirectory()+"\\"+chooser.getSelectedFile().getName(); textField.setText(fileName); String name = chooser.getSelectedFile().getPath(); label.setIcon(new ImageIcon(name)); } counter++; chckbxNewCheckBox.setEnabled(true); } }); //准备提取 chckbxNewCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if(counter != 0) { if(k%2==0) { btnNewButton_1.setEnabled(true); btnNewButton_2.setEnabled(true); btnNewButton_3.setEnabled(true); } else { btnNewButton_1.setEnabled(false); btnNewButton_2.setEnabled(false); btnNewButton_3.setEnabled(false); } k++; } } }); //结束监听器 btnNewButton_4.addActionListener(new ActionListener() {@ Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub System.exit(0); } }); } private JFrame frame; private JTextField textField; private JLabel label; private JFileChooser chooser; public static int k = 0; public static int counter = 0; }程序运行结果如下: