import java.applet.Applet; import java.awt.*; import java.awt.event.*; import javax.swing.*; /* */ public class ExeInput extends Applet implements MouseListener ,MouseMotionListener ,ActionListener { private int width = 300; private int height = 300; private Point before; private boolean checkPressed = false; private ArrayImage img; Mametan mame = null; private Label edgeL; private Label answL; private List sujL; private Button gakB; private Button ansB; private Button creB; private Database base; public void init() { img =new ArrayImage( createImage(280,280),280,280); addMouseListener(this); addMouseMotionListener(this); before = null; // setLayout(null); edgeL = new Label("端の数:"); answL = new Label("僕は思う:"); edgeL.setLocation(0,0); // answL.setDimention(10,100); answL.setLocation(0,0); add(edgeL); add(answL); sujL = new List(); sujL.add("0"); sujL.add("1"); sujL.add("2"); sujL.add("3"); sujL.add("4"); sujL.add("5"); sujL.add("6"); sujL.add("7"); sujL.add("8"); sujL.add("9"); gakB = new Button("学習"); ansB = new Button("答える"); creB = new Button("画面をクリアする"); gakB.addActionListener(this); ansB.addActionListener(this); creB.addActionListener(this); add(ansB); add(creB); add(gakB); add(sujL); base = new Database(); } public void mouseDragged(MouseEvent e) { int x= 0; int y = 0; int xx = 0; int yy = 0; int width=280; int height=280; if(checkPressed == true && before != null) { if(e.getX()<280 && e.getY()<280 && e.getX()>0 && e.getY() >0) { img.drawLine((int)before.getX(),(int)before.getY(),e.getX(),e.getY()); img.baseXY(e.getX(),e.getY(),true); img.imageXY(e.getX(),e.getY()); x = (int)before.getX(); y = (int)before.getY(); xx = (int)e.getX(); yy = (int)e.getX(); before = e.getPoint(); if(x >xx){int temp = x;x =xx; xx= temp;} if(y >yy){int temp = y;y =yy; yy= temp;} repaint(x-5,y-5,xx-x+10,yy-y+10); } } } public void mouseMoved(MouseEvent e) { } public void update(Graphics g) { paint(g); } public void paint(Graphics g) { g.drawImage(img.createImage(),0,0,this); if(mame ==null){return;} for(int i= 0;null != mame.getRoot(i+1);i++) { // System.out.println("sdf"); g.setColor(new Color(100,10,200)); g.drawLine( (int)mame.getRoot(i).getX(), (int)mame.getRoot(i).getY(), (int)mame.getRoot(i+1).getX(), (int)mame.getRoot(i+1).getY()); } } public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mousePressed(MouseEvent e){checkPressed = true; before = e.getPoint();} public void mouseReleased(MouseEvent e) { checkPressed = false;before = null; Pattern pat = new Pattern(img.getArray(),img.Width(),img.Height()); int a = pat.searchEdge(); edgeL.setText("端の数:"+a); mame = new Mametan(img,pat.putEdge()); mame.startDeconvolution(); repaint(); } public void actionPerformed(ActionEvent e) { System.out.println(e.getActionCommand()); if(e.getActionCommand().compareTo("画面をクリアする") == 0) { System.out.println(" 画面をクリアするだと思うのだな"); System.out.println(" ではしよう"); // mosskite img.clearImage(); mame = null; repaint(); } else if(e.getActionCommand().compareTo("答える") == 0) { System.out.println(" 答えるだと思うのだな"); Data dat; Mametan mame; Pattern pat = new Pattern(img.getArray(),img.Width(),img.Height()); int a = pat.searchEdge(); // edgeL.setText("端の数:"+a); //answL.setText("僕は思う"+a+"ではいかと"); dat = new Data(sujL.getSelectedItem()); for(int i = 0; i < a;i++) { mame = new Mametan(img,pat.putEdge()); mame.startDeconvolution(); dat.addMametan(mame); } answL.setText("僕は思う"+base.search(dat)+"ではいかと"); } else if(e.getActionCommand().compareTo("学習") == 0) { System.out.println(" 学習するだと思うのだな"); Data dat; Mametan mame; Pattern pat = new Pattern(img.getArray(),img.Width(),img.Height()); int a = pat.searchEdge(); // edgeL.setText("端の数:"+a); //answL.setText("僕は思う"+a+"ではいかと"); dat = new Data(sujL.getSelectedItem()); System.out.println(" 学習中"); for(int i = 0; i < a;i++) { mame = new Mametan(img,pat.putEdge()); mame.startDeconvolution(); dat.addMametan(mame); } base.addData(dat); System.out.println(" 学した"); } } }