Include a sound for capturing image and a button
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
84a3ce417c
commit
12d186a378
BIN
bin/screenshot.png
Normal file
BIN
bin/screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 246 KiB |
BIN
screenshot.png
Normal file
BIN
screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 210 KiB |
10
scripts/md5
10
scripts/md5
@ -1,5 +1,5 @@
|
|||||||
build.sh:a833e7598ad65672a9c01306d244b49f -
|
build.sh:de32fdf9f3ce9eb5d4ea9902ee48dbe0 *-
|
||||||
clean.sh:96ce35f2d2dcb555421e00a6afda23ca -
|
clean.sh:8aec15e447257f1c3a4e978f1b56a78e *-
|
||||||
commit.sh:21af1fa6f09d01679c9e11408967264a -
|
commit.sh:a592fe2113538f8cf933907eeda13ddc *-
|
||||||
jar.sh:2ac636f584c43a1124affb9ea6bdc7bf -
|
jar.sh:58c4f48f7e34425e55358a165a81c03b *-
|
||||||
lean.sh:3be7b8b182ccd96e48989b4e57311193 -
|
lean.sh:3be7b8b182ccd96e48989b4e57311193 *-
|
||||||
|
@ -7,9 +7,17 @@ import java.awt.AWTException;
|
|||||||
import java.awt.GraphicsEnvironment;
|
import java.awt.GraphicsEnvironment;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.sound.sampled.AudioInputStream;
|
||||||
|
import javax.sound.sampled.AudioSystem;
|
||||||
|
import javax.sound.sampled.Clip;
|
||||||
|
import javax.swing.JButton;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
|
||||||
import java.awt.Robot;
|
import java.awt.Robot;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
import sig.engine.Panel;
|
import sig.engine.Panel;
|
||||||
|
|
||||||
public class ArcadeScreenshotHandler {
|
public class ArcadeScreenshotHandler {
|
||||||
@ -17,26 +25,53 @@ public class ArcadeScreenshotHandler {
|
|||||||
public static final String PROGRAM_NAME="Sig's Java Project Template";
|
public static final String PROGRAM_NAME="Sig's Java Project Template";
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
JFrame f = new JFrame(PROGRAM_NAME);
|
JFrame f = new JFrame(PROGRAM_NAME);
|
||||||
Panel p = new Panel(f);
|
JButton button = new JButton("Capture");
|
||||||
|
|
||||||
|
JLabel text = new JLabel("");
|
||||||
|
|
||||||
p.init();
|
button.addActionListener(new ActionListener(){
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
System.out.println(e.getActionCommand());
|
||||||
|
BufferedImage img;
|
||||||
|
try {
|
||||||
|
img = CaptureScreen();
|
||||||
|
ImageIO.write(img,"png",Path.of("..","screenshot.png").toFile());
|
||||||
|
} catch (IOException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
playSound(Path.of("..","ding.wav"));
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
f.add(p);
|
f.add(button);
|
||||||
f.setSize(1280,720);
|
//f.add(text);
|
||||||
|
f.pack();
|
||||||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
f.setVisible(true);
|
f.setVisible(true);
|
||||||
|
|
||||||
p.render();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
r = new Robot();
|
r = new Robot();
|
||||||
BufferedImage img = CaptureScreen();
|
} catch (AWTException e) {
|
||||||
ImageIO.write(img,"png",Path.of("screenshot.png").toFile());
|
|
||||||
} catch (AWTException | IOException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void playSound(Path file) {
|
||||||
|
try {
|
||||||
|
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file.toFile());
|
||||||
|
Clip clip = AudioSystem.getClip();
|
||||||
|
clip.open(audioInputStream);
|
||||||
|
clip.start();
|
||||||
|
// If you want the sound to loop infinitely, then put: clip.loop(Clip.LOOP_CONTINUOUSLY);
|
||||||
|
// If you want to stop the sound, then use clip.stop();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static BufferedImage CaptureScreen() throws IOException {
|
private static BufferedImage CaptureScreen() throws IOException {
|
||||||
BufferedImage screenshot = r.createScreenCapture(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds());
|
BufferedImage screenshot = r.createScreenCapture(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds());
|
||||||
//ImageIO.write(screenshot,"png",new File("screenshot.png"));
|
//ImageIO.write(screenshot,"png",new File("screenshot.png"));
|
||||||
|
@ -108,33 +108,6 @@ public class Panel extends JPanel implements Runnable {
|
|||||||
p[y*width+x]=(0<<16)+(0<<8)+0;
|
p[y*width+x]=(0<<16)+(0<<8)+0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
x_offset+=1;
|
|
||||||
y_offset=50;
|
|
||||||
|
|
||||||
FillPolygon(p,Color.WHITE,50,50,new Point[] {
|
|
||||||
new Point(135,2),
|
|
||||||
new Point(166,96),
|
|
||||||
new Point(265,97),
|
|
||||||
new Point(185,156),
|
|
||||||
new Point(215,251),
|
|
||||||
new Point(134,192),
|
|
||||||
new Point(54,251),
|
|
||||||
new Point(84,156),
|
|
||||||
new Point(4,97),
|
|
||||||
new Point(103,96),
|
|
||||||
});
|
|
||||||
FillPolygon(p,Color.BRIGHT_CYAN,x_offset,y_offset,new Point[] {
|
|
||||||
new Point(28,29),
|
|
||||||
new Point(78,103),
|
|
||||||
new Point(120,31),
|
|
||||||
new Point(123,221),
|
|
||||||
new Point(30,218),
|
|
||||||
});
|
|
||||||
//FillRect(p,Color.BRIGHT_RED,200,200,600,64);
|
|
||||||
final Color testAlpha = new Color(150,0,0,128);
|
|
||||||
FillCircle(p,testAlpha,150,150,100);
|
|
||||||
FillOval(p,Color.BRIGHT_GREEN,300,150,100,50);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FillRect(int[] p,Color col,double x,double y,double w,double h) {
|
public void FillRect(int[] p,Color col,double x,double y,double w,double h) {
|
||||||
|
10
utils/md5
10
utils/md5
@ -1,5 +1,5 @@
|
|||||||
.coauthors:3785ad38663e5fc43e574914ad067294 -
|
.coauthors:3785ad38663e5fc43e574914ad067294 *-
|
||||||
define.sh:d6b20a25a04a60d94f466e48fa60ac69 -
|
.updateDirectories:0ede00461e947494545e694040787b3f *-
|
||||||
main.sh:32a1f953ffca8584d1eb57c0ecd8a582 -
|
define.sh:d6b20a25a04a60d94f466e48fa60ac69 *-
|
||||||
search.sh:28d0ede8345514d80cc68cc756870002 -
|
main.sh:32a1f953ffca8584d1eb57c0ecd8a582 *-
|
||||||
.updateDirectories:0ede00461e947494545e694040787b3f -
|
search.sh:6eec52214a36f2114442c41ab9c04f72 *-
|
||||||
|
@ -37,6 +37,7 @@ function check() {
|
|||||||
if [ "$g" != "md5" ]; then
|
if [ "$g" != "md5" ]; then
|
||||||
if [ -f $1$g ];
|
if [ -f $1$g ];
|
||||||
then
|
then
|
||||||
|
if [ "$g" != ".coauthors" ]; then
|
||||||
echo "++Redownload $1$g..."
|
echo "++Redownload $1$g..."
|
||||||
if [ -f "$1$g" ]; then
|
if [ -f "$1$g" ]; then
|
||||||
#Read the 2nd line and see if it has a special directory.
|
#Read the 2nd line and see if it has a special directory.
|
||||||
@ -58,6 +59,7 @@ function check() {
|
|||||||
echo "===Could not find directory, assuming regular scripts directory exists."
|
echo "===Could not find directory, assuming regular scripts directory exists."
|
||||||
curl -H 'Cache-Control: no-cache, no-store' https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1$g --output scripts/$g
|
curl -H 'Cache-Control: no-cache, no-store' https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1$g --output scripts/$g
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "++==Downloading $1$g..."
|
echo "++==Downloading $1$g..."
|
||||||
curl -H 'Cache-Control: no-cache, no-store' https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1$g --output $1$g
|
curl -H 'Cache-Control: no-cache, no-store' https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1$g --output $1$g
|
||||||
@ -74,4 +76,4 @@ function check() {
|
|||||||
check $1$g/
|
check $1$g/
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user