diff --git a/Vokabeln.txt b/Vokabeln.txt index 1ae74ea..acf34a1 100644 --- a/Vokabeln.txt +++ b/Vokabeln.txt @@ -11,3 +11,31 @@ decision Entscheidung chef Koch +childcare assistant +Kinderpfleger +mechanic +Mechaniker +garage +Autowerkstatt +customer adviser +Kundenbetreuer +advise +beraten +advice +Rat +make-up artist +Maskenbildner +fitness instructor +lange arbeiten +serve +bedienen +repair +reparieren +sporty +sportlich +artistic +kuenstlerisch +organized +organisiert +calm +ruhig diff --git a/src/readandwrite/read.java b/src/readandwrite/read.java index 5d1d743..0cd592b 100644 --- a/src/readandwrite/read.java +++ b/src/readandwrite/read.java @@ -20,6 +20,7 @@ public class read { while ((zeile = br.readLine()) != null) { GUI.vokabeln0.add(zeile); } + br.close(); } } } diff --git a/src/readandwrite/readandremove.java b/src/readandwrite/readandremove.java new file mode 100644 index 0000000..401e03b --- /dev/null +++ b/src/readandwrite/readandremove.java @@ -0,0 +1,30 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package readandwrite; + +/** + * + * @author simono41 + */ +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import vokabeltrainer.Vokabeln; + +public class readandremove { + public void read() throws FileNotFoundException, IOException { + String zeile; + FileReader fr = new FileReader("./Vokabeln.old.txt"); + try (BufferedReader br = new BufferedReader(fr)) { + br.readLine(); + while ((zeile = br.readLine()) != null) { + Vokabeln.vokabeln0.add(zeile); + } + br.close(); + } + } +} \ No newline at end of file diff --git a/src/readandwrite/remove.java b/src/readandwrite/remove.java new file mode 100644 index 0000000..44f9de0 --- /dev/null +++ b/src/readandwrite/remove.java @@ -0,0 +1,26 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package readandwrite; + +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import vokabeltrainer.Vokabeln; + +public class remove { + public void write() throws IOException { + FileWriter fw = new FileWriter("./Vokabeln.old.txt"); + try (BufferedWriter bw = new BufferedWriter(fw)) { + bw.write("Vokabelnold:"); + bw.newLine(); + for (String str : Vokabeln.vokabeln0) { + bw.write(str); + bw.newLine(); + } + bw.close(); + } + } +} diff --git a/src/readandwrite/write.java b/src/readandwrite/write.java index d3a4712..b3b6119 100644 --- a/src/readandwrite/write.java +++ b/src/readandwrite/write.java @@ -20,6 +20,7 @@ public class write { bw.write(str); bw.newLine(); } + bw.close(); } } } diff --git a/src/vokabeltrainer/GUI.form b/src/vokabeltrainer/GUI.form index 6d7e2de..859a409 100644 --- a/src/vokabeltrainer/GUI.form +++ b/src/vokabeltrainer/GUI.form @@ -1,10 +1,37 @@
+ + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -108,7 +135,7 @@ - + diff --git a/src/vokabeltrainer/GUI.java b/src/vokabeltrainer/GUI.java index 0730102..bc7a37c 100644 --- a/src/vokabeltrainer/GUI.java +++ b/src/vokabeltrainer/GUI.java @@ -5,14 +5,12 @@ */ package vokabeltrainer; +import java.awt.event.KeyEvent; import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JTextField; import readandwrite.read; import readandwrite.write; @@ -61,6 +59,10 @@ public class GUI extends javax.swing.JFrame { jLabel9 = new javax.swing.JLabel(); jLabel10 = new javax.swing.JLabel(); jButton5 = new javax.swing.JButton(); + jMenuBar1 = new javax.swing.JMenuBar(); + jMenu1 = new javax.swing.JMenu(); + jMenuItem1 = new javax.swing.JMenuItem(); + jMenu2 = new javax.swing.JMenu(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); @@ -128,6 +130,23 @@ public class GUI extends javax.swing.JFrame { } }); + jMenu1.setText("File"); + + jMenuItem1.setText("EXIT"); + jMenuItem1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jMenuItem1ActionPerformed(evt); + } + }); + jMenu1.add(jMenuItem1); + + jMenuBar1.add(jMenu1); + + jMenu2.setText("Edit"); + jMenuBar1.add(jMenu2); + + setJMenuBar(jMenuBar1); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( @@ -200,7 +219,7 @@ public class GUI extends javax.swing.JFrame { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel7) .addComponent(jLabel8))) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 38, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton4) .addComponent(jButton5)) @@ -217,10 +236,14 @@ public class GUI extends javax.swing.JFrame { private void jTextField2KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField2KeyPressed // TODO add your handling code here: - if (evt.getKeyCode() == 10) { + if (evt.getKeyCode() == KeyEvent.VK_ENTER) { System.out.println("ENTER"); this.eingabe(); } + if (evt.getKeyCode() == KeyEvent.VK_ALT) { + System.out.println("Neue Vokabel"); + this.vokabel(); + } }//GEN-LAST:event_jTextField2KeyPressed private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed @@ -248,6 +271,11 @@ public class GUI extends javax.swing.JFrame { this.aktualisieren(); }//GEN-LAST:event_jButton5ActionPerformed + private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed + // TODO add your handling code here: + System.exit(0); + }//GEN-LAST:event_jMenuItem1ActionPerformed + private void vokabeln() { new Vokabeln().setVisible(true); } @@ -337,6 +365,10 @@ public class GUI extends javax.swing.JFrame { private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; + private javax.swing.JMenu jMenu1; + private javax.swing.JMenu jMenu2; + private javax.swing.JMenuBar jMenuBar1; + private javax.swing.JMenuItem jMenuItem1; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField2; // End of variables declaration//GEN-END:variables diff --git a/src/vokabeltrainer/Vokabeln.form b/src/vokabeltrainer/Vokabeln.form index 7ba1675..c9fbd02 100644 --- a/src/vokabeltrainer/Vokabeln.form +++ b/src/vokabeltrainer/Vokabeln.form @@ -26,8 +26,12 @@ - - + + + + + + @@ -39,7 +43,10 @@ - + + + + @@ -73,5 +80,13 @@ + + + + + + + +
diff --git a/src/vokabeltrainer/Vokabeln.java b/src/vokabeltrainer/Vokabeln.java index 5c8f4b8..1a748c3 100644 --- a/src/vokabeltrainer/Vokabeln.java +++ b/src/vokabeltrainer/Vokabeln.java @@ -6,7 +6,15 @@ package vokabeltrainer; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.swing.DefaultListModel; +import readandwrite.readandremove; +import readandwrite.remove; +import readandwrite.write; /** * @@ -14,6 +22,9 @@ import javax.swing.DefaultListModel; */ public class Vokabeln extends javax.swing.JFrame { + private int position; + public static ArrayList vokabeln0 = new ArrayList(); + /** Creates new form Vokabeln */ public Vokabeln() { initComponents(); @@ -31,6 +42,7 @@ public class Vokabeln extends javax.swing.JFrame { jScrollPane1 = new javax.swing.JScrollPane(); jList1 = new javax.swing.JList<>(); jButton1 = new javax.swing.JButton(); + jButton2 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); @@ -43,6 +55,13 @@ public class Vokabeln extends javax.swing.JFrame { } }); + jButton2.setText("Remove"); + jButton2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton2ActionPerformed(evt); + } + }); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( @@ -50,8 +69,11 @@ public class Vokabeln extends javax.swing.JFrame { .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE) - .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE)) + .addComponent(jScrollPane1)) .addContainerGap()) ); layout.setVerticalGroup( @@ -60,7 +82,9 @@ public class Vokabeln extends javax.swing.JFrame { .addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE) - .addComponent(jButton1) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jButton1) + .addComponent(jButton2)) .addContainerGap()) ); @@ -72,6 +96,54 @@ public class Vokabeln extends javax.swing.JFrame { this.aktualisieren(); }//GEN-LAST:event_jButton1ActionPerformed + private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed + // TODO add your handling code here: + this.entfernen(); + }//GEN-LAST:event_jButton2ActionPerformed + + public void entfernen() { + position = jList1.getSelectedIndex(); + + System.out.println("Ausgewählt = " + jList1.getSelectedValue()); + System.out.println("Ausgewählt = " + position); + + System.out.println(GUI.vokabeln0.get(position * 2)); + + readandremove d = new readandremove(); + + vokabeln0.clear(); + try { + d.read(); + } catch (FileNotFoundException ex) { + System.out.println("Datei wird neu Angelegt!"); + } catch (IOException ex) { + Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex); + } + + vokabeln0.add(GUI.vokabeln0.get(position * 2)); + vokabeln0.add(GUI.vokabeln0.get(position * 2 + 1)); + + remove c = new remove(); + try { + c.write(); + } catch (IOException ex) { + Logger.getLogger(Vokabeln.class.getName()).log(Level.SEVERE, null, ex); + } + + GUI.vokabeln0.remove(position * 2); + GUI.vokabeln0.remove(position * 2); + + + this.aktualisieren(); + write b = new write(); + try { + b.write(); + } catch (IOException ex) { + Logger.getLogger(Vokabeln.class.getName()).log(Level.SEVERE, null, ex); + } + GUI a = new GUI(); + a.aktualisieren(); + } public void aktualisieren() { DefaultListModel dim = new DefaultListModel<>(); for (int i = 0; i < GUI.vokabeln0.size();) { @@ -81,6 +153,7 @@ public class Vokabeln extends javax.swing.JFrame { } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; + private javax.swing.JButton jButton2; private javax.swing.JList jList1; private javax.swing.JScrollPane jScrollPane1; // End of variables declaration//GEN-END:variables