Hi nochmal.
Habe nun noch die Sourcen der meiner Meinung nach wichtigsten Klassen mit aufgeführt. Ich hoffe es hilft euch und somit vielleicht auch mir weiter.
------------------- Fenster - Klasse -------------------------------
-------------------------------------------------------------------
package sl;
import javax.swing.*;
import java.text.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Menu;
public class Fenster
extends JFrame
implements ActionListener
{
private MainPanel mainPanel = new MainPanel ();
// Menüpunkte in der Leiste
private JMenu dateiMenu = createJMenu("Datei", 'D'); //Menü-Punkt
private JMenu bearbeitenMenu = createJMenu("Bearbeiten",'B');
private JMenu hilfeMenu = createJMenu("?", 'H');
// Menüpunkt im Menüpunkt
private JMenu vorhanden = new JMenu("Vorhandenen Satz");
// Menü - Leiste
private JMenuBar menuBar = new JMenuBar();
// die einzelnen Menüpunkte
private JMenuItem oeffnen = addJMenuItem(dateiMenu, "Öffnen", 'Ö', 'Ö');
private JMenuItem schliessen = addJMenuItem(dateiMenu, "Schließen", 'S', 'S');
private JMenuItem beenden = addJMenuItem(dateiMenu, "Beenden", 'B', 'B');
private JMenuItem neuanlegen = new JMenuItem("Satz anlegen");
private JMenuItem loeschen = new JMenuItem("Satz löschen");
private JMenuItem bearbeiten = new JMenuItem("Satz bearbeiten");
private JMenuItem hilfe = new JMenuItem("Hilfe");
// Konstruktoren
public Fenster()
{
super("Bearbeitungs - Fenster");
this.createComponentTree();
this.Reaktions();
}
public void createComponentTree()
{
//Menü - Leiste erstellen \ Menüpunkte hinzufügen
this.menuBar.add(dateiMenu);
this.menuBar.add(bearbeitenMenu);
this.menuBar.add(hilfeMenu);
this.dateiMenu.add(oeffnen);
this.dateiMenu.add(schliessen);
this.dateiMenu.add(beenden);
// dem Menüpunkt 2 weitere Menüpunkte hinzufügen
this.bearbeitenMenu.add(neuanlegen);
this.bearbeitenMenu.add(vorhanden);
this.vorhanden.add(bearbeiten);
this.vorhanden.add(loeschen);
this.hilfeMenu.add(hilfe);
// Buttons hinzufügen
this.getContentPane().setLayout(new GridLayout ());
this.getContentPane().add (this.mainPanel);
this.setJMenuBar(menuBar);
}
public void actionPerformed(ActionEvent event)
{
System.out.println(event.getActionCommand());
}
private JMenu createJMenu(String label, char mnemonic)
{
JMenu jm = new JMenu(label);
jm.setMnemonic(mnemonic);
return jm;
}
private JMenuItem addJMenuItem(JMenu jm, String label, char mnemonic, char acc)
{
JMenuItem jmi = new JMenuItem(label, mnemonic);
setCtrlAccelerator(jmi, acc);
jmi.addActionListener(this);
jm.add(jmi);
return jmi;
}
private void setCtrlAccelerator(JMenuItem jmi, char c)
{
KeyStroke ks = KeyStroke.getKeyStroke(c, Event.CTRL_MASK);
}
public void Reaktions()
{
// Fenster wird geschlossen, wenn "X" gedrückt wird
this.addWindowListener (new WindowAdapter ()
{
public void windowClosing (WindowEvent e)
{
System.exit (0);
}
});
/* this.oeffnen.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println("oeffnen");
}
});
this.schliessen.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println("schliessen");
}
});
this.beenden.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println("Programm beenden");
System.exit (0);
}
});*/
this.neuanlegen.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println("Satz anlegen");
}
});
this.loeschen.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println("loeschen");
}
});
this.bearbeiten.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println("bearbeiten");
}
});
this.hilfe.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println("hilfe");
}
});
}
}
-------------------------------------------------------------------
------------------- MainPanel - Klasse -----------------------------
-------------------------------------------------------------------package sl;
import java.awt.*;
import javax.swing.*;
import java.text.*;
import java.awt.event.*;
public class MainPanel extends JPanel
{
// Menü - Elemente
private JButton add = new JButton("Satz anlegen");
private JButton del = new JButton("Entfernen");
private JButton change = new JButton("Bearbeiten");
private JButton view = new JButton("Ansehen");
private JButton hinzu = new JButton("Person hinzufügen");
private JButton cancel = new JButton("Hinzufügen abbrechen");
private JTextField vornameTF = new JTextField(15); // Textfelder
private JTextField nameTF = new JTextField(15);
// private Verdaechtiger [] v = new Verdaechtiger [10];
private VerdaechtigerSet set = new VerdaechtigerSet();
//private String [] model = {"Franz Peter"};
private JList liste = new JList(set);
//private DefaultListModel listModel = new DefaultListModel();
// Labels
private JLabel vname = new JLabel("Vorname");
private JLabel nname = new JLabel("Nachname");
// Panels
private Panel p1 = new Panel();
private Panel p2 = new Panel();
public MainPanel()
{
this.createComponentTree();
this.registerListeners();
try {
//jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
this.set.fillTestData();
}
public void createComponentTree()
{
this.setLayout(new GridLayout(1,2));
this.add(p1);
this.add(p2);
this.p1.setLayout(new BorderLayout());
this.p1.add(this.liste, BorderLayout.CENTER);
this.liste.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
this.liste.setVisibleRowCount(5);
this.liste.setModel(this.set);
this.p2.setLayout(new GridLayout(5,2,5,5));
this.p2.add(add);
this.p2.add(del);
this.p2.add(change);
this.p2.add(view);
this.p2.add(vname);
this.p2.add(nname);
this.p2.add(vornameTF);
this.p2.add(nameTF);
setunVis();
this.p2.add(hinzu);
this.p2.add(cancel);
}
public void registerListeners()
{
this.hinzu.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if (vornameTF.getText().length() > 0 && nameTF.getText().length() > 0 )
{
ListModel lm = liste.getModel();
//liste.setModel(lm);
//Verdaechtiger v = new Verdaechtiger(nameTF.getText(), vornameTF.getText());
//liste.addElement(v);
setunVis();
}
else
{
JOptionPane.showConfirmDialog(null,"Zum Anlegen einer neuen Person bitte Vor - und Nachnamen angeben. Mit der Abbruch - Taste kann die Erfassung abgebrochen werden.","Fehler",JOptionPane.YES_NO_CANCEL_OPTION);
//warnung();
}
}
});
this.add.addActionListener(new ActionListener ()
{
public void actionPerformed(ActionEvent e)
{
setVis();
}
});
this.del.addActionListener(new ActionListener ()
{
public void actionPerformed(ActionEvent e)
{
//String [] s = liste.getSelectedValue();
//for(int i=0;i<s.length;i++)
//{
// liste.remove(s);
//}
}
});
this.cancel.addActionListener(new ActionListener ()
{
public void actionPerformed(ActionEvent e)
{
setunVis();
}
});
}
public void clrTxf()
{
vornameTF.setText("");
nameTF.setText("");
}
public void setVis()
{
vornameTF.setVisible(true);
nameTF.setVisible(true);
hinzu.setVisible(true);
cancel.setVisible(true);
vname.setVisible(true);
nname.setVisible(true);
clrTxf();
}
public void setunVis()
{
vornameTF.setVisible(false);
nameTF.setVisible(false);
hinzu.setVisible(false);
cancel.setVisible(false);
vname.setVisible(false);
nname.setVisible(false);
}
}