基于JAVA SE的舌像提取系统完整代码

it2026-03-05  2

舌像提取主代码

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); 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(104, 645, 131, 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(355, 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(552, 645, 81, 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); JButton btnNewButton_5 = new JButton("\u4FDD\u5B58"); btnNewButton_5.setBounds(457, 645, 81, 23); frame.getContentPane().add(btnNewButton_5); 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)); myPanel=new MyPanel(name); //scrollPane=new JScrollPane(myPanel); //scrollPane.setBounds(32, 204, 598, 420); //frame.getContentPane().add(scrollPane); scrollPane.setViewportView(myPanel); myPanel.setBackground(Color.GRAY); scrollPane.setBackground(Color.GRAY); myPanel.repaint(); scrollPane.repaint(); } 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; MyPanel myPanel; JScrollPane scrollPane; }

MyFrame类

package StudyTEST; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; public class MyFrame extends JFrame{ private JPanel contentPane; public MyFrame() { setBg(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 500, 710); init(); } public static void main(String[] args) { new MyFrame(); } public void init() { contentPane = new JPanel(); contentPane.setOpaque(false); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); this.setVisible(true); } public void setBg(){ ((JPanel)this.getContentPane()).setOpaque(false); ImageIcon img = new ImageIcon ("C:\\Users\\201801033013\\Desktop\\舌像提取\\e0fe9a3db859fe950c698a7a236b68c.png"); JLabel background = new JLabel(img); this.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE)); background.setBounds(0, 0, img.getIconWidth(), img.getIconHeight()); } }

MyPanel类

package StudyTEST; import java.awt.Dimension; import java.awt.Graphics; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.ImageIcon; import javax.swing.JPanel; import javax.swing.JTextField; public class MyPanel extends JPanel { public String strFileName; //构造函数 public MyPanel(String strFileName) { this.strFileName=strFileName; } //对象数组 int counter = 1; public MyDot mydotArray[] = new MyDot[100]; protected void paintComponent(Graphics g) { ImageIcon image=new ImageIcon(strFileName); this.setPreferredSize(new Dimension(image.getIconWidth(),image.getIconHeight())); g.drawImage(image.getImage() , 0, 0, image.getIconWidth(), image.getIconHeight(), this); //实现在图片面板中绘图,并增加鼠标监听器 this.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { counter++; JPanel p = (JPanel) e.getSource(); Graphics g = p.getGraphics(); g.drawRect(e.getX(), e.getY(), 10, 10); //只要一点击就将参数传递给MyDot MyDot mydot = new MyDot(e.getX(), e.getY()); //dotname = ""+mydot.x+" "+mydot.y; for(int i=0; i<100; i++) { mydotArray[i] = mydot; } } }); } }

##MyDot类

package StudyTEST; public class MyDot { public double x; public double y; public MyDot(double x, double y) { this.x = x; this.y = y; } }

程序执行结果如下:

最新回复(0)