package wz.cs.szu.edu;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
/**
*/
public class MainEntry extends JFrame implements Runnable {
/**
* The downsample width for the application.
*/
static final int DOWNSAMPLE_WIDTH = 5;
/**
* The down sample height for the application.
*/
static final int DOWNSAMPLE_HEIGHT = 7;
/**
* The entry component for the user to draw into.
*/
Entry entry;
/**
* The down sample component to display the drawing
* downsampled.
*/
Sample sample;
/**
* The letters that have been defined.
*/
DefaultListModel letterListModel = new DefaultListModel();
/**
* The neural network.
*/
KohonenNetwork net;
/**
* The background thread used for training.
*/
Thread trainThread = null;
/**
* The constructor.
*/
MainEntry()
{
setResizable(false);
getContentPane().setLayout(null);
entry = new Entry();
entry.reshape(168,25,200,128);
getContentPane().add(entry);
sample = new Sample(DOWNSAMPLE_WIDTH,DOWNSAMPLE_HEIGHT);
sample.reshape(217,210,130,140);
entry.setSample(sample);
getContentPane().add(sample);
//{{INIT_CONTROLS
setTitle("Java SOM Neural Network");
getContentPane().setLayout(null);
setSize(453,443);
setVisible(false);
JLabel1.setText("\u5DF2\u8BC6\u522B\u7684\u5B57\u7B26");
getContentPane().add(JLabel1);
JLabel1.setBounds(12,12,84,12);
JLabel2.setText("Tries:");
getContentPane().add(JLabel2);
JLabel2.setBounds(12,264,72,24);
add.setText("\u6DFB\u52A0");
add.setActionCommand("Add");
getContentPane().add(add);
add.setBounds(168,156,84,24);
clear.setText("\u6E05\u9664");
clear.setActionCommand("Clear");
getContentPane().add(clear);
clear.setBounds(168,180,84,24);
recognize.setText("\u8BC6\u522B");
recognize.setActionCommand("Recognize");
getContentPane().add(recognize);
recognize.setBounds(252,156,120,24);
JScrollPane1.setVerticalScrollBarPolicy(
javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
JScrollPane1.setOpaque(true);
getContentPane().add(JScrollPane1);
JScrollPane1.setBounds(12,24,144,132);
JScrollPane1.getViewport().add(letters);
letters.setBounds(0,0,126,129);
del.setText("\u5220\u9664");
del.setActionCommand("Delete");
getContentPane().add(del);
del.setBounds(12,156,144,24);
load.setText("\u5BFC\u5165");
load.setActionCommand("Load");
getContentPane().add(load);
load.setBounds(12,180,72,24);
save.setText("\u4FDD\u5B58");
save.setActionCommand("Save");
getContentPane().add(save);
save.setBounds(84,180,72,24);
train.setText("\u5F00\u59CB\u8BAD\u7EC3");
train.setActionCommand("开始训练");
getContentPane().add(train);
train.setBounds(12,204,144,24);
JLabel3.setText("Last Error:");
getContentPane().add(JLabel3);
JLabel3.setBounds(12,288,72,24);
JLabel4.setText("Best Error:");
getContentPane().add(JLabel4);
JLabel4.setBounds(12,312,72,24);
tries.setText("0");
getContentPane().add(tries);
tries.setBounds(96,264,72,24);
lastError.setText("0");
getContentPane().add(lastError);
lastError.setBounds(96,288,72,24);
bestError.setText("0");
getContentPane().add(bestError);
bestError.setBounds(96,312,72,24);
JLabel8.setHorizontalTextPosition(
javax.swing.SwingConstants.CENTER);
JLabel8.setHorizontalAlignment(
javax.swing.SwingConstants.CENTER);
JLabel8.setText("Training Results");
getContentPane().add(JLabel8);
JLabel8.setFont(new Font("Dialog", Font.BOLD, 14));
JLabel8.setBounds(12,240,120,24);
JLabel5.setText("\u624B\u5199\u5B57\u6BCD\u533A");
getContentPane().add(JLabel5);
JLabel5.setBounds(204,12,144,12);
//}}
//{{REGISTER_LISTENERS
SymAction lSymAction = new SymAction();
clear.addActionListener(lSymAction);
add.addActionListener(lSymAction);
del.addActionListener(lSymAction);
SymListSelection lSymListSelection = new SymListSelection();
letters.addListSelectionListener(lSymListSelection);
load.addActionListener(lSymAction);
save.addActionListener(lSymAction);
train.addActionListener(lSymAction);
recognize.addActionListener(lSymAction);
//}}
letters.setModel(letterListModel);
//{{INIT_MENUS
//}}
}
/**
* The main method.
*
* @param args Args not really used.
*/
public static void main(String args[])
{
MainEntry mEntry=new MainEntry();
mEntry.setLocationRelativeTo(mEntry);//display in the center
mEntry.show();
}
//{{DECLARE_CONTROLS
javax.swing.JLabel JLabel1 = new javax.swing.JLabel();
javax.swing.JLabel JLabel2 = new javax.swing.JLabel();
/**
* The add button.
*/
javax.swing.JButton add = new javax.swing.JButton();
/**
* The clear button
*/
javax.swing.JButton clear = new javax.swing.JButton();
/**
* The recognize button
*/
javax.swing.JButton recognize = new javax.swing.JButton();
javax.swing.JScrollPane JScrollPane1 = new javax.swing.JScrollPane();
/**
* The letters list box
*/
javax.swing.JList letters = new javax.swing.JList();
/**
* The delete button
*/
javax.swing.JButton del = new javax.swing.JButton();
/**
* The load button
*/
javax.swing.JButton load = new javax.swing.JButton();
/**
* The save button
*/
javax.swing.JButton save = new javax.swing.JButton();
/**
* The train button
*/
javax.swing.JButton train = new javax.swing.JButton();
javax.swing.JLabel JLabel3 = new javax.swing.JLabel();
javax.swing.JLabel JLabel4 = new javax.swing.JLabel();
/**
* How many tries
*/
javax.swing.JLabel tries = new javax.swing.JLabel();
/**
* The last error
*/
javax.swing.JLabel lastError = new javax.swing.JLabel();
/**
* The best error
*/
javax.swing.JLabel bestError = new javax.swing.JLabel();
javax.swing.JLabel JLabel8 = new javax.swing.JLabel();
javax.swing.JLabel JLabel5 = new javax.swing.JLabel();
class SymAction implements java.awt.event.ActionListener {
public void actionPerformed(java.awt.event.ActionEvent event)
{
Object object = event.getSource();
if ( object == clear )
clear_actionPerformed(event);
else if ( object == add )
add_actionPerformed(event);
else if ( object == del )
del_actionPerformed(event);
else if ( object == load )
load_actionPerformed(event);
else if ( object == save )
save_actionPerformed(event);
else if ( object == train )
train_actionPerformed(event);
else if ( object == recognize )
recognize_actionPerformed(event);
}
}
/**
* Called to clear the image.
*
* @param event The event
*/
void clear_actionPerformed(java.awt.event.ActionEvent event)
{
entry.clear();
sample.getData().clear();
sample.repaint();
}
/**
* Called to add the current image to the training set
*
* @param event The event
*/
void add_actionPerformed(java.awt.event.ActionEvent event)
{
int i;
String letter = JOptionPane.showInputDialog(
"Please enter a letter you would like to assign this sample to.");
if ( letter==null )
return;
if ( letter.length()>1 ) {
JOptionPane.showMessageDialog(this,
"Please enter only a single letter.","Error",
JOptionPane.ERROR_MESSAGE);
return;
}
entry.downSample();//采集样本
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Gesture-recognition-using-SOM_Java.rar (23个子文件)
SOM_OCR
bin
sl
cs
szu
edu
MainEntry.class 12KB
MainEntry$UpdateStats.class 1KB
Entry.class 4KB
SampleData.class 2KB
sample.dat 1KB
MainEntry$SymAction.class 1KB
Network.class 2KB
TrainingSet.class 3KB
MainEntry$SymListSelection.class 944B
Sample.class 1KB
KohonenNetwork.class 6KB
hs_err_pid7924.log 5KB
hs_err_pid2992.log 11KB
src
wz
cs
szu
edu
Entry.java 8KB
Network.java 4KB
sample.dat 1KB
Sample.java 2KB
SampleData.java 3KB
TrainingSet.java 6KB
KohonenNetwork.java 13KB
MainEntry.java 17KB
.project 383B
.classpath 232B
共 23 条
- 1
资源评论
我虽横行却不霸道
- 粉丝: 72
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功