diff options
| author | sowgro <tpoke.ferrari@gmail.com> | 2023-05-06 14:56:46 -0400 | 
|---|---|---|
| committer | sowgro <tpoke.ferrari@gmail.com> | 2023-05-06 14:56:46 -0400 | 
| commit | 372d97fee538f86c8333fbbde43cf51484b8ac67 (patch) | |
| tree | 055f5560e58d4a83a90a3e1c46ec8d998e12a96f /apcs | |
| parent | cee3ca3fec021c0ddf8f3ee66940bb1cdfba4262 (diff) | |
| download | NPEhero-372d97fee538f86c8333fbbde43cf51484b8ac67.tar.gz NPEhero-372d97fee538f86c8333fbbde43cf51484b8ac67.tar.bz2 NPEhero-372d97fee538f86c8333fbbde43cf51484b8ac67.zip  | |
Add JavaFX and seperate source and class files
Diffstat (limited to 'apcs')
| -rw-r--r-- | apcs/Driver.java | 18 | ||||
| -rw-r--r-- | apcs/Gui.java | 41 | ||||
| -rw-r--r-- | apcs/KeyDetection.java | 27 | ||||
| -rw-r--r-- | apcs/NoteTest.java | 35 | ||||
| -rw-r--r-- | apcs/RoundedRectangleTest.java | 91 | ||||
| -rw-r--r-- | apcs/ShortAudioFilePlayer.java | 96 | ||||
| -rw-r--r-- | apcs/SongPlayer.java | 97 | ||||
| -rw-r--r-- | apcs/TButton.java | 30 | ||||
| -rw-r--r-- | apcs/block.java | 86 | ||||
| -rw-r--r-- | apcs/shadowtest.java | 26 | 
10 files changed, 0 insertions, 547 deletions
diff --git a/apcs/Driver.java b/apcs/Driver.java deleted file mode 100644 index 7b053e4..0000000 --- a/apcs/Driver.java +++ /dev/null @@ -1,18 +0,0 @@ -/*Name:	 - *Date: - *Period: - *Teacher: - *Description: - */ -package apcs; - - -public class Driver -{ - -    public static void main(String[] args) -    { -        new RoundedRectangleTest(); -    } - -} diff --git a/apcs/Gui.java b/apcs/Gui.java deleted file mode 100644 index 934c371..0000000 --- a/apcs/Gui.java +++ /dev/null @@ -1,41 +0,0 @@ -/*Name:	 - *Date: - *Period: - *Teacher: - *Description: - */ -package apcs; - -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/apcs/KeyDetection.java b/apcs/KeyDetection.java deleted file mode 100644 index 9fc9db6..0000000 --- a/apcs/KeyDetection.java +++ /dev/null @@ -1,27 +0,0 @@ -/*Name:	 - *Date: - *Period: - *Teacher: - *Description: - */ -package apcs; - -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/apcs/NoteTest.java b/apcs/NoteTest.java deleted file mode 100644 index 310325b..0000000 --- a/apcs/NoteTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/*Name:	 - *Date: - *Period: - *Teacher: - *Description: - */ -package apcs; -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/apcs/RoundedRectangleTest.java b/apcs/RoundedRectangleTest.java deleted file mode 100644 index c24772c..0000000 --- a/apcs/RoundedRectangleTest.java +++ /dev/null @@ -1,91 +0,0 @@ -package apcs; - -import java.awt.*; -import java.awt.event.*; -import java.awt.geom.AffineTransform; -import java.awt.geom.RoundRectangle2D; - -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/apcs/ShortAudioFilePlayer.java b/apcs/ShortAudioFilePlayer.java deleted file mode 100644 index 0a03c9c..0000000 --- a/apcs/ShortAudioFilePlayer.java +++ /dev/null @@ -1,96 +0,0 @@ -package apcs; -//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/apcs/SongPlayer.java b/apcs/SongPlayer.java deleted file mode 100644 index 686bc7c..0000000 --- a/apcs/SongPlayer.java +++ /dev/null @@ -1,97 +0,0 @@ -/*Name:	 - *Date: - *Period: - *Teacher: - *Description: - */ -package apcs; - -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/apcs/TButton.java b/apcs/TButton.java deleted file mode 100644 index 7583726..0000000 --- a/apcs/TButton.java +++ /dev/null @@ -1,30 +0,0 @@ -package apcs; - -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/apcs/block.java b/apcs/block.java deleted file mode 100644 index 97dbf75..0000000 --- a/apcs/block.java +++ /dev/null @@ -1,86 +0,0 @@ -package apcs; - -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; -import javafx.scene.effect.DropShadow; - -// - -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/apcs/shadowtest.java b/apcs/shadowtest.java deleted file mode 100644 index b6acba5..0000000 --- a/apcs/shadowtest.java +++ /dev/null @@ -1,26 +0,0 @@ -package apcs; - -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.Graphics2D; - -import java.awt.Shape; - -import java.awt.geom.AffineTransform; - -public class shadowtest { -    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 = 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  | 
