7 * @author Andersson, Andreen, Lanneskog, Pehrson
11 public class MooViewCounter extends JPanel {
13 private int timeSig1, timeSig2, measure, halfBeat, beat, halfNote;
14 private static final int CELL_HEIGHT = 10;
17 * Creates an musical ruler depending on the timesignature
20 public MooViewCounter (int ts1, int ts2) {
23 setBackground(Color.black);
24 setPreferredSize(new Dimension(35, 200 * CELL_HEIGHT));
26 case 16: measure = timeSig1; // 1/16
28 case 8: measure = timeSig1 * 2; // 1/16
29 halfBeat = measure / timeSig1; // 1/8
31 case 4: measure = timeSig1 * 4; // 1/16
32 halfBeat = beat / 2; // 1/8
33 beat = measure / timeSig1; // 1/4
35 case 2: measure = timeSig1 * 8; // 1/16
36 halfBeat = beat / 2; // 1/8
37 beat = halfNote / 2; // 1/4
38 halfNote = measure / timeSig1; // 1/2
40 case 1: measure = timeSig1 * 16; // 1/16
41 halfBeat = beat / 2; // 1/8
42 beat = halfNote / 2; // 1/4
43 halfNote = measure / 2; // 1/2
48 public void paintComponent(Graphics g) {
49 super.paintComponent(g);
50 setBackground(Color.black);
52 if (!(g instanceof Graphics2D)) return;
53 Graphics2D g2 = (Graphics2D)g;
54 g2.setColor(Color.white);
55 for (int c = 0; c < 200; c++) {
56 g2.drawLine(0, c * CELL_HEIGHT, 5, c * CELL_HEIGHT); // 1/16
57 g2.drawLine(0, c * CELL_HEIGHT * halfBeat, 10, c * CELL_HEIGHT * halfBeat); // 1/8
58 g2.drawLine(0, c * CELL_HEIGHT * beat, 15, c * CELL_HEIGHT * beat); // 1/4
59 g2.drawLine(0, c * CELL_HEIGHT * halfNote, 20, c * CELL_HEIGHT * halfNote); // 1/2
60 g2.drawLine(0, c * CELL_HEIGHT * measure, 30, c * CELL_HEIGHT * measure); // 1/1