Ich habe mich mal daran probiert eine einfache Musikdatenbank zu erstellen. Dazu habe ich mir eine GUI mit Suchfunktion zusammengebastelt, mit der ich aber auch neue Daten hinzufügen kann. Nun haben ich also bis zu einem gewissen Punkt alles programmiert, alle Fehler ausgemerzt und muss jetzt aber festestellen, dass es immer noch nicht so funktioniert, wie es soll.
Ich habe mir en Quelltext noch 3 mal angesehen, Zeile für Zeile, kann aber einfach nicht erkennen, woran es hapert. Ich habe im Internet gelesen, dass dieser Fehler auftritt, wenn ich zb. versuche, sowas wie "hallo welt" in einen Integer Wert umzuwandeln. Sowas kann ich bei mir jedoch nicht entdecken.
Ich bin kein studierter Informatiker, würde mich aber schon als fortgeschrittenen Java Benutzer bezeichen.
Ich hoffe daher auf Hilfe
Ich habe 3 Klasse geschrieben, die assoziativ miteinander verbunden sind.
Ich benutze den Java Editor. Mit dem habe ich auch die GUI zusammengebaut.
Hier der Code (dabei war ich mir nicht sicher ob ich den Quelltext der GUI auch posten soll. die wirklichen Probleme treten wahrscheinlich ab Zeile 202 auf ) :
Klasse CGUI:
Hier die 2. Klasse COrdner:
Und hier die 3. und letzte Klasse CSong:
Danke für die Hilfe schonmal im Vorraus.
Ich habe mir en Quelltext noch 3 mal angesehen, Zeile für Zeile, kann aber einfach nicht erkennen, woran es hapert. Ich habe im Internet gelesen, dass dieser Fehler auftritt, wenn ich zb. versuche, sowas wie "hallo welt" in einen Integer Wert umzuwandeln. Sowas kann ich bei mir jedoch nicht entdecken.
Ich bin kein studierter Informatiker, würde mich aber schon als fortgeschrittenen Java Benutzer bezeichen.
Ich hoffe daher auf Hilfe
Ich habe 3 Klasse geschrieben, die assoziativ miteinander verbunden sind.
Ich benutze den Java Editor. Mit dem habe ich auch die GUI zusammengebaut.
Hier der Code (dabei war ich mir nicht sicher ob ich den Quelltext der GUI auch posten soll. die wirklichen Probleme treten wahrscheinlich ab Zeile 202 auf ) :
Klasse CGUI:
Java:
public class CGUI extends JFrame
{
// Anfang Attribute
private JMenuBar toll = new JMenuBar();
private JTextField tF_Suchfeld = new JTextField();
private JButton bT_Suche = new JButton();
private JRadioButton rB_Titel = new JRadioButton();
private JRadioButton rB_Jahr = new JRadioButton();
private JRadioButton rB_Genre = new JRadioButton();
private JRadioButton rB_Album = new JRadioButton();
private JRadioButton rB_Preis = new JRadioButton();
private JRadioButton rB_Interpret = new JRadioButton();
private String[] jList1Data = {};
private JList l_DatenAusgabe = new JList(jList1Data);
private JButton bT_DatenHinzufuegen = new JButton();
private COrdner Ordner3;
private ButtonGroup jButtonGroup1 = new ButtonGroup();
private JTextField tF_Untergrenze = new JTextField();
private JTextField tF_Obergrenze = new JTextField();
private JLabel jL_Untergrenze = new JLabel();
private JLabel jL_Obergrenze = new JLabel();
private JLabel jL_Euro = new JLabel();
private JLabel jL_Euro2 = new JLabel();
private JTextField tF_EingabeTitel = new JTextField();
private JTextField tF_EingabeInterpret = new JTextField();
private JTextField tF_EingabeAlbum = new JTextField();
private JTextField tF_EingabeGenre = new JTextField();
private JTextField tF_EingabeJahr = new JTextField();
private JLabel Titel = new JLabel();
private JLabel Interpret = new JLabel();
private JLabel Album = new JLabel();
private JTextField tF_EingabePreis = new JTextField();
private JLabel Genre = new JLabel();
private JLabel Jahr = new JLabel();
private JLabel Preis = new JLabel();
private JButton bT_Speichern = new JButton();
private JTextField tF_TestFeld = new JTextField();
// Ende Attribute
public CGUI(String title)
{
// Frame-Initialisierung
super(title);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
int frameWidth = 659;
int frameHeight = 370;
setSize(frameWidth, frameHeight);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (d.width - getSize().width) / 2;
int y = (d.height - getSize().height) / 2;
setLocation(x, y);
Container cp = getContentPane();
cp.setLayout(null);
// Anfang Komponenten
tF_Suchfeld.setBounds(112, 8, 145, 24);
tF_Suchfeld.setText("");
tF_Suchfeld.setEnabled(true);
cp.add(tF_Suchfeld);
bT_Suche.setBounds(8, 8, 99, 25);
bT_Suche.setText("Suche");
bT_Suche.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
bT_Suche_ActionPerformed(evt);
}
});
bT_Suche.setFont(new Font("MS Sans Serif", Font.BOLD, 15));
cp.add(bT_Suche);
rB_Titel.setBounds(32, 112, 65, 17);
rB_Titel.setText("Titel?");
cp.add(rB_Titel);
rB_Jahr.setBounds(128, 136, 65, 17);
rB_Jahr.setText("Jahr?");
cp.add(rB_Jahr);
rB_Genre.setBounds(128, 113, 73, 15);
rB_Genre.setText("Genre?");
cp.add(rB_Genre);
rB_Album.setBounds(32, 160, 73, 17);
rB_Album.setText("Album?");
cp.add(rB_Album);
rB_Preis.setBounds(128, 160, 73, 17);
rB_Preis.setText("Preis?");
cp.add(rB_Preis);
rB_Interpret.setBounds(32, 137, 81, 15);
rB_Interpret.setText("Interpret?");
cp.add(rB_Interpret);
jButtonGroup1.add(rB_Titel);
jButtonGroup1.add(rB_Genre);
jButtonGroup1.add(rB_Interpret);
jButtonGroup1.add(rB_Jahr);
jButtonGroup1.add(rB_Album);
jButtonGroup1.add(rB_Preis);
l_DatenAusgabe.setBounds(24, 192, 233, 81);
cp.add(l_DatenAusgabe);
bT_DatenHinzufuegen.setBounds(80, 304, 131, 25);
bT_DatenHinzufuegen.setText("experimental Button");
bT_DatenHinzufuegen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
bT_DatenHinzufuegen_ActionPerformed(evt);
}
});
cp.add(bT_DatenHinzufuegen);
tF_Untergrenze.setBounds(112, 40, 113, 24);
tF_Untergrenze.setText("");
tF_Untergrenze.setVisible(false);
cp.add(tF_Untergrenze);
tF_Obergrenze.setBounds(112, 72, 113, 24);
tF_Obergrenze.setText("");
tF_Obergrenze.setVisible(false);
cp.add(tF_Obergrenze);
jL_Untergrenze.setBounds(24, 48, 73, 16);
jL_Untergrenze.setText("Untergrenze");
jL_Untergrenze.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
jL_Untergrenze.setVisible(false);
cp.add(jL_Untergrenze);
jL_Obergrenze.setBounds(24, 72, 71, 16);
jL_Obergrenze.setText("Obergrenze");
jL_Obergrenze.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
jL_Obergrenze.setVisible(false);
cp.add(jL_Obergrenze);
jL_Euro.setBounds(256, 40, 9, 20);
jL_Euro.setText("€");
jL_Euro.setFont(new Font("MS Sans Serif", Font.PLAIN, 15));
jL_Euro.setForeground(Color.BLACK);
jL_Euro.setVisible(false);
cp.add(jL_Euro);
jL_Euro2.setBounds(256, 72, 9, 20);
jL_Euro2.setText("€");
jL_Euro2.setFont(new Font("MS Sans Serif", Font.PLAIN, 15));
jL_Euro2.setForeground(Color.BLACK);
jL_Euro2.setVisible(false);
cp.add(jL_Euro2);
tF_EingabeTitel.setBounds(448, 24, 121, 24);
tF_EingabeTitel.setText("");
cp.add(tF_EingabeTitel);
tF_EingabeInterpret.setBounds(448, 56, 121, 24);
tF_EingabeInterpret.setText("");
cp.add(tF_EingabeInterpret);
tF_EingabeAlbum.setBounds(448, 88, 121, 24);
tF_EingabeAlbum.setText("");
cp.add(tF_EingabeAlbum);
tF_EingabeGenre.setBounds(448, 120, 121, 24);
tF_EingabeGenre.setText("");
cp.add(tF_EingabeGenre);
tF_EingabeJahr.setBounds(448, 152, 121, 24);
tF_EingabeJahr.setText("");
cp.add(tF_EingabeJahr);
Titel.setBounds(384, 24, 41, 24);
Titel.setText("Titel");
Titel.setFont(new Font("MS Sans Serif", Font.BOLD, 17));
cp.add(Titel);
Interpret.setBounds(352, 57, 78, 24);
Interpret.setText("Interpret");
Interpret.setFont(new Font("MS Sans Serif", Font.BOLD, 17));
cp.add(Interpret);
Album.setBounds(368, 88, 61, 24);
Album.setText("Album");
Album.setFont(new Font("MS Sans Serif", Font.BOLD, 17));
cp.add(Album);
tF_EingabePreis.setBounds(448, 184, 121, 24);
tF_EingabePreis.setText("");
cp.add(tF_EingabePreis);
Genre.setBounds(368, 121, 59, 24);
Genre.setText("Genre");
Genre.setFont(new Font("MS Sans Serif", Font.BOLD, 17));
cp.add(Genre);
Jahr.setBounds(384, 152, 41, 24);
Jahr.setText("Jahr");
Jahr.setFont(new Font("MS Sans Serif", Font.BOLD, 17));
cp.add(Jahr);
Preis.setBounds(384, 184, 48, 24);
Preis.setText("Preis");
Preis.setFont(new Font("MS Sans Serif", Font.BOLD, 17));
cp.add(Preis);
bT_Speichern.setBounds(400, 232, 107, 25);
bT_Speichern.setText("Speichern");
bT_Speichern.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
bT_Speichern_ActionPerformed(evt);
}
});
bT_Speichern.setFont(new Font("MS Sans Serif", Font.BOLD, 15));
cp.add(bT_Speichern);
tF_TestFeld.setBounds(392, 280, 113, 24);
tF_TestFeld.setText("");
cp.add(tF_TestFeld);
// Ende Komponenten
setResizable(false);
setVisible(true);
}
// Anfang Methoden
public void preisSuche()
{
if (rB_Preis.isSelected())
{
tF_Untergrenze.setVisible(true);
tF_Obergrenze.setVisible(true);
jL_Untergrenze.setVisible(true);
jL_Obergrenze.setVisible(true);
jL_Euro2.setVisible(true);
jL_Euro.setVisible(true);
tF_Suchfeld.setEnabled(false);
}
}
public void bT_Suche_ActionPerformed(ActionEvent evt)
{
// TODO hier Quelltext einfügen
String a = tF_Suchfeld.getText();
if (rB_Titel.isSelected())
{
Ordner3.titelFinden(a);
String umgewandelt = ("" + Ordner3.titelFinden(a));
String gefunden[] = {umgewandelt};
JList l_DatenAusgabe = new JList(gefunden);
JScrollPane ScrollPane1 = new JScrollPane(l_DatenAusgabe);
}
if (rB_Genre.isSelected())
{
Ordner3.genreFinden(a);
String umgewandelt = ("" + Ordner3.genreFinden(a));
String gefunden[] = {umgewandelt};
JList l_DatenAusgabe = new JList(gefunden);
JScrollPane ScrollPane1 = new JScrollPane(l_DatenAusgabe);
}
if (rB_Interpret.isSelected())
{
Ordner3.interpretFinden(a);
String umgewandelt = ("" + Ordner3.interpretFinden(a));
String gefunden[] = {umgewandelt};
JList l_DatenAusgabe = new JList(gefunden);
JScrollPane ScrollPane1 = new JScrollPane(l_DatenAusgabe);
}
if (rB_Album.isSelected())
{
Ordner3.albumFinden(a);
String umgewandelt = ("" + Ordner3.albumFinden(a));
String gefunden[] = {umgewandelt};
JList l_DatenAusgabe = new JList(gefunden);
JScrollPane ScrollPane1 = new JScrollPane(l_DatenAusgabe);
}
if (rB_Jahr.isSelected())
{
int b = Integer.parseInt(a);
Ordner3.jahrFinden(b);
String umgewandelt = ("" + Ordner3.jahrFinden(b));
String gefunden[] = {umgewandelt};
JList l_DatenAusgabe = new JList(gefunden);
JScrollPane ScrollPane1 = new JScrollPane(l_DatenAusgabe);
}
if (rB_Preis.isSelected())
{
Double uG = Double.parseDouble(tF_Untergrenze.getText());
Double oG = Double.parseDouble(tF_Obergrenze.getText());
Ordner3.preisFinden(uG,oG);
String umgewandelt = ("" + Ordner3.preisFinden(uG,oG));
String gefunden[] = {umgewandelt};
JList l_DatenAusgabe = new JList(gefunden);
JScrollPane ScrollPane1 = new JScrollPane(l_DatenAusgabe);
}
}
public void bT_DatenHinzufuegen_ActionPerformed(ActionEvent evt) {
// TODO hier Quelltext einfügen
//private JButton bT_Hallo = new JButton();
}
public String getSelectedRadioButton(ButtonGroup bg) {
for (java.util.Enumeration<AbstractButton> e = bg.getElements(); e.hasMoreElements();) {
AbstractButton b = e.nextElement();
if (b.isSelected()) return b.getText();
}
return null;
}
public void bT_Speichern_ActionPerformed(ActionEvent evt)
{
int x = Integer.parseInt(tF_EingabeJahr.getText());
Double y = Double.parseDouble(tF_EingabePreis.getText());
Ordner3.SongAttribute(new CSong(tF_EingabeTitel.getText(), tF_EingabeInterpret.getText(), tF_EingabeGenre.getText(), tF_EingabeAlbum.getText(), x, y));
tF_TestFeld.setText(tF_EingabeTitel.getText());
}
// Ende Methoden
public static void main(String[] args) {
new CGUI("CGUI");
}
}
Hier die 2. Klasse COrdner:
Java:
public class COrdner {
// Anfang Attribute
private CSong[] Ordner2;
private int AnzahlSongs = 0;
// Ende Attribute
// Anfang Methoden
public int AnzahlSongsAusgeben ()
{
return AnzahlSongs;
}
public void SongAttribute(CSong AlleAttribute)
{
Ordner2[AnzahlSongs] = AlleAttribute;
AnzahlSongs++;
}
//Alle normalen Abfragen:
public CSong albumFinden(String album)
{
for (int index = 0; index <= AnzahlSongs; index++)
{
if(Ordner2[index].getAlbum().equals(album))
{
return Ordner2[index];
}
}
return null;
}
public CSong titelFinden (String titel)
{
for (int index=0; index <= AnzahlSongs; index++)
{
if (Ordner2[index].getTitel().equals(titel))
{
return Ordner2[index];
}
}
return null;
}
public CSong genreFinden(String genre)
{
for (int index=0; index <= AnzahlSongs; index++)
{
if (Ordner2[index].getGenre().equals(genre))
{
return Ordner2[index];
}
}
return null;
}
public CSong interpretFinden (String interpret)
{
for (int index=0; index <= AnzahlSongs; index++)
{
if (Ordner2[index].getInterpret().equals(interpret))
{
return Ordner2[index];
}
}
return null;
}
public CSong preisFinden(Double uG,Double oG)
{
for( int index=0; index <= AnzahlSongs; index++)
{
for(Double g=uG; g<=oG ; g = g+0.01)
{
//String e = (new Double.valueOf(g)).toString(); //um g/e in eine Zeichenkette zu verwandeln
if(Ordner2[index].getPreis() == g)
{
return Ordner2[index];
}
}
}
return null;
}
public CSong jahrFinden(int jahr)
{
for(int index=0; index <= AnzahlSongs; index++)
{
if(Ordner2[index].getJahr() == jahr)
{
return Ordner2[index];
}
}
return null;
}
}
Und hier die 3. und letzte Klasse CSong:
Java:
public class CSong {
// Anfang Attribute
private String Titel;
private String Interpret;
private String Genre;
private String Album;
private int Jahr;
private double Preis;
// Ende Attribute
// Anfang Methoden
public CSong(String Titel, String Interpret, String Genre, String Album, int Jahr, Double Preis)
{
this.Titel = Titel;
this.Interpret = Interpret;
this.Genre = Genre;
this.Album = Album;
this.Jahr = Jahr;
this.Preis = Preis;
}
public String getTitel()
{
return Titel;
}
public String getInterpret()
{
return Interpret;
}
public String getGenre()
{
return Genre;
}
public String getAlbum()
{
return Album;
}
public int getJahr()
{
return Jahr;
}
public double getPreis()
{
return Preis;
}
// Ende Methoden
}
Danke für die Hilfe schonmal im Vorraus.