commit a0152d60e1457ae2390c7d3a3961596d092f4955 Author: Seil0 Date: Sat Aug 13 14:39:28 2016 +0200 initial release diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..360e89f --- /dev/null +++ b/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..9e8da04 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + Bergerboard + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/JLayer.jar b/JLayer.jar new file mode 100644 index 0000000..bd5fb8b Binary files /dev/null and b/JLayer.jar differ diff --git a/bin/GUI$1.class b/bin/GUI$1.class new file mode 100644 index 0000000..8449168 Binary files /dev/null and b/bin/GUI$1.class differ diff --git a/bin/GUI$2.class b/bin/GUI$2.class new file mode 100644 index 0000000..259f18f Binary files /dev/null and b/bin/GUI$2.class differ diff --git a/bin/GUI$3.class b/bin/GUI$3.class new file mode 100644 index 0000000..beee1d2 Binary files /dev/null and b/bin/GUI$3.class differ diff --git a/bin/GUI$4.class b/bin/GUI$4.class new file mode 100644 index 0000000..78acebc Binary files /dev/null and b/bin/GUI$4.class differ diff --git a/bin/GUI$5.class b/bin/GUI$5.class new file mode 100644 index 0000000..d452ed4 Binary files /dev/null and b/bin/GUI$5.class differ diff --git a/bin/GUI$6.class b/bin/GUI$6.class new file mode 100644 index 0000000..099c2ff Binary files /dev/null and b/bin/GUI$6.class differ diff --git a/bin/GUI$7.class b/bin/GUI$7.class new file mode 100644 index 0000000..9e09aec Binary files /dev/null and b/bin/GUI$7.class differ diff --git a/bin/GUI$8.class b/bin/GUI$8.class new file mode 100644 index 0000000..eee45de Binary files /dev/null and b/bin/GUI$8.class differ diff --git a/bin/GUI$SoundJLayer.class b/bin/GUI$SoundJLayer.class new file mode 100644 index 0000000..3cbba04 Binary files /dev/null and b/bin/GUI$SoundJLayer.class differ diff --git a/bin/GUI.class b/bin/GUI.class new file mode 100644 index 0000000..3b32195 Binary files /dev/null and b/bin/GUI.class differ diff --git a/bin/Main.class b/bin/Main.class new file mode 100644 index 0000000..f495982 Binary files /dev/null and b/bin/Main.class differ diff --git a/bin/SoundJLayer.class b/bin/SoundJLayer.class new file mode 100644 index 0000000..8e2df24 Binary files /dev/null and b/bin/SoundJLayer.class differ diff --git a/bin/jaggob$1.class b/bin/jaggob$1.class new file mode 100644 index 0000000..b12525a Binary files /dev/null and b/bin/jaggob$1.class differ diff --git a/bin/jaggob$2.class b/bin/jaggob$2.class new file mode 100644 index 0000000..0137bd0 Binary files /dev/null and b/bin/jaggob$2.class differ diff --git a/bin/jaggob.class b/bin/jaggob.class new file mode 100644 index 0000000..28f526b Binary files /dev/null and b/bin/jaggob.class differ diff --git a/src/GUI.java b/src/GUI.java new file mode 100644 index 0000000..f50adaf --- /dev/null +++ b/src/GUI.java @@ -0,0 +1,395 @@ +/** + * Sir Berger Board + * + * Copyright 2016 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + */ + +import java.awt.Color; +import java.awt.Component; +import java.awt.Cursor; +import java.awt.EventQueue; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Properties; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.SwingConstants; +import javax.swing.border.EmptyBorder; + +import javazoom.jl.player.advanced.AdvancedPlayer; +import javazoom.jl.player.advanced.PlaybackEvent; +import javazoom.jl.player.advanced.PlaybackListener; + +public class GUI extends JFrame { + + private static final long serialVersionUID = 1L; + public boolean disable; + private int posX = 32; //startwert posX + private int posY = 80; //startwert posY + private int anzahlBtn = 0; + private int zY = 0; // zähler für posX + + ArrayList myButton = new ArrayList(); + ArrayList eventPath = new ArrayList(); + + Properties props = new Properties(); + + private JPanel contentPane; + private JTextField textField; + private JTextField textField_1; + + private jaggob derJaggob = new jaggob(); + + public static void main(String[] args) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + File file = new File("config.xml"); + GUI frame = new GUI(); + frame.setVisible(true); + if (file.exists() == true) { + frame.laden(); + } + } catch (Exception e) { + e.printStackTrace(); + } + + } + }); + } + + /** + * Create the frame. + */ + public GUI() { + setBackground(Color.DARK_GRAY); + setTitle("Sir Berger Board V0.3.5 alpha Kevin Edition"); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setBounds(100, 100, 1126, 702); + contentPane = new JPanel(); + contentPane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + contentPane.setBackground(Color.DARK_GRAY); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + setContentPane(contentPane); + contentPane.setLayout(null); + + JLabel label = new JLabel("Sir Berger Board"); + label.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + JOptionPane.showMessageDialog(null,"Sir Berger Board v0.3.5 \n Changelog: \n -automatisches speichern und laden \n der Buttons implementiert \n © 2016 Kellerkinder \n © 2016 Jaggob Edition by Seilo \n www.kellerkinder.xyz","Über",JOptionPane.INFORMATION_MESSAGE); + } + }); + label.setForeground(Color.WHITE); + label.setBackground(Color.WHITE); + label.setHorizontalAlignment(SwingConstants.CENTER); + label.setAlignmentX(Component.CENTER_ALIGNMENT); + label.setFont(new Font("Arial", Font.ITALIC, 77)); + label.setBounds(109, 24, 645, 84); + contentPane.add(label); + + JLabel lblKellerkinderSoftwareDevelopment = new JLabel(" © 2016 Kellerkinder"); + lblKellerkinderSoftwareDevelopment.setForeground(Color.BLUE); + lblKellerkinderSoftwareDevelopment.setFont(new Font("Arial", Font.ITALIC, 20)); + lblKellerkinderSoftwareDevelopment.setBounds(32, 626, 409, 37); + contentPane.add(lblKellerkinderSoftwareDevelopment); + + //öffnet Jaggob -> Problem mit der Übergabe von Name und Path + JButton btnOpenJaggob = new JButton("open Jaggob"); + btnOpenJaggob.setEnabled(false); + btnOpenJaggob.setFont(new Font("Arial", Font.PLAIN, 17)); + btnOpenJaggob.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + derJaggob.setVisible(true); + } + }); + btnOpenJaggob.setBounds(851, 110, 249, 23); + contentPane.add(btnOpenJaggob); + + //ruft gnButton auf + JButton btnNewButton = new JButton("new Button"); + btnNewButton.setFont(new Font("Arial", Font.PLAIN, 17)); + btnNewButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if(anzahlBtn == 40){ + JOptionPane.showMessageDialog(null, "Maximal Anzahl erreicht!", "Error", JOptionPane.ERROR_MESSAGE); + btnNewButton.setEnabled(false); + }else{ + gnButton(); + } + } + }); + btnNewButton.setBounds(851, 76, 249, 23); + contentPane.add(btnNewButton); + + textField = new JTextField(); + textField.setBounds(851, 14, 249, 20); + contentPane.add(textField); + textField.setColumns(10); + + JLabel lblNewLabel = new JLabel("Dateiname"); + lblNewLabel.setForeground(Color.WHITE); + lblNewLabel.setFont(new Font("Arial", Font.PLAIN, 14)); + lblNewLabel.setBounds(764, 17, 77, 17); + contentPane.add(lblNewLabel); + + JLabel lblNewLabel_1 = new JLabel("Buttonname"); + lblNewLabel_1.setForeground(Color.WHITE); + lblNewLabel_1.setFont(new Font("Arial", Font.PLAIN, 14)); + lblNewLabel_1.setBounds(764, 48, 77, 17); + contentPane.add(lblNewLabel_1); + + textField_1 = new JTextField(); + textField_1.setBounds(851, 45, 249, 20); + contentPane.add(textField_1); + textField_1.setColumns(10); + + JButton btnSave = new JButton("save"); + btnSave.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + speichern(); + } + }); + btnSave.setBounds(10, 24, 89, 23); + contentPane.add(btnSave); + + JButton btnLoad = new JButton("load"); + btnLoad.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + laden(); + } + }); + btnLoad.setBounds(10, 57, 89, 23); + contentPane.add(btnLoad); + + } + + /** + * generiert den Button und ActionListener,eventPath hinzufügen + */ + public void gnButton(){ + generatePos(); + eventPath.add(setPath()); //speicher den eingegebenen Pfad in der Array List + JButton button = new JButton(); + myButton.add(button); + button.setText(setName()); //setzte den Button Text auf Wert von setName() + contentPane.add(button); //fügt Butoon zur cPane hinzu + button.setFont(new Font("Arial", Font.PLAIN, 18)); //Schriftart und Größe + button.setBounds(getPosX(), getPosY(), 200, 50); //position (x, y(j+160), width, height) + button.setVisible(true); + button.addActionListener( //erstellt actionListener + new ActionListener(){ + public void actionPerformed(ActionEvent e){ + SoundJLayer soundToPlay = new SoundJLayer(eventPath.get(myButton.indexOf(e.getSource()))); + soundToPlay.play(); + } + } + ); + speichern(); + textField.setText(""); + textField_1.setText(""); + } + + private void generatePos(){ + if(zY == 8){ + posY = 140; //setzt posY zurück + posX = posX + 210; + zY = 1; + }else{ + posY = posY + 60; + zY++; + } + anzahlBtn++; + } + + private int getPosX(){ + return posX; + } + + private int getPosY(){ + return posY; + } + + private String setName(){ + String Name = textField_1.getText(); + return Name; + } + private String setPath() { + String path = textField.getText(); + return path; + } + + //wird für jaggob benötigt + public String getName(String Name){ + System.out.println("Name:" + Name); + return Name; + } +// + public String getPath(String Path){ + System.out.println("Pfad: " + Path); + return Path; + } + + /** + * speichert die Daten in xml + */ + public void speichern(){ + + File configFile = new File("config.xml"); //neue Datei "config.xml" + try { + String size = Integer.toString(myButton.size()); + props.setProperty("size", size); + + for(int i = 0; i < myButton.size(); i++){ + String btnName = "btnName"+i; + String datName = "datName"+i; + props.setProperty(btnName, myButton.get(i).getText()); //setzt pfad in propselement + props.setProperty(datName, eventPath.get(i)); + } + OutputStream outputStream = new FileOutputStream(configFile); //neuer outputstream + props.storeToXML(outputStream, "BergerBoard_Btn"); + outputStream.close(); + System.out.println("speichern erfolgreich"); + } catch (IOException e) { + System.out.println("beim speichern ist ein fehler aufgetreten!"); + e.printStackTrace(); + } + } + + /** + * läd die datei aus der xml + */ + public void laden(){ + + File configFile = new File("config.xml"); + try { + InputStream inputStream = new FileInputStream(configFile); + props.loadFromXML(inputStream); + int size = Integer.parseInt(props.getProperty("size")); + for(int i = 0; i < size; i++){ + String btnName = "btnName"+i; + String datName = "datName"+i; + + generatePos(); + eventPath.add(props.getProperty(datName)); //speicher den eingegebenen Pfad in der Array List + JButton button = new JButton(); + myButton.add(button); + button.setText(props.getProperty(btnName)); //setzte den Button Text auf Wert von setName() + contentPane.add(button); //fügt Butoon zur cPane hinzu + button.setFont(new Font("Arial", Font.PLAIN, 18)); //Schriftart und Größe + button.setBounds(getPosX(), getPosY(), 200, 50); //position (x, y(j+160), width, height) + button.setVisible(true); + button.addActionListener( //erstellt actionListener + new ActionListener(){ + public void actionPerformed(ActionEvent e){ + SoundJLayer soundToPlay = new SoundJLayer(eventPath.get(myButton.indexOf(e.getSource()))); + soundToPlay.play(); + } + } + ); + } + System.out.println("laden erfolgreich"); + inputStream.close(); + } catch (IOException e) { + System.out.println("beim laden ist ein Fehler aufgetreten!"); + e.printStackTrace(); + } + } + + class SoundJLayer extends PlaybackListener implements Runnable + { + private String filePath; + private AdvancedPlayer player; + private Thread playerThread; + + public SoundJLayer(String filePath) + { + this.filePath = filePath; + } + + public void play() + { + try + { + String urlAsString = + "file:///" + + new java.io.File(".").getCanonicalPath() + "/" + + this.filePath; + + this.player = new AdvancedPlayer + ( + new java.net.URL(urlAsString).openStream(), + javazoom.jl.player.FactoryRegistry.systemRegistry().createAudioDevice() + ); + + this.player.setPlayBackListener(this); + + this.playerThread = new Thread(this, "AudioPlayerThread"); + + this.playerThread.start(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + + // PlaybackListener members + + public void playbackStarted(PlaybackEvent playbackEvent) + { + System.out.println("playbackStarted"); + } + + public void playbackFinished(PlaybackEvent playbackEvent) + { + System.out.println("playbackEnded"); + } + + // Runnable members + + public void run() + { + try + { + this.player.play(); + } + catch (javazoom.jl.decoder.JavaLayerException ex) + { + ex.printStackTrace(); + } + + } + } +} diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..3415c6e --- /dev/null +++ b/src/Main.java @@ -0,0 +1,78 @@ + +import javazoom.jl.player.advanced.*; + +public class Main +{ + public static void main(String[] args) + { + SoundJLayer soundToPlay = new SoundJLayer("Clip01.mp3"); + + soundToPlay.play(); + } +} + +class SoundJLayer extends PlaybackListener implements Runnable +{ + private String filePath; + private AdvancedPlayer player; + private Thread playerThread; + + public SoundJLayer(String filePath) + { + this.filePath = filePath; + } + + public void play() + { + try + { + String urlAsString = + "file:///" + + new java.io.File(".").getCanonicalPath() + "/" + + this.filePath; + + this.player = new AdvancedPlayer + ( + new java.net.URL(urlAsString).openStream(), + javazoom.jl.player.FactoryRegistry.systemRegistry().createAudioDevice() + ); + + this.player.setPlayBackListener(this); + + this.playerThread = new Thread(this, "AudioPlayerThread"); + + this.playerThread.start(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + + // PlaybackListener members + + public void playbackStarted(PlaybackEvent playbackEvent) + { + System.out.println("playbackStarted"); + } + + public void playbackFinished(PlaybackEvent playbackEvent) + { + System.out.println("playbackEnded"); + } + + // Runnable members + + public void run() + { + try + { + this.player.play(); + } + catch (javazoom.jl.decoder.JavaLayerException ex) + { + ex.printStackTrace(); + } + + } +} \ No newline at end of file diff --git a/src/jaggob.java b/src/jaggob.java new file mode 100644 index 0000000..e7a95d6 --- /dev/null +++ b/src/jaggob.java @@ -0,0 +1,91 @@ +import java.awt.EventQueue; + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; +import javax.swing.JButton; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import javax.swing.JLabel; +import javax.swing.JTextField; + +@SuppressWarnings("serial") +public class jaggob extends JFrame { + + private JPanel contentPane; + private JTextField textField; + private JTextField textField_1; + private GUI dieGUI; + + /** + * Launch the application. + */ + public static void main(String[] args) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + jaggob frame = new jaggob(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + + /** + * Create the frame. + */ + public jaggob() { + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setBounds(100, 100, 450, 200); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + setContentPane(contentPane); + contentPane.setLayout(null); + + JButton btnNewButton = new JButton("OK"); + btnNewButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + dieGUI.getName(getName()); +// GUI.getPath(getPath()); + //GUI.gnButton(); // ->braucht noch arbeit + System.out.println(getPath()+" ,"+getName()); + zu(); + } + }); + btnNewButton.setBounds(10, 115, 414, 23); + contentPane.add(btnNewButton); + + JLabel lblNewLabel = new JLabel("Dateiname"); + lblNewLabel.setBounds(10, 11, 85, 17); + contentPane.add(lblNewLabel); + + JLabel lblNewLabel_1 = new JLabel("Buttonname"); + lblNewLabel_1.setBounds(10, 36, 85, 17); + contentPane.add(lblNewLabel_1); + + textField = new JTextField(); + textField.setBounds(119, 8, 305, 20); + contentPane.add(textField); + textField.setColumns(10); + + textField_1 = new JTextField(); + textField_1.setBounds(119, 34, 305, 20); + contentPane.add(textField_1); + textField_1.setColumns(10); + } + + public String getPath(){ + String path = textField.getText(); + return path; + } + + public String getName(){ + String name = textField_1.getText(); + return name; + } + public void zu(){ + this.setVisible(false); + } +}