]> ruin.nu Git - moosique.git/blob - MooViewCounter.java
inte helt klar
[moosique.git] / MooViewCounter.java
1 import javax.swing.*;
2 import java.awt.*;
3
4 /**
5  * 
6  * 
7  * @author  Andersson, Andreen, Lanneskog, Pehrson
8  * @version 1
9  */
10  
11 public class MooViewCounter extends JPanel {
12
13         //public static final int LINE_LENGTH;
14         private int measure, halfBeat, beat, halfNote;
15         //private String check; 
16         //private Line[];
17
18         /** 
19          * Creates 
20          */
21         private int timeSig1, timeSig2;
22          
23         public MooViewCounter (int ts1, int ts2) {
24                 timeSig1 = ts1;
25                 timeSig2 = ts2;
26                 
27         switch (timeSig2) {
28                         case  16: measure = timeSig1;  
29                         break;
30                         case  8: measure = timeSig1 * 2;
31                                          halfBeat = measure/timeSig1;
32                         break;
33                         case  4: measure = timeSig1 * (int)Math.pow(2,2);  
34                         break;
35                         case  2: measure = timeSig1 * (int)Math.pow(2,3); 
36                         break;
37                         case  1: measure = timeSig1 * (int)Math.pow(2,4);  
38                         break;
39                 }
40                 
41         }
42
43         public void paintComponent(Graphics g) {
44                 super.paintComponent(g);
45                 setBackground(Color.black);
46                 if (!(g instanceof Graphics2D)) return;
47                 Graphics2D g2 = (Graphics2D)g;
48                 setPreferredSize(new Dimension(50,200*10));
49                 g2.setColor(Color.white);
50                 for (int c = 0; c < 200; c++) {
51                         g2.drawLine(0,c*10,5,c*10);                                                     // 1/16
52                         g2.drawLine(0,c*10*halfBeat,10,c*10*halfBeat);                  // 1/8
53                         g2.drawLine(0,c*10*(beat/4),15,c*10*(beat/4));                  // 1/4
54                         g2.drawLine(0,c*10*(halfNote/2),20,c*10*(halfNote/2));  // 1/2
55                         g2.drawLine(0,c*10*measure,35,c*10*measure);                    // 1/1
56                         
57                 }
58         }
59 }