Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By KevinWorkman

Thread: Gui

  1. #1
    GetIt is offline Member
    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Default Gui

    Hello community, I am a complete Java newbie and just try me on a Java GUI to various audio formats such as. Flac to. Mp3 converts.

    But I come with my GUI not just continue, I have "already accomplished a frame to create a menu bar" File> Open and Close "," Tools "and" Help> About

    For the audio converter to get an MP3 player with volume control and Fortschritsanzeige into the window.

    Could help me there, perhaps?
    I would be very grateful for the help and ideas.

    About as I had imagined.
    Gui-guixmdi0.jpg

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package sox;
    
    import java.awt.*;
    import java.awt.event.*;
    import java.io.File;
    import javax.swing.*;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    import javax.swing.filechooser.FileFilter;
    
    class LAF extends JFrame
            implements ActionListener {
    
        private File file;
    
        //implementieren des ActionListener interfaces
        @Override
        public void actionPerformed(ActionEvent event) {                        //
            if (event.getActionCommand().equals("open")) {                      //
                JFileChooser fc = new JFileChooser();                           //
                fc.setMultiSelectionEnabled(true);                              //Mehrere Dateien wählen
                fc.setDialogTitle("Datei Auswahl");                             //
                fc.setFileFilter(new FileFilter() {                             //
                    public boolean accept(File f) {                             //
                        return f.getName().toLowerCase().endsWith(".mp3") || f.isDirectory();
                    }
    
                    public String getDescription() {
                        return "(*.mp3)";
                    }
                });
                if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {   //Öffnen Button
                    @SuppressWarnings("LocalVariableHidesMemberVariable")       //mit File Chooser
                    File file = fc.getSelectedFile();                           //
                    System.out.println(file.getName());                         //
                }
    
            }
            if (event.getActionCommand().equals("Beenden")) {  //Fenster schließen 
                this.setVisible(false);                        //durch Beenden 
                this.dispose();                                //Button
    
            }
    
        }
    //Konstruktor
    
        @SuppressWarnings("LeakingThisInConstructor")
        public LAF() {
            super("AUDIO CONVERTER");
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setSize(800, 600);
    
    
            Container container = this.getContentPane();
            container.setLayout(new BorderLayout());
    
            //Menüleiste erzeugen
            JMenuBar menueLeiste = new JMenuBar();
            this.setJMenuBar(menueLeiste);
    
            // ---------------------------------------------------------------------
    
            // Dropdown Menü (Datei)
            JMenu dateiMenue = new JMenu("Datei");
            menueLeiste.add(dateiMenue);  // Datei Button
    
            JMenuItem oeffnenEintrag = new JMenuItem("Öffnen");
            oeffnenEintrag.addActionListener(this);
            oeffnenEintrag.setActionCommand("open");
            dateiMenue.add(oeffnenEintrag); // (Öffnen Button mit FileChooser)
    
            JMenuItem beendenEintrag = new JMenuItem("Beenden");
            beendenEintrag.addActionListener(this);         // Beendet das Programm                   
            beendenEintrag.setActionCommand("Beenden");     // Beendet das Programm     
            dateiMenue.add(beendenEintrag);  // (Beenden Button)
    
            // ---------------------------------------------------------------------
    
            // Dropdown Menü (Werkzeuge)
            JMenu werkzeuge = new JMenu("Werkzeuge");
            menueLeiste.add(werkzeuge);  // Dropdown Menü (Werkzeuge Button)
    
            JMenuItem audioConverter = new JMenuItem("Audio Converter");
            audioConverter.addActionListener(this);
            werkzeuge.add(audioConverter); // Werkzeug Audio Converter
    
            JMenuItem mediaPlayer = new JMenuItem("Media Player");
            mediaPlayer.addActionListener(this);
            werkzeuge.add(mediaPlayer); // Werkzeug Media Player
    
            // ---------------------------------------------------------------------
    
            // Dropdown Menü (Hilfe)
    
            JMenu hilfeMenue = new JMenu("Hilfe");
            menueLeiste.add(hilfeMenue);  // Hilfe Button
    
            JMenuItem infoEintrag = new JMenuItem("Info");
            infoEintrag.addActionListener(this);
            hilfeMenue.add(infoEintrag);  // Info (Button)
    
    
    
            setVisible(true);
            infoEintrag.addActionListener(this);
            // ---------------------------------------------------------------------
        }
    
        //Die Main Methode
        @SuppressWarnings("ResultOfObjectAllocationIgnored")
        public static void main(String args[]) {
            new LAF();
        }
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,993
    Rep Power
    9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •