aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/AudioFilePlayer.java96
-rw-r--r--src/main/Driver.java19
-rw-r--r--src/main/Gui.java41
-rw-r--r--src/main/KeyDetection.java27
-rw-r--r--src/main/NoteTest.java35
-rw-r--r--src/main/RoundedRectangleTest.java92
-rw-r--r--src/main/SongPlayer.java97
-rw-r--r--src/main/TButton.java30
-rw-r--r--src/main/block.java85
-rw-r--r--src/main/jfxTest.java35
-rw-r--r--src/main/shadowtest.java40
11 files changed, 597 insertions, 0 deletions
diff --git a/src/main/AudioFilePlayer.java b/src/main/AudioFilePlayer.java
new file mode 100644
index 0000000..c3b9728
--- /dev/null
+++ b/src/main/AudioFilePlayer.java
@@ -0,0 +1,96 @@
+package main;
+//Java program to play audio files. imports file scanning and various
+//methods from the java audio class in order to do so.
+import java.io.File;
+import java.io.IOException;
+
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioInputStream;
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.Clip;
+import javax.sound.sampled.DataLine;
+import javax.sound.sampled.LineEvent;
+import javax.sound.sampled.LineListener;
+import javax.sound.sampled.LineUnavailableException;
+import javax.sound.sampled.UnsupportedAudioFileException;
+
+public class AudioFilePlayer implements LineListener
+{
+ //indicates whether the playback completes or not
+ boolean playCompleted;
+ Clip audioClip;
+
+ public void play(String audioFilePath)
+ {
+ File audioFile = new File(audioFilePath);
+
+ try
+ {
+ //creates an audioInput object using the file we
+ //declared earlier
+ AudioInputStream audioStream = AudioSystem.getAudioInputStream(audioFile);
+
+ //gets the format of the audioStream object
+ AudioFormat format = audioStream.getFormat();
+
+ DataLine.Info info = new DataLine.Info(Clip.class, format);
+
+ audioClip = (Clip) AudioSystem.getLine(info);
+
+ audioClip.addLineListener(this);
+
+ audioClip.open(audioStream);
+
+ audioClip.start();
+
+ while (!playCompleted)
+ {
+ // wait for the playback to complete
+ try
+ {
+ Thread.sleep(1000);
+ }
+ catch (InterruptedException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ audioClip.close(); //stops the audio clip
+ }
+ catch (UnsupportedAudioFileException ex)
+ {
+ System.out.println("The specified audio file is not supported.");
+ ex.printStackTrace();
+ }
+ catch (LineUnavailableException ex)
+ {
+ System.out.println("Audio line for playing back is unavailable.");
+ ex.printStackTrace();
+ }
+ catch (IOException ex)
+ {
+ System.out.println("Error playing the audio file.");
+ ex.printStackTrace();
+ }
+ }
+
+
+ /**
+ * Listens to the START and STOP events of the audio line.
+ */
+ @Override
+ public void update(LineEvent event)
+ {
+ LineEvent.Type type = event.getType();
+
+ if (type == LineEvent.Type.START)
+ {
+ System.out.println("Playback started.");
+ }
+ else if (type == LineEvent.Type.STOP)
+ {
+ playCompleted = true;
+ System.out.println("Playback completed.");
+ }
+ }
+}
diff --git a/src/main/Driver.java b/src/main/Driver.java
new file mode 100644
index 0000000..7b04b2f
--- /dev/null
+++ b/src/main/Driver.java
@@ -0,0 +1,19 @@
+/*Name:
+ *Date:
+ *Period:
+ *Teacher:
+ *Description:
+ */
+package main;
+
+
+public class Driver
+{
+
+ public static void main(String[] args)
+ {
+ System.out.println("test");
+ //new shadowtest();
+ }
+
+}
diff --git a/src/main/Gui.java b/src/main/Gui.java
new file mode 100644
index 0000000..a8dad5c
--- /dev/null
+++ b/src/main/Gui.java
@@ -0,0 +1,41 @@
+/*Name:
+ *Date:
+ *Period:
+ *Teacher:
+ *Description:
+ */
+package main;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+public class Gui {
+ public Gui()
+ {
+ /* JFrame is a top level container (window)
+ * where we would be adding our button
+ */
+ JFrame frame=new JFrame();
+
+ // Creating Button
+ JButton b=new JButton("Click Me..");
+ /* This method specifies the location and size
+ * of button. In method setBounds(x, y, width, height)
+ * x,y) are cordinates from the top left
+ * corner and remaining two arguments are the width
+ * and height of the button.
+ */
+ b.setBounds(50,50,200, 50);
+
+ //Adding button onto the frame
+ frame.add(b);
+
+ // Setting Frame size. This is the window size
+ frame.setSize(600,500);
+
+ frame.setLayout(null);
+ frame.setVisible(true);
+
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+ }
+}
diff --git a/src/main/KeyDetection.java b/src/main/KeyDetection.java
new file mode 100644
index 0000000..7887405
--- /dev/null
+++ b/src/main/KeyDetection.java
@@ -0,0 +1,27 @@
+/*Name:
+ *Date:
+ *Period:
+ *Teacher:
+ *Description:
+ */
+package main;
+
+import javax.swing.*;
+import java.awt.event.ActionEvent;
+
+public class KeyDetection extends AbstractAction
+{
+ long timeStart = System.currentTimeMillis();
+ private char key;
+ public KeyDetection(char ch){
+ key = ch;
+ }
+
+ public void actionPerformed(ActionEvent e)
+ {
+ // TODO Auto-generated method stub
+ int time = (int)((System.currentTimeMillis()-timeStart));
+ System.out.println(key + ": " + time);
+ }
+
+}
diff --git a/src/main/NoteTest.java b/src/main/NoteTest.java
new file mode 100644
index 0000000..34d9c8c
--- /dev/null
+++ b/src/main/NoteTest.java
@@ -0,0 +1,35 @@
+/*Name:
+ *Date:
+ *Period:
+ *Teacher:
+ *Description:
+ */
+package main;
+import java.awt.*;
+
+public class NoteTest
+{
+ private boolean failed = false;
+ private int lane;
+ private final int NOTESPEED = 1;
+ private int yPos = SongPlayer.HEIGHT;
+
+ public void gameTick() {
+ if (!failed) {
+ if (yPos > 0) {
+ yPos -= NOTESPEED;
+ }
+ else {
+ failed = true;
+ }
+ }
+ }
+
+ public boolean getFailed() {
+ return failed;
+ }
+
+ public int getY() {
+ return yPos;
+ }
+}
diff --git a/src/main/RoundedRectangleTest.java b/src/main/RoundedRectangleTest.java
new file mode 100644
index 0000000..e5f40d2
--- /dev/null
+++ b/src/main/RoundedRectangleTest.java
@@ -0,0 +1,92 @@
+package main;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.RoundRectangle2D;
+//import javafx.scene.effect.DropShadow;
+
+import javax.swing.*;
+
+public class RoundedRectangleTest extends JFrame {
+ public RoundedRectangleTest() {
+ setTitle("RoundedRectangle Test");
+ setSize(350, 275);
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ setLocationRelativeTo(null);
+ setVisible(true);
+ }
+ public void paint(Graphics g) {
+ //DropShadowBorder shadow = new DropShadowBorder();
+
+ Graphics2D g2d = (Graphics2D) g;
+ g2d.setPaint(Color.DARK_GRAY);
+ g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ g2d.fillRoundRect(10, 50, 150, 150, 30, 30); // to draw a rounded rectangle.
+
+ /*Graphics2D g2d = (Graphics2D) g;
+ Color holdColor = g2d.getColor();
+ g2d.setColor(Color.black);
+ AffineTransform holdTransform = g2d.getTransform();
+ // want the shadow to be one line width pixel offset
+ float lineWidth;
+ if (g2d.getStroke() instanceof BasicStroke)
+ {
+ lineWidth = ((BasicStroke) (g2d.getStroke())).getLineWidth();
+ }
+ else
+ {
+ lineWidth = 1.0f;
+ }
+ //System.err.println("DrawingUtilities.drawShadowedShape(): lineWidth = "+lineWidth);
+ //g2d.translate(lineWidth, lineWidth);
+ g2d.fillRoundRect(10, 50, 150, 150, 30, 30);
+ //g2d.setColor(holdColor);
+ //g2d.setTransform(holdTransform);
+ //g2d.drawRoundRect(10, 50, 150, 150, 30, 30);
+ */
+
+
+ }
+ public static void main(String []args) {
+ new RoundedRectangleTest();
+ }
+
+ public static void drawShadowedShape(Shape shape, Graphics2D g2d)
+ {
+ Color holdColor = g2d.getColor();
+ g2d.setColor(Color.black);
+ AffineTransform holdTransform = g2d.getTransform();
+ // want the shadow to be one line width pixel offset
+ float lineWidth;
+ if (g2d.getStroke() instanceof BasicStroke)
+ {
+ lineWidth = ((BasicStroke) (g2d.getStroke())).getLineWidth();
+ }
+ else
+ {
+ lineWidth = 1.0f;
+ }
+ //System.err.println("DrawingUtilities.drawShadowedShape(): lineWidth = "+lineWidth);
+ g2d.translate(lineWidth, lineWidth);
+ g2d.draw(shape);
+ g2d.setColor(holdColor);
+ g2d.setTransform(holdTransform);
+ g2d.draw(shape);
+ }
+
+ public static void drawShadowedShape2(Shape shape, Graphics2D g2d) {
+ Color holdColor = g2d.getColor();
+ g2d.setColor(Color.black);
+ AffineTransform holdTransform = g2d.getTransform();
+ // want the shadow to be one line width pixel offset
+ float lineWidth = g2d.getStroke() instanceof BasicStroke ? ((BasicStroke) (g2d.getStroke())).getLineWidth()
+ : 1.0f;
+ //System.err.println("DrawingUtilities.drawShadowedShape(): lineWidth = "+lineWidth);
+ g2d.translate(lineWidth, lineWidth);
+ g2d.draw(shape);
+ g2d.setColor(holdColor);
+ g2d.setTransform(holdTransform);
+ g2d.draw(shape);
+ }
+} \ No newline at end of file
diff --git a/src/main/SongPlayer.java b/src/main/SongPlayer.java
new file mode 100644
index 0000000..caf1ab7
--- /dev/null
+++ b/src/main/SongPlayer.java
@@ -0,0 +1,97 @@
+/*Name:
+ *Date:
+ *Period:
+ *Teacher:
+ *Description:
+ */
+package main;
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+
+public class SongPlayer
+{
+ public static final int HEIGHT = 650;
+ public static final int LENGTH = 400;
+
+
+ private final int BLENGTH = LENGTH/6;
+ private final int BHEIGHT = HEIGHT/20;
+ JFrame frame = new JFrame("Guitar Hero"); //creates the frame
+
+
+ JButton d = new JButton("D"); //creates the four button lanes
+ JButton f = new JButton("F");
+ JButton h = new JButton("H");
+ JButton j = new JButton("J");
+
+
+ public void createAndShowGui() {
+
+ d.setBounds(1*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT); //makes the button bounds for each button
+ f.setBounds(2*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT);
+ h.setBounds(3*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT);
+ j.setBounds(4*BLENGTH, (5*HEIGHT)/6, BLENGTH, BHEIGHT);
+
+
+ frame.add(d); //adds the buttons to the frame
+ frame.add(f);
+ frame.add(h);
+ frame.add(j);
+
+ frame.setSize(LENGTH, HEIGHT); //sets the size of the frame
+ frame.setLayout(null); //???
+ frame.setVisible(true); //makes the frame visible
+
+ KeyDetection dAction = new KeyDetection('d'); //creates an action for each char
+ d.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke('d'), "dPress"); //Input map and Action map setting
+ d.getActionMap().put("dPress", dAction);
+ d.setFocusable(false); //makes it so you can't highlight the button
+
+ KeyDetection fAction = new KeyDetection('f');
+ f.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke('f'), "fPress");
+ f.getActionMap().put("fPress", fAction);
+ f.setFocusable(false);
+
+ KeyDetection hAction = new KeyDetection('h');
+ h.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke('h'), "hPress");
+ h.getActionMap().put("hPress", hAction);
+ h.setFocusable(false);
+
+ KeyDetection jAction = new KeyDetection('j');
+ j.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke('j'), "jPress");
+ j.getActionMap().put("jPress", jAction);
+ j.setFocusable(false);
+ }
+
+ public void loop() {
+ JButton note = new JButton();
+ JButton test = new JButton();
+ test.setBounds(200, 200, 100, 100);
+ note.setBounds(BLENGTH, 0, BLENGTH, BHEIGHT);
+ frame.add(note);
+ frame.add(test);
+
+ NoteTest a = new NoteTest();
+ while (!a.getFailed()) {
+ if (!a.getFailed()) {
+ a.gameTick();
+ note.setBounds(BLENGTH, HEIGHT-a.getY(), BLENGTH, BHEIGHT); //moves the note down every frame
+ System.out.println(a.getFailed());
+ //the computer runs too fast normally, force it to run at a certain fps
+ try {
+ Thread.sleep(2);
+ } catch (InterruptedException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ if (a.getFailed()) {
+ frame.remove(note); //removes the note once its off the screen
+ }
+ }
+ }
+}
diff --git a/src/main/TButton.java b/src/main/TButton.java
new file mode 100644
index 0000000..ab3cfa8
--- /dev/null
+++ b/src/main/TButton.java
@@ -0,0 +1,30 @@
+package main;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import java.awt.Color;
+import java.awt.Graphics;
+
+public class TButton extends JButton{
+ public TButton(String text) {
+ super(text);
+ super.setContentAreaFilled(false);
+ }
+
+ @Override
+ protected void paintComponent(Graphics g) {
+ Color temp = super.getBackground();
+ if (getModel().isPressed()) {
+ g.setColor(temp.darker().darker());
+ } else if (getModel().isRollover()) {
+ g.setColor(temp.darker());
+ } else {
+ g.setColor(temp);
+ }
+ g.fillRect(0, 0, getWidth(), getHeight());
+ super.paintComponent(g);
+ super.setBorderPainted(false);
+ }
+}
diff --git a/src/main/block.java b/src/main/block.java
new file mode 100644
index 0000000..cb04132
--- /dev/null
+++ b/src/main/block.java
@@ -0,0 +1,85 @@
+package main;
+
+import java.awt.Dimension;
+import java.awt.EventQueue;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.geom.Path2D;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.UIManager;
+import javax.swing.UnsupportedLookAndFeelException;
+
+//
+
+public class block {
+
+ public static void main(String[] args) {
+ new block();
+ }
+
+ public block() {
+ EventQueue.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ /*try {
+ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+ } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
+ ex.printStackTrace();
+ }
+ */
+
+ JFrame frame = new JFrame("Testing");
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.add(new TestPane());
+ frame.pack();
+ frame.setLocationRelativeTo(null);
+ frame.setVisible(true);
+
+ }
+ });
+ }
+
+ public class TestPane extends JPanel {
+
+ private RightEnd rightEnd;
+
+ public TestPane() {
+ rightEnd = new RightEnd(100, 100, 40);
+ }
+
+ @Override
+ public Dimension getPreferredSize() {
+ return new Dimension(100, 100);
+ }
+
+
+ @Override
+ protected void paintComponent(Graphics g) {
+ super.paintComponent(g);
+ int x = (getWidth() - 100) / 2;
+ int y = (getHeight()- 100) / 2;
+ Graphics2D g2d = (Graphics2D) g.create();
+ g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ g2d.translate(x, y);
+ g2d.fill(rightEnd);
+ g2d.dispose();
+ }
+
+
+ }
+
+ public class RightEnd extends Path2D.Float {
+
+ public RightEnd(float width, float height, float radius) {
+ moveTo(0, 0);
+ lineTo(width - radius, 0);
+ curveTo(width, 0, width, 0, width, radius);
+ lineTo(width, height - radius);
+ curveTo(width, height, width, height, width - radius, height);
+ lineTo(0, height);
+ closePath();
+ }
+ }
+}
diff --git a/src/main/jfxTest.java b/src/main/jfxTest.java
new file mode 100644
index 0000000..9552946
--- /dev/null
+++ b/src/main/jfxTest.java
@@ -0,0 +1,35 @@
+package main;
+
+import javafx.application.Application;
+import javafx.event.ActionEvent;
+import javafx.event.EventHandler;
+import javafx.scene.Scene;
+import javafx.scene.control.Button;
+import javafx.scene.layout.StackPane;
+import javafx.stage.Stage;
+
+public class jfxTest extends Application {
+ public static void main(String[] args) {
+ launch(args);
+ }
+
+ @Override
+ public void start(Stage primaryStage) {
+ primaryStage.setTitle("Hello World!");
+ Button btn = new Button();
+ btn.setText("Say 'Hello World'");
+ btn.setOnAction(new EventHandler<ActionEvent>() {
+
+ @Override
+ public void handle(ActionEvent event) {
+ System.out.println("Hello World!");
+ }
+ });
+
+ StackPane root = new StackPane();
+ root.getChildren().add(btn);
+ primaryStage.setScene(new Scene(root, 300, 250));
+ primaryStage.show();
+
+ }
+} \ No newline at end of file
diff --git a/src/main/shadowtest.java b/src/main/shadowtest.java
new file mode 100644
index 0000000..e24ae36
--- /dev/null
+++ b/src/main/shadowtest.java
@@ -0,0 +1,40 @@
+package main;
+import javafx.scene.effect.DropShadow;
+import javafx.scene.paint.Color;
+import javafx.scene.shape.Circle;
+import javafx.scene.text.Font;
+import javafx.scene.text.FontWeight;
+import javafx.scene.text.Text;
+
+public class shadowtest
+{
+ public shadowtest()
+ {
+ DropShadow dropShadow = new DropShadow();
+ dropShadow.setRadius(5.0);
+ dropShadow.setOffsetX(3.0);
+ dropShadow.setOffsetY(3.0);
+ dropShadow.setColor(Color.color(0.4, 0.5, 0.5));
+
+ Text text = new Text();
+ text.setEffect(dropShadow);
+ text.setCache(true);
+ text.setX(10.0);
+ text.setY(70.0);
+ text.setFill(Color.web("0x3b596d"));
+ text.setText("JavaFX drop shadow...");
+ text.setFont(Font.font(null, FontWeight.BOLD, 40));
+
+ DropShadow dropShadow2 = new DropShadow();
+ dropShadow2.setOffsetX(6.0);
+ dropShadow2.setOffsetY(4.0);
+
+ Circle circle = new Circle();
+ circle.setEffect(dropShadow2);
+ circle.setCenterX(50.0);
+ circle.setCenterY(125.0);
+ circle.setRadius(30.0);
+ circle.setFill(Color.STEELBLUE);
+ circle.setCache(true);
+ }
+} \ No newline at end of file