GUI-Ausgabe mit Bild und Sound

Status
Nicht offen für weitere Antworten.

Zeim

Mitglied
Hey,
ich hoffe, dass ich das richtige Unterforum erwischt habe.

Zur Zeit erstelle ich mir einen Pokedex mit Java BlueJ als eine Art Projekt für Informatik. Jedenfalls bin ich soweit, dass mir alles korrekt ausgegeben wird und alle Buttons, etc. funktionieren. Nun will ich zusätzlich noch im GUI ein Bild sowie einen Button einfügen, der einen Sound abspielt.

Mometan sieht es so aus:


Hier der Quellcode:
Code:
import java.io.*;
import javax.sound.sampled.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Pokédex extends JFrame implements ActionListener {
    private JPanel eingabe, information;
    private JTextArea aInformation;
    private JLabel lZahl, lName, lTyp1, lTyp2, lAngaben;
    private JTextField tZahl, tName, tTyp1, tTyp2, tAngaben;
    private JButton bSuchen;

    public Pokédex() {
        super("Pokédex");
        setSize(220,250);
        eingabe = new JPanel();
        information = new JPanel();
        getContentPane().add("North", eingabe);
        eingabe.setLayout(new GridLayout(5,2));
        getContentPane().add("Center", information);
        
        lZahl = new JLabel("Nr. des Pokemon:");
        eingabe.add(lZahl);
        tZahl = new JTextField(3);
        eingabe.add(tZahl);
        
        lName = new JLabel("Name:");
        eingabe.add(lName);
        tName = new JTextField(15);
        eingabe.add(tName);
        tName.setEditable(false);
        
        lTyp1 = new JLabel("Typ #1:");
        eingabe.add(lTyp1);
        tTyp1 = new JTextField(10);
        eingabe.add(tTyp1);
        tTyp1.setEditable(false);
        
        lTyp2 = new JLabel("Typ #2:");
        eingabe.add(lTyp2);
        tTyp2 = new JTextField(10);
        eingabe.add(tTyp2);
        tTyp2.setEditable(false);
        
        lAngaben = new JLabel("Größe/Gewicht:");
        eingabe.add(lAngaben);
        tAngaben = new JTextField(10);
        eingabe.add(tAngaben);
        tAngaben.setEditable(false);
        
        aInformation = new JTextArea(4,17);
        information.add(aInformation);
        aInformation.setEditable(false);
        aInformation.setLineWrap(true);
        
        bSuchen = new JButton("Suchen");
        information.add(bSuchen);
        bSuchen.addActionListener(this);
        
        setVisible(true);
    }
    
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == bSuchen){
            suchePokemon();
        }
    }
    
    public void suchePokemon() {
        aInformation.setText("");
        tName.setText("");
        tTyp1.setText("");
        tTyp2.setText("");
        tAngaben.setText("");
        int nummer;
        try {
            nummer = Integer.parseInt(tZahl.getText());
        }
        catch(Exception e) {
            nummer = 0;
            aInformation.setText("Bitte eine Zahl zwischen 1 \nund 151 eingeben.");
            return;
        }
        
        if((nummer <= 0) || (nummer > 151)) {
            aInformation.setText("Bitte eine Zahl zwischen 1 \nund 151 eingeben");
        }
        
        else if(nummer == 1) {
            tName.setText("Bisasam");
            tTyp1.setText("Gift");
            tTyp2.setText("Pflanze");
            tAngaben.setText("0,7m / 6,9kg");
            aInformation.setText("Informationen über das Pokemon");
        }
    }
}
Hat jemand Ahnung wie das funktioniert?
Die Bilder sind nicht größer als 250x250 (30kb) und die Sounddateien können in ein beliebiges Format gewandelt werden.

Danke & MfG
 
Hello again,

habe das Bild nun in den GUI eingefügt gekriegt:

Code:
bild = new JLabel(new ImageIcon("Pfad/004.gif"));
        information.add(bild);

Weiß jemand etwas über das Einfügen/Abspielen einer Sounddatei?

MfG
 
Status
Nicht offen für weitere Antworten.

Zurück
Oben