anonymous No title
Java
public class Score{
    private int score = 0;

    Score(int score){
        this.score = score;
    }

    Score(){
    }

    public void setScore(int score) {
        if (score >= 0 && score <= 100){
            this.score = score;
        }
    }
    public int getScore(){
        return score;
    }
    public void showResult(String person){
        System.out.println(person+"さんの点数:"+score);
    }

}
Yogurt FM Synth_Akira _002
Java
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Dimension;

import java.lang.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.sound.sampled.*;

public class SynthAkira extends JFrame {

  public static void main(String[] args){

		SynthAkira akira = new SynthAkira("Synth Akira");
		akira.setVisible(true);
  }

  SynthAkira(String title){
    setTitle(title);
    setBounds(100, 100, 600, 600);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container contentPane = getContentPane();
    contentPane.add(new SynthSlider(), BorderLayout.PAGE_START);
    contentPane.add(new DrawCurve(), BorderLayout.CENTER);
	}
}

class SynthSlider extends JPanel implements ChangeListener {

  JSlider slider1;
  JSlider slider2;
  JPanel p1;
  JPanel p2;
  JPanel p3;
  	JPanel p4;
  	JButton b1;
  JButton b2;
  JLabel label1;
  JLabel label2;
  
  	static byte[] wave_data = new byte[44100];
  
	SynthSlider() {
		
		slider1 = new JSlider(0, 1000);
    slider1.setValue(100);
    slider1.addChangeListener(this);
    slider2 = new JSlider(0, 1000);
    slider2.setValue(100);
    slider2.addChangeListener(this);

    p1 = new JPanel();
    p1.add(slider1);
    p1.add(slider2);

    b1 = new JButton("DOWN");
    b2 = new JButton("UP");
    
    p2 = new JPanel();
    p2.add(b1);
    p2.add(b2);
    
    label1 = new JLabel();
    label2 = new JLabel();
    label1.setText("値:" + slider1.getValue());
    label2.setText("値:" + slider2.getValue());

    p3 = new JPanel();
    p3.add(label1);
    p3.add(label2);

    p4 = new JPanel();
// 		p4.setPreferredSize(new Dimension(600, 400));
    p4.setLayout(new BorderLayout());
    p4.add(p1, BorderLayout.PAGE_START);
    p4.add(p2, BorderLayout.CENTER);
    p4.add(p3, BorderLayout.PAGE_END);

		add(p4);

    b1.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
      			setSound(1);
		  }
		});
    b2.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
      			setSound(2);
		  }
		});
	}

   void setSound(int j){
      try{
          double l1 = j*slider1.getValue()/44100.0;
         double l2 = j*slider2.getValue()/44100.0;
         for(int i=0;i<wave_data.length;i++){
            wave_data[i]= (byte)(110*(wave_data.length-(i+1))/wave_data.length*Math.sin((i*l1)*Math.PI*2)
            *Math.sin((i*l2)*Math.PI*2));
            			}
         AudioFormat   frmt= new AudioFormat(44100,8,1,true,false);
         DataLine.Info info= new DataLine.Info(Clip.class,frmt);
         Clip          clip= (Clip)AudioSystem.getLine(info);
         clip.open(frmt,wave_data,0,wave_data.length);
         clip.start();
	         }
      catch(Exception e){e.printStackTrace(System.err);}
      }

	public void stateChanged(ChangeEvent e) {
    label1.setText("値:" + slider1.getValue());
    label2.setText("値:" + slider2.getValue());
	}
}

class DrawCurve extends JPanel { 

	JButton b1;
	Paint paint;
	JPanel p1;

	DrawCurve() { 

		p1 = new JPanel();
      b1 = new JButton ("PUSH");
     b1.setPreferredSize(new Dimension(100, 30));
      paint = new Paint();
     paint.setPreferredSize(new Dimension(600, 200));
     	p1.setPreferredSize(new Dimension(600, 300));
		p1.add(b1);
		p1.add(paint);
		add(p1);

     b1.addActionListener(new ActionListener() {
	      @Override
	      public void actionPerformed(ActionEvent e) {
		 		paint.repaint();
			}
		}); 
	 } 
}

class Paint extends JPanel {
	
	byte[] wave_data = SynthSlider.wave_data;
	
	public Paint() {
		super();
	}
	
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		g.setColor(Color.RED);
		for(int i = 0; i < (wave_data.length/200-1); i++) {
    			g.drawLine(i*2,128-wave_data[i*200],(i+1)*2,128-wave_data[(i+1)*200]);
 		}
	}
} 
Yogurt FM SynthAkira001
Java
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import javax.swing.*;
import javax.swing.event.*;
import javax.sound.sampled.*;

public class SynthAkira extends JFrame implements ChangeListener{

  JSlider slider1;
  JSlider slider2;
  JPanel p1;
  JPanel p2;
  JButton b;
  JLabel label1;
  JLabel label2;

  public static void main(String[] args){
    SynthAkira frame = new SynthAkira();

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(10, 10, 600, 200);
    frame.setTitle("SYNTH AKIRA");
    frame.setVisible(true);
  }

  SynthAkira(){

    slider1 = new JSlider(0, 1000);
    slider1.setValue(100);
    slider1.addChangeListener(this);
    slider2 = new JSlider(0, 1000);
    slider2.setValue(100);
    slider2.addChangeListener(this);

    p1 = new JPanel();
    p1.add(slider1);
    p1.add(slider2);

    b = new JButton("PUSH");

    label1 = new JLabel();
    label2 = new JLabel();
    label1.setText("値:" + slider1.getValue());
    label2.setText("値:" + slider2.getValue());

    p2 = new JPanel();
    p2.add(label1);
    p2.add(label2);

    getContentPane().add(p1, BorderLayout.PAGE_START);
    getContentPane().add(b, BorderLayout.CENTER);
    getContentPane().add(p2, BorderLayout.PAGE_END);
    
    b.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
      			setSound();
		  }
		});
	}

   void setSound(){
      try{
         byte[] wave_data= new byte[44100*2];
         double l1      = 44100.0/slider1.getValue();
         double l2      = 44100.0/slider2.getValue();
         for(int i=0;i<wave_data.length;i++){
            wave_data[i]= (byte)(110*Math.sin((i/l1)*Math.PI*2
            +110*Math.sin((i/l2)*Math.PI*2)));
            }
         AudioFormat   frmt= new AudioFormat(44100,8,1,true,false);
         DataLine.Info info= new DataLine.Info(Clip.class,frmt);
         Clip          clip= (Clip)AudioSystem.getLine(info);
         clip.open(frmt,wave_data,0,wave_data.length);
         clip.start();

         Thread.sleep(100);while(clip.isRunning()) {Thread.sleep(100);}
         }
      catch(Exception e){e.printStackTrace(System.err);}
      }

	public void stateChanged(ChangeEvent e) {
    label1.setText("値:" + slider1.getValue());
    label2.setText("値:" + slider2.getValue());
 }
}
anonymous No title
Java
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import javax.swing.*;
import javax.swing.event.*;
import javax.sound.sampled.*;

public class SynthAkira extends JFrame implements ChangeListener{

  JSlider slider1;
  JSlider slider2;
  JPanel p1;
  JPanel p2;
  JButton b;
  JLabel label1;
  JLabel label2;

  public static void main(String[] args){
    SynthAkira frame = new SynthAkira();

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(10, 10, 600, 200);
    frame.setTitle("SYNTH AKIRA");
    frame.setVisible(true);
  }

  SynthAkira(){

    slider1 = new JSlider(0, 1000);
    slider1.setValue(100);
    slider1.addChangeListener(this);
    slider2 = new JSlider(0, 1000);
    slider2.setValue(100);
    slider2.addChangeListener(this);

    p1 = new JPanel();
    p1.add(slider1);
    p1.add(slider2);

    b = new JButton("PUSH");

    label1 = new JLabel();
    label2 = new JLabel();
    label1.setText("値:" + slider1.getValue());
    label2.setText("値:" + slider2.getValue());

    p2 = new JPanel();
    p2.add(label1);
    p2.add(label2);

    getContentPane().add(p1, BorderLayout.PAGE_START);
    getContentPane().add(b, BorderLayout.CENTER);
    getContentPane().add(p2, BorderLayout.PAGE_END);
    
    b.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
      			setSound();
		  }
		});
	}

   void setSound(){
      try{
         byte[] wave_data= new byte[44100*2];
         double l1      = 44100.0/slider1.getValue();
         double l2      = 44100.0/slider2.getValue();
         for(int i=0;i<wave_data.length;i++){
            wave_data[i]= (byte)(110*Math.sin((i/l1)*Math.PI*2
            +110*Math.sin((i/l2)*Math.PI*2)));
            }
         AudioFormat   frmt= new AudioFormat(44100,8,1,true,false);
         DataLine.Info info= new DataLine.Info(Clip.class,frmt);
         Clip          clip= (Clip)AudioSystem.getLine(info);
         clip.open(frmt,wave_data,0,wave_data.length);
         clip.start();

         Thread.sleep(100);while(clip.isRunning()) {Thread.sleep(100);}
         }
      catch(Exception e){e.printStackTrace(System.err);}
      }

	public void stateChanged(ChangeEvent e) {
    label1.setText("値:" + slider1.getValue());
    label2.setText("値:" + slider2.getValue());
 }
}
anonymous No title
Java
private double[][] estimatePose(List<Mat> corners){
        float marker_length = (float) 0.05;//0.05
        double camera_matrix[] = {344.173397, 0.000000, 630.793795,
                0.000000, 344.277922, 487.033834,
                0.000000, 0.000000, 1.000000};
        double distortion_coefficients[] = {-0.152963, 0.017530, -0.001107,
                -0.000210, 0.000000};
        Mat camera_matrix_mat = new Mat(3,3,CV_64F);
        Mat distortion_coefficients_mat = new Mat(1,5,CV_64F);
        camera_matrix_mat.put(0,0,camera_matrix[0]);
        camera_matrix_mat.put(0,1,camera_matrix[1]);
        camera_matrix_mat.put(0,2,camera_matrix[2]);
        camera_matrix_mat.put(1,0,camera_matrix[3]);
        camera_matrix_mat.put(1,1,camera_matrix[4]);
        camera_matrix_mat.put(1,2,camera_matrix[5]);
        camera_matrix_mat.put(2,0,camera_matrix[6]);
        camera_matrix_mat.put(2,1,camera_matrix[7]);
        camera_matrix_mat.put(2,2,camera_matrix[8]);
        distortion_coefficients_mat.put(0,0,distortion_coefficients[0]);
        distortion_coefficients_mat.put(0,1,distortion_coefficients[1]);
        distortion_coefficients_mat.put(0,2,distortion_coefficients[2]);
        distortion_coefficients_mat.put(0,3,distortion_coefficients[3]);
        distortion_coefficients_mat.put(0,4,distortion_coefficients[4]);
        Mat rvecs = new Mat();
        Mat tvecs = new Mat();
        Aruco.estimatePoseSingleMarkers(corners,marker_length,camera_matrix_mat,distortion_coefficients_mat,rvecs,tvecs);
        Log.d("MY_STRING", "rvecs[0,0] =" + Arrays.toString(rvecs.get(0, 0)));
        Log.d("MY_STRING", "tvecs[0,0] = "+ Arrays.toString(tvecs.get(0, 0)));
        double[][] ans = new double[2][];
        ans[0] = rvecs.get(0,0);
        ans[1] = tvecs.get(0,0);
        return ans;
    }
    private boolean readARmarker(Bitmap bitmap, boolean needSend) {
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        bitmap = Bitmap.createScaledBitmap(bitmap,(int)(width*0.3),(int)(height*0.3),true);
        Mat inputImage = new Mat();
        bitmapToMat(bitmap,inputImage,false);
        Dictionary dictionary = Aruco.getPredefinedDictionary(Aruco.DICT_5X5_250);
        List<Mat> corners = new ArrayList<>();
        Mat markerIds = new Mat();
        DetectorParameters parameters = DetectorParameters.create();
        Imgproc.cvtColor(inputImage, inputImage, Imgproc.COLOR_BGR2GRAY);
        Aruco.detectMarkers(inputImage, dictionary, corners, markerIds, parameters);
        String markerIDfromArr = Arrays.toString(markerIds.get(0, 0));
        if (markerIDfromArr.equals("null")) {
            return false;
        } else {
            String markerID = String.valueOf((int)(markerIds.get(0, 0)[0]));
            double[][] vecs = estimatePose(corners);
            //vecs[][]はrvecとtvecが入った二次元配列です。以下にそれぞれの要素を示します。
            Log.d("MY_STRING", "rvec_1 = " +vecs[0][0]);
            Log.d("MY_STRING", "rvec_2 = " +vecs[0][1]);
            Log.d("MY_STRING", "rvec_3 = " +vecs[0][2]);
            Log.d("MY_STRING", "tvec_1 = " +vecs[1][0]);
            Log.d("MY_STRING", "tvec_2 = " +vecs[1][1]);
            Log.d("MY_STRING", "tvec_3 = " +vecs[1][2]);

            if(needSend){
                api.judgeSendDiscoveredAR(markerID);
            }
            return true;
        }
    }
anonymous No title
Java
package sep3.model.cycle;

import sep3.Model;
import sep3.model.CPU;
import sep3.model.operation.InstructionSet;

public class ReadFromOpe2 extends State {
	@Override
	public State clockstep(Model model) {
		//System.out.println("%% IF0 %%");
		// ステータスカウンタの設定。次の2行は、すべての状態において、最初に必ず記述すること
		CPU cpu = model.getCPU();
		cpu.getRegister(CPU.REG_SC).setInitValue(StateFactory.SC_FF2);

		//MDRからAバスへ送る
		cpu.getABusSelector().selectFrom(CPU.REG_MDR);
		//ALUはAバスの値をそのままSバスへ流す
		cpu.getALU().operate(InstructionSet.OP_THRA);
		//Sバスの値をB0へ送る
		cpu.getSBusSelector().selectTo(CPU.REG_B0);


		// 次の状態へ
		return cpu.getStateFactory().getState(StateFactory.SC_HLT);
	}

}
anonymous No title
Java
package sep3.model.cycle;


import sep3.Model;
import sep3.model.CPU;
import sep3.model.Memory;

public class ReadFromOpe1 extends State {
	@Override
	public State clockstep(Model model) {
		//System.out.println("%% IF1 %%");
		// ステータスカウンタの設定。次の2行は、すべての状態において、最初に必ず記述すること
		CPU cpu = model.getCPU();
		cpu.getRegister(CPU.REG_SC).setInitValue(StateFactory.SC_FF1);

		// MARに格納されている番地から命令を読み出してISRへ送る

		// MAR をアドレスバスに流す
		model.getAddrBusSelector().selectFrom(CPU.REG_MAR);
		// メモリを読み出してデータバスへ出力
		model.getMemory().access(Memory.MEM_RD);
		// データバスの値をMDRへ送る
		model.getDataBusSelector().selectTo(CPU.REG_MDR);

		// 次の状態へ
		//return cpu.getStateFactory().getState(StateFactory.SC_HLT);
		return cpu.getStateFactory().getState(StateFactory.SC_FF2);
	}
}
anonymous No title
Java
package sep3.model.cycle;

import sep3.Model;
import sep3.model.CPU;
import sep3.model.operation.InstructionSet;

public class ReadFromOpe0 extends State {
	@Override
	public State clockstep(Model model) {
		//System.out.println("%% IF0 %%");
		// ステータスカウンタの設定。次の2行は、すべての状態において、最初に必ず記述すること
		CPU cpu = model.getCPU();
		cpu.getRegister(CPU.REG_SC).setInitValue(StateFactory.SC_FF0);


		// Fromオペランドで指定されたレジスタの値(R6とする)を MARへ送る

		//指定されたレジスタからAバスに流す
		cpu.getABusSelector().selectFrom(CPU.REG_R6);
		//ALUをそのまま貫通してSバスに流す
        cpu.getALU().operate(InstructionSet.OP_THRA);
		//SバスからMARに送る
        cpu.getSBusSelector().selectTo(CPU.REG_MAR);


		// 次の状態へ
		return cpu.getStateFactory().getState(StateFactory.SC_FF1);
	}

}
anonymous No title
Java
/*
 [The "BSD license"]
  Copyright (c) 2013 Terence Parr
  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions
  are met:

  1. Redistributions of source code must retain the above copyright
     notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in the
     documentation and/or other materials provided with the distribution.
  3. The name of the author may not be used to endorse or promote products
     derived from this software without specific prior written permission.

  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

import org.antlr.v4.runtime.ANTLRFileStream;
import org.antlr.v4.runtime.BailErrorStrategy;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.DiagnosticErrorListener;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.atn.LexerATNSimulator;
import org.antlr.v4.runtime.atn.PredictionMode;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.gui.Trees;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeWalker;

import java.io.File;
import java.lang.System;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/* This more or less duplicates the functionality of grun (TestRig) but it
 * has a few specific options for benchmarking like -x2 and -threaded.
 * It also allows directory names as commandline arguments. The simplest test is
 * for the current directory:

~/antlr/code/grammars-v4/java $ java Test .
/Users/parrt/antlr/code/grammars-v4/java9/JavaBaseListener.java
/Users/parrt/antlr/code/grammars-v4/java9/Java9Lexer.java
/Users/parrt/antlr/code/grammars-v4/java9/JavaListener.java
/Users/parrt/antlr/code/grammars-v4/java9/JavaParser.java
/Users/parrt/antlr/code/grammars-v4/java9/Test.java
Total lexer+parser time 1867ms.
 */
class Test {
//	public static long lexerTime = 0;
	public static boolean profile = false;
	public static boolean notree = false;
	public static boolean gui = false;
	public static boolean printTree = false;
	public static boolean SLL = false;
	public static boolean diag = false;
	public static boolean bail = false;
	public static boolean x2 = false;
	public static boolean threaded = false;
	public static boolean quiet = false;
//	public static long parserStart;
//	public static long parserStop;
	public static Worker[] workers = new Worker[3];
	static int windex = 0;

	public static CyclicBarrier barrier;

	public static volatile boolean firstPassDone = false;

	public static class Worker implements Runnable {
		public long parserStart;
		public long parserStop;
		List<String> files;
		public Worker(List<String> files) {
			this.files = files;
		}
		@Override
		public void run() {
			parserStart = System.currentTimeMillis();
			for (String f : files) {
				parseFile(f);
			}
			parserStop = System.currentTimeMillis();
			try {
				barrier.await();
			}
			catch (InterruptedException ex) {
				return;
			}
			catch (BrokenBarrierException ex) {
				return;
			}
		}
	}

	public static void main(String[] args) {
		doAll(args);
	}

	public static void doAll(String[] args) {
		List<String> inputFiles = new ArrayList<String>();
		long start = System.currentTimeMillis();
		try {
			if (args.length > 0 ) {
				// for each directory/file specified on the command line
				for(int i=0; i< args.length;i++) {
					if ( args[i].equals("-notree") ) notree = true;
					else if ( args[i].equals("-gui") ) gui = true;
					else if ( args[i].equals("-ptree") ) printTree = true;
					else if ( args[i].equals("-SLL") ) SLL = true;
					else if ( args[i].equals("-bail") ) bail = true;
					else if ( args[i].equals("-diag") ) diag = true;
					else if ( args[i].equals("-2x") ) x2 = true;
					else if ( args[i].equals("-threaded") ) threaded = true;
					else if ( args[i].equals("-quiet") ) quiet = true;
					if ( args[i].charAt(0)!='-' ) { // input file name
						inputFiles.add(args[i]);
					}
				}
				List<String> javaFiles = new ArrayList<String>();
				for (String fileName : inputFiles) {
					List<String> files = getFilenames(new File(fileName));
					javaFiles.addAll(files);
				}
				doFiles(javaFiles);

//				DOTGenerator gen = new DOTGenerator(null);
//				String dot = gen.getDOT(Java9Parser._decisionToDFA[112], false);
//				System.out.println(dot);
//				dot = gen.getDOT(Java9Parser._decisionToDFA[81], false);
//				System.out.println(dot);

				if ( x2 ) {
					System.gc();
					System.out.println("waiting for 1st pass");
					if ( threaded ) while ( !firstPassDone ) { } // spin
					System.out.println("2nd pass");
					doFiles(javaFiles);
				}
			}
			else {
				System.err.println("Usage: java Main <directory or file name>");
			}
		}
		catch(Exception e) {
			System.err.println("exception: "+e);
			e.printStackTrace(System.err);   // so we can get stack trace
		}
		long stop = System.currentTimeMillis();
//		System.out.println("Overall time " + (stop - start) + "ms.");
		System.gc();
	}

	public static void doFiles(List<String> files) throws Exception {
		long parserStart = System.currentTimeMillis();
//		lexerTime = 0;
		if ( threaded ) {
			barrier = new CyclicBarrier(3,new Runnable() {
				public void run() {
					report(); firstPassDone = true;
				}
			});
			int chunkSize = files.size() / 3;  // 10/3 = 3
			int p1 = chunkSize; // 0..3
			int p2 = 2 * chunkSize; // 4..6, then 7..10
			workers[0] = new Worker(files.subList(0,p1+1));
			workers[1] = new Worker(files.subList(p1+1,p2+1));
			workers[2] = new Worker(files.subList(p2+1,files.size()));
			new Thread(workers[0], "worker-"+windex++).start();
			new Thread(workers[1], "worker-"+windex++).start();
			new Thread(workers[2], "worker-"+windex++).start();
		}
		else {
			for (String f : files) {
				parseFile(f);
			}
			long parserStop = System.currentTimeMillis();
			System.out.println("Total lexer+parser time " + (parserStop - parserStart) + "ms.");
		}
	}

	private static void report() {
//		parserStop = System.currentTimeMillis();
//		System.out.println("Lexer total time " + lexerTime + "ms.");
		long time = 0;
		if ( workers!=null ) {
			// compute max as it's overlapped time
			for (Worker w : workers) {
				long wtime = w.parserStop - w.parserStart;
				time = Math.max(time,wtime);
				System.out.println("worker time " + wtime + "ms.");
			}
		}
		System.out.println("Total lexer+parser time " + time + "ms.");

		System.out.println("finished parsing OK");
		//System.out.println(LexerATNSimulator.match_calls+" lexer match calls");
//		System.out.println(ParserATNSimulator.predict_calls +" parser predict calls");
//		System.out.println(ParserATNSimulator.retry_with_context +" retry_with_context after SLL conflict");
//		System.out.println(ParserATNSimulator.retry_with_context_indicates_no_conflict +" retry sees no conflict");
//		System.out.println(ParserATNSimulator.retry_with_context_predicts_same_alt +" retry predicts same alt as resolving conflict");
	}

	public static List<String> getFilenames(File f) throws Exception {
		List<String> files = new ArrayList<String>();
		getFilenames_(f, files);
		return files;
	}

	public static void getFilenames_(File f, List<String> files) throws Exception {
		// If this is a directory, walk each file/dir in that directory
		if (f.isDirectory()) {
			String flist[] = f.list();
			for(int i=0; i < flist.length; i++) {
				getFilenames_(new File(f, flist[i]), files);
			}
		}

		// otherwise, if this is a java file, parse it!
		else if ( ((f.getName().length()>5) &&
			f.getName().substring(f.getName().length()-5).equals(".java")) )
		{
			files.add(f.getAbsolutePath());
		}
	}

	// This method decides what action to take based on the type of
	//   file we are looking at
//	public static void doFile_(File f) throws Exception {
//		// If this is a directory, walk each file/dir in that directory
//		if (f.isDirectory()) {
//			String files[] = f.list();
//			for(int i=0; i < files.length; i++) {
//				doFile_(new File(f, files[i]));
//			}
//		}
//
//		// otherwise, if this is a java file, parse it!
//		else if ( ((f.getName().length()>5) &&
//			f.getName().substring(f.getName().length()-5).equals(".java")) )
//		{
//			System.err.println(f.getAbsolutePath());
//			parseFile(f.getAbsolutePath());
//		}
//	}

	public static void parseFile(String f) {
		try {
			if ( !quiet ) System.err.println(f);
			// Create a scanner that reads from the input stream passed to us
			Lexer lexer = new Java9Lexer(new ANTLRFileStream(f));
			//Lexer lexer = new Java9Lexer(CharStreams.fromString("public class test {}"));

			CommonTokenStream tokens = new CommonTokenStream(lexer);
//			long start = System.currentTimeMillis();
//			tokens.fill(); // load all and check time
//			long stop = System.currentTimeMillis();
//			lexerTime += stop-start;

			// Create a parser that reads from the scanner
			Java9Parser parser = new Java9Parser(tokens);

			//ParseTree tree = parser.compilationUnit();

			if ( diag ) parser.addErrorListener(new DiagnosticErrorListener());
			if ( bail ) parser.setErrorHandler(new BailErrorStrategy());
			if ( SLL ) parser.getInterpreter().setPredictionMode(PredictionMode.SLL);

			// start parsing at the compilationUnit rule
			ParserRuleContext t = parser.compilationUnit();

			ParseTreeWalker walker = new ParseTreeWalker();
      ExtractListener extractor = new ExtractListener(parser);
      walker.walk(extractor,t);

			if ( notree ) parser.setBuildParseTree(false);
			if ( gui ) Trees.inspect(t, parser); //t.inspect(parser);
			if ( printTree ) System.out.println(t.toStringTree(parser));
		}
		catch (Exception e) {
			System.err.println("parser exception: "+e);
			e.printStackTrace();   // so we can get stack trace
		}
	}
}
出口尚哉 No title
Java
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.event.*;
import java.util.List;
import java.util.ArrayList;

public class MyPanel extends JPanel {
	private List<Shape> shapes;

	public MyPanel() {
		super();
		this.shapes = new ArrayList<>();
		MouseAdapter myMcl = new MyMouseClickListener(this);  // change here
		// insert here
		this.addMouseListener(myMcl);
		}

	public void addShape(Shape s) {
		this.shapes.add(s);
		this.repaint();
		}

	public void panelClicked(int x, int y){
		for (Shape s : this.shapes) {
			if (s != null) {
				s.select(x, y);
				}
			}// insert here
		this.repaint();
		}

	@Override
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		System.out.println("MyPanel repainting ...");
		for (Shape s : this.shapes) {
			if (s != null) {
				s.draw(g);
				}
			}
		}
	}
Don't you submit code?
Submit
年末年始は機械学習・深層学習を勉強しませんか?
広告
未経験から最短でエンジニアへの転職を目指すなら