現在、完全に停電中です。下部に drawlines2 というメソッドがありますが、2 つの異なる引数で並列に実行するにはどうすればよいですか? 実行可能な実装を試してみましたが、実行メソッドに何を入れればよいかわかりません。同じクラスでスレッドを作成したいので、それを把握できません。
package javastuff;
/**
* Copyright © 2011 Parag Patil
* Licensed under the Apache License, Version 2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* You may not use this file except in compliance with Apache License, Version 2.0
* You may obtain a copy of the license at
* http://www.apache.org/licenses/LICENSE-2.0
**/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TreeAnimation {
public static final int SIZE_X = 1366;
public static final int SIZE_Y = 768;
public static void main(final String[] args) {
final PFrame pframe = new PFrame();
pframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final PCanvas canvas = new PCanvas((int)pframe.getBounds().getWidth(),(int)pframe.getBounds().getHeight());
pframe.add(canvas);
pframe.setVisible(true);
canvas.setIgnoreRepaint(true);
}
}
class PFrame extends JFrame {
private static final long serialVersionUID = 1L;
PFrame() {
setUndecorated(true);
final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(0,0,screenSize.width, screenSize.height);
final KeyStroke escapeKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0, false);
Action escapeAction = new AbstractAction() {
private static final long serialVersionUID = 1L;
public void actionPerformed(final ActionEvent e) {
System.exit(0);
}
};
getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeKeyStroke,"ESCAPE");
getRootPane().getActionMap().put("ESCAPE", escapeAction);
}
}
class PCanvas extends Canvas{
private static final long serialVersionUID = 1L;
public static int xsize;
public static int ysize;
public static final double TRIM_FACTOR = 0.8;
public static final double INITIAL_LENGTH = 180;
public static final double EXIT_LENGTH = 2;
public static final double BRANCH_ANGLE = Math.PI / 9.0;
public static final int WAIT = 10;
PCanvas(int size_x, int size_y) {
super();
xsize = size_x;
ysize = size_y - size_y / 20;
setBackground(Color.black);
setForeground(Color.white);
}
@Override
public void paint(final Graphics g) {
drawLine2(g, xsize / 2, 0, INITIAL_LENGTH, Math.PI / 2);
}
public void drawLine2(final Graphics g, final double x1, final double y1, final double l, final double theta) {
if (l < EXIT_LENGTH) {
return;
}
final double x2 = x1 + l * Math.cos(theta);
final double y2 = y1 + l * Math.sin(theta);
g.drawLine((int)x1, (int)(ysize - y1), (int)x2, (int)(ysize - y2));
//Here be parallelizable code
drawLine2(g, x2, y2, l * TRIM_FACTOR, theta - BRANCH_ANGLE);
drawLine2(g, x2, y2, l * TRIM_FACTOR, theta + BRANCH_ANGLE);
}
}