Announcement

Collapse
No announcement yet.

Building A Completely Java Based Front End

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Building A Completely Java Based Front End

    Not sure what I'll call it yet but it'll be completely Java based and the front end will be separate from the back end so you'll be able to build your own GUI and run it on your machine if you're so inclined. But here's what I have after just a few days....more questions than anything really....


    Here's a hacked up version of the skin I'm using now with a few new features added:



    The top bar will display the current song and to the right of it is a digital clock. The bottom left is a slider style control for the volume and above that is a box containing the heading and next to that is the temperature in the car with up/down arrows for controlling it. Functionality not important for now.

    So here are the containers I was going to build to hold all this stuff:



    In this image I've got the JFrame which will be 800x600 and three containers inside the JFrame labeled 1, 2 and 3.

    Each container will hold more containers:



    Each of those containers holds more contianers:



    And each of those containers will contain a bunch of JPanels which will eventually each contain a button or label:



    Now I have a few questions:
    1. Am I doing this totally wrong? I know it will work but what's better for laying it out?
    2. Do I have to add containers to the JFrame and then JPanels to the container and then labels tot he JPanels and then buttons to the labels? Can I just add buttons to the Frame, or JPanels straight to the JFrame or any other weird combination?
    3, Any other ideas?
    Ampie Case
    2.5" Hard Drive 80GB Samsung 5400RPM
    256 MB DDR2 PC5400
    Xenarc 700TSV - VGA Monitor
    Intel D945GCLF Motherboard
    M2-ATX-HV

    2005 Honda Civic

  • #2
    having panels/containters isn't a "bad" idea it just seems rather limiting.

    I am also just wondering, why java?

    keep up the good work
    Former author of LinuxICE, nghost, nobdy.
    Current author of Automotive Message Broker (AMB).
    Works on Tizen IVI. Does not represent anyone or anything but himself.

    Comment


    • #3
      It's the only language I know. Why does everyone ask that? Who cares.
      Ampie Case
      2.5" Hard Drive 80GB Samsung 5400RPM
      256 MB DDR2 PC5400
      Xenarc 700TSV - VGA Monitor
      Intel D945GCLF Motherboard
      M2-ATX-HV

      2005 Honda Civic

      Comment


      • #4
        Originally posted by kev000 View Post
        having panels/containters isn't a "bad" idea it just seems rather limiting.

        I am also just wondering, why java?


        Originally posted by Maheriano View Post
        It's the only language I know. Why does everyone ask that? Who cares.
        We ask because Java is very limiting, bloated, and slow. It is cross platform though so you may get that first all OS support that no-body has. But you do know that java is one of the slowest languages, so smoothness will be hard to achieve with big graphics and low-end media.

        But I dont think this has been done before, so keep at it!

        As for how to do it, I am pretty sure the best way to do it, would be to just put everything in 1 panel. Define where by point locations and size. This way you are not limited by the number of panels. Then when a click happens, iterate through every thing in that 1 panel, until the mouse intersects that area.
        Fusion Brain Version 6 Released!
        1.9in x 2.9in -- 47mm x 73mm
        30 Digital Outputs -- Directly drive a relay
        15 Analogue Inputs -- Read sensors like temperature, light, distance, acceleration, and more
        Buy now in the MP3Car.com Store

        Comment


        • #5
          Been working on it yesterday and today.

          Ampie Case
          2.5" Hard Drive 80GB Samsung 5400RPM
          256 MB DDR2 PC5400
          Xenarc 700TSV - VGA Monitor
          Intel D945GCLF Motherboard
          M2-ATX-HV

          2005 Honda Civic

          Comment


          • #6
            Been coding all day, even took it to the restaurant while waiting for food.

            Clock - dynamically pulls current time from computer clock
            Songs - dynamically pulls current files located in predetermined songs directory. Doesn't yet pull level 0 files, just top level.
            Album Cover - doesn't yet pull dynamically
            Buttons - not yet mapped to anything

            Ampie Case
            2.5" Hard Drive 80GB Samsung 5400RPM
            256 MB DDR2 PC5400
            Xenarc 700TSV - VGA Monitor
            Intel D945GCLF Motherboard
            M2-ATX-HV

            2005 Honda Civic

            Comment


            • #7
              updates:

              - song list recursively populated from a specified directory
              - double tap a song in the list and it plays
              - double tap a new song in the list and the first one stops, the new one plays
              - new buttons

              Ampie Case
              2.5" Hard Drive 80GB Samsung 5400RPM
              256 MB DDR2 PC5400
              Xenarc 700TSV - VGA Monitor
              Intel D945GCLF Motherboard
              M2-ATX-HV

              2005 Honda Civic

              Comment


              • #8
                Is anyone even following this thread?

                Had some more time yesterday. I'm not doing much at work right now so I got a lot of time to browse the Swing forums over at Sun.

                - to play a song you can double click the song name or single click it and hit play
                - song list is just song names now, not the full path
                - when you play a song it loads the song name up top
                - buttons fit to window
                - volume bar which moves from green to red to control volume
                - border removed around song list
                - album cover loads when song is played

                Ampie Case
                2.5" Hard Drive 80GB Samsung 5400RPM
                256 MB DDR2 PC5400
                Xenarc 700TSV - VGA Monitor
                Intel D945GCLF Motherboard
                M2-ATX-HV

                2005 Honda Civic

                Comment


                • #9
                  I check in every now and then to see what you've got.
                  Fusion Brain Version 6 Released!
                  1.9in x 2.9in -- 47mm x 73mm
                  30 Digital Outputs -- Directly drive a relay
                  15 Analogue Inputs -- Read sensors like temperature, light, distance, acceleration, and more
                  Buy now in the MP3Car.com Store

                  Comment


                  • #10
                    That makes me feel better!
                    Ampie Case
                    2.5" Hard Drive 80GB Samsung 5400RPM
                    256 MB DDR2 PC5400
                    Xenarc 700TSV - VGA Monitor
                    Intel D945GCLF Motherboard
                    M2-ATX-HV

                    2005 Honda Civic

                    Comment


                    • #11
                      I always keep an eye on frontends. It is always good to see what is being developed.
                      Never let the truth get in the way of a good story

                      Comment


                      • #12
                        Challenges

                        How much time have you spent researching the challenges involved in making a truly great Java front-end? By 'great', I mean that people would prefer your app over what is currently on the market, regardless of price.

                        I've been building simple test cases for a while now, and I have yet to find a cost effective solution to the following...

                        1. DRM infected music. There are a lot of people with subscriptions to music services. These people will naturally expect their music to play on their carpc. How would you play subscription-downloaded music in a cross platform manner? Sure, you could always write a wrapper around WMP (or buy one), but then you kill the cross platform compatability.

                        2. Navigation. You can use Java to access the GPS receiver, but then you have the challenge of how to display it. You could use one of the online map providers, but that would require users to be always connected to the internet. Again, you could write a wrapper around mappoint or some other sdk, but you kill the cross platform part. I've searched and searched for a Java solution, but came up empty every time.

                        These are the hard challenges. If you can think of a way around them, I'd be happy to help you out.

                        @The Java-haters above: java itself is not slow, the recent jres (1.5+) have great performance. Cold startup time is admittedly an issue. However, once the jre starts, you would be hard pressed to see the performance difference.
                        My car PC page, with pictures

                        Comment


                        • #13
                          1. WTF is DRM?
                          2. For navigation I would just embed iGuidance again, I'm not looking for something cross platform, this is simply a front end for me specifically. And if anyone else likes it then they can use it too!

                          But I'm kind of stuck right now as to how I skip to a specified portion of the audio file after moving the slider. I can't figure that out. I don't see any methods that take a byte/frame position in the file as a parameter to use as a starting point.
                          Ampie Case
                          2.5" Hard Drive 80GB Samsung 5400RPM
                          256 MB DDR2 PC5400
                          Xenarc 700TSV - VGA Monitor
                          Intel D945GCLF Motherboard
                          M2-ATX-HV

                          2005 Honda Civic

                          Comment


                          • #14
                            1. DRM = Digital Rights Management, aka restricted files. This is put on files that you download from music subscription services (Napster, iTunes, etc...)

                            2. It seems odd to use Java to write a platform specific application. If I was going to write for windows only, I'd just use C# or VB, which allow much tighter integration into the underlying platform. I know you only know Java right now, but this may be a good excuse for you to learn C# (very Java-like). It looks good on a resume to know more than one language anyhow.

                            3. If you were able to pull off a great, fully cross platform frontend in Java, you'd be a star at the next JavaOne.

                            4. What method are you using to play music files? Maybe I can help you on the seek functionality.
                            My car PC page, with pictures

                            Comment


                            • #15
                              Originally posted by coffeejolts View Post
                              1. DRM = Digital Rights Management, aka restricted files. This is put on files that you download from music subscription services (Napster, iTunes, etc...)

                              2. It seems odd to use Java to write a platform specific application. If I was going to write for windows only, I'd just use C# or VB, which allow much tighter integration into the underlying platform. I know you only know Java right now, but this may be a good excuse for you to learn C# (very Java-like). It looks good on a resume to know more than one language anyhow.

                              3. If you were able to pull off a great, fully cross platform frontend in Java, you'd be a star at the next JavaOne.

                              4. What method are you using to play music files? Maybe I can help you on the seek functionality.
                              DRM......right, but I don't understand what the issue is. Just put it in your car and play it........it doesn't work? Why would anyone buy a song you can't port?

                              I'm using the Java Media Framework (JMF) to play the songs right now, I wrote my own player for it by creating an AudioInputStream and reading from the file, then writing to the stream. I've posted it a few times on the Java forums at Sun but no luck, not even any replies. Here's the Player class I wrote:
                              import java.io.File;
                              import java.io.IOException;

                              import javax.sound.sampled.AudioFormat;
                              import javax.sound.sampled.AudioInputStream;
                              import javax.sound.sampled.AudioSystem;
                              import javax.sound.sampled.BooleanControl;
                              import javax.sound.sampled.Control;
                              import javax.sound.sampled.DataLine;
                              import javax.sound.sampled.FloatControl;
                              import javax.sound.sampled.SourceDataLine;
                              import javax.sound.sampled.FloatControl.Type;
                              import javax.swing.SwingUtilities;


                              public class Player
                              {


                              public Player()
                              {

                              }

                              public void playSong(String song)
                              {
                              final String songLocation = song;
                              {
                              try
                              {
                              File file = new File(songLocation);
                              fileSize = file.length();
                              in = AudioSystem.getAudioInputStream(file);
                              AudioFormat baseFormat = in.getFormat();
                              AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16, baseFormat.getChannels(), baseFormat.getChannels() * 2, baseFormat.getSampleRate(), false);
                              din = AudioSystem.getAudioInputStream(decodedFormat, in);
                              DataLine.Info info = new DataLine.Info(SourceDataLine.class, decodedFormat);
                              line = (SourceDataLine) AudioSystem.getLine(info);
                              if (line != null)
                              {
                              line.open(decodedFormat);
                              data = new byte[4096];
                              // Start
                              line.start();
                              long percentageOfFileRead;
                              long numberOfBytesRead;
                              while ((nBytesRead = din.read(data, 0, data.length)) != -1)
                              {
                              line.write(data, 0, nBytesRead);
                              System.out.println("Frame length = " + din.getFrameLength());
                              numberOfBytesRead = fileSize - in.available();
                              percentageOfFileRead = (numberOfBytesRead * 100) / fileSize;
                              MusicGUI.songSlider.setValue((int)percentageOfFile Read);
                              }
                              // Stop
                              /* line.drain();
                              line.stop();
                              line.close();
                              din.close();*/
                              }
                              }
                              catch(Exception e)
                              {
                              e.printStackTrace();
                              }
                              finally
                              {
                              if(din != null)
                              {
                              try
                              {
                              din.close();
                              }
                              catch(IOException e)
                              {
                              System.out.println("Error: " + e);
                              }
                              }
                              }
                              }
                              try
                              {
                              Thread.sleep(800);
                              }
                              catch (InterruptedException e)
                              {
                              e.printStackTrace();
                              }
                              }

                              public void stopSong()
                              {
                              if(din != null)
                              {
                              try
                              {
                              line.stop();
                              line.close();
                              din.close();
                              }
                              catch(IOException e)
                              {
                              System.out.println("Error: " + e);
                              }
                              }
                              }


                              public void muteLine()
                              {
                              /* control = (BooleanControl)line.getControl(BooleanControl.Typ e.MUTE);
                              if (control.getValue() == true)
                              {
                              control.setValue(false);
                              }
                              else
                              {
                              control.setValue(true);
                              }
                              */
                              volumeControl = (FloatControl)line.getControl(FloatControl.Type.MA STER_GAIN);
                              if (volumeControl.getValue() == -80)
                              {
                              volumeControl.shift(-80, 6, 400000000);
                              }
                              else
                              {
                              volumeControl.setValue(-80);
                              }
                              }

                              public int getElapsedTime()
                              {
                              return nBytesRead;
                              }

                              public void setElapsedTime(int newPosition)
                              {
                              if(newPosition > 0)
                              {
                              temp = (int)fileSize * newPosition / 100;
                              System.out.println("File Size = " + fileSize);
                              System.out.println("Slider Position = " + newPosition);
                              System.out.println("Number of bytes to skip to = " + temp);
                              try
                              {
                              din.skip(500);
                              }
                              catch(IOException e)
                              {
                              e.printStackTrace();
                              }
                              }
                              }

                              public String getVolume()
                              {
                              volumeControl = (FloatControl)line.getControl(FloatControl.Type.MA STER_GAIN);
                              return volumeControl.toString();
                              }

                              public void setVolume(int volume)
                              {
                              volumeControl = (FloatControl)line.getControl(FloatControl.Type.MA STER_GAIN);
                              volumeControl.setValue(volumeControl.getValue() + (float).1);
                              }

                              private long i = 0;
                              private int temp;
                              private long fileSize;
                              private byte[] data;
                              private int nBytesRead;
                              private SourceDataLine line = null;
                              private FloatControl volumeControl = null;
                              BooleanControl control = null;
                              AudioInputStream in = null;
                              AudioInputStream din = null;
                              }
                              Forget the getter / setter methods at the bottom, the place it's playing the song is this line:
                              while ((nBytesRead = din.read(data, 0, data.length)) != -1)
                              {
                              line.write(data, 0, nBytesRead);
                              }
                              It's buffering 4096 bytes, writing (playing) it, then getting the next 4096 bytes and it does that for the whole song. It works perfect and the slider follows along with it but when I move the slider I can't get the song to jump, I'm lost at how to do this. Let me know if you want any more code. Thanks!
                              Ampie Case
                              2.5" Hard Drive 80GB Samsung 5400RPM
                              256 MB DDR2 PC5400
                              Xenarc 700TSV - VGA Monitor
                              Intel D945GCLF Motherboard
                              M2-ATX-HV

                              2005 Honda Civic

                              Comment

                              Working...
                              X