Skip to content

Commit

Permalink
Code Cleanup and updated finish message
Browse files Browse the repository at this point in the history
  • Loading branch information
marios8543 committed Apr 6, 2019
1 parent 18a4e04 commit 2c64526
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 163 deletions.
23 changes: 23 additions & 0 deletions src/com/bongo/Canvas.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.bongo;

import javax.swing.*;
import java.awt.*;
import java.util.concurrent.TimeUnit;

class Canvas extends JComponent {
public void paintComponent(Graphics g){
g.clearRect(0, 0, Main.window.getWidth(), Main.window.getHeight());
for(int i=0;i<Main.bongos.length;i++){
Renderer.Bongo bongo = Main.bongos[i];
if(bongo!=null){
if (TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()) - 1 > bongo.getLastSecondValue()) {
Main.bongos[i] = null;
} else {
g.drawImage(bongo.getNote().getCpatch().getAsset(), bongo.getX(), bongo.getY(), this);
g.drawImage(Renderer.get_lhand(bongo.isL_hand()), bongo.getX(), bongo.getY(), this);
g.drawImage(Renderer.get_rhand(bongo.isR_hand()), bongo.getX(), bongo.getY(), this);
}
}
}
}
}
47 changes: 47 additions & 0 deletions src/com/bongo/FinishAnimation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.bongo;

import javax.swing.*;
import java.awt.*;

class FinishAnimation implements Icon {
private Boolean lhand = true;
private Boolean rhand = false;

FinishAnimation() {
final Thread renderThread = new Thread(new Runnable() {
@Override
public void run() {
while (true){
try {
Thread.sleep(200);
} catch (Exception e) {
JOptionPane.showMessageDialog(Main.window, e.getMessage(), "Rendering thread error", JOptionPane.ERROR_MESSAGE);
break;
}
if (component != null) component.repaint();
}
}
});
renderThread.start();
}

public void paintIcon(Component c, Graphics g, int x, int y) {
if (FinishAnimation.component == null) FinishAnimation.component = c;
g.clearRect(0,0, c.getWidth(), c.getHeight());
g.drawImage(Renderer.Instr_Categ.Bongo.getAsset(), x, y, c);
g.drawImage(Renderer.get_lhand(lhand), x, y, c);
g.drawImage(Renderer.get_rhand(rhand), x, y, c);
lhand=!lhand;
rhand=!rhand;
}

private static Component component;

public int getIconWidth() {
return 380;
}

public int getIconHeight() {
return 264;
}
}
Loading

0 comments on commit 2c64526

Please sign in to comment.