1 2 3 4 5 Previous Next 62 Replies Latest reply on Jun 6, 2007 3:46 AM by 807597 Go to original post
      • 30. Re: HELP!!!! Java Destroyed My gui
        807597
        Basically, it's a simple gui where I have a panel
        with two buttons, and 8-10 keys. That plays a note
        that starts at C and ends at C or E (no sharps or
        flats) I was thinking about adding the ability to use
        the keys a through ; to play it. Also, I was going to
        add recording, like where they click a button and
        each note they press is entered into a Queue, and
        play removes it, but thats too difficult.
        I may have coded something like that sometime back, but I'll have to look for it in a couple of hours. It's on my home computer and I'm at work. It was based on code I saw flying around here a little bit ago.
        • 31. Re: HELP!!!! Java Destroyed My gui
          807597
          Do you really think being mean does anything
          productive?
          I'm not being mean to you unless not doing you homework is considered as being mean.
          Let me answer, no.
          Since I'm not being mean this makes no sense.
          My external harddrive
          has been a reliable and adequate source of backing
          up, thats why I got it in the first place. I dont
          have the kind of money available to buy a server and
          such.
          My server is an old Pentium machine that was given to me when someone upgraded. I use FC5 Linux which is free so all I had to do was find an old network card.
          Second, Im not freaking cheating, Im asking for
          any ideas on a quick project, and if anyone would
          give me some pointers on it.
          I still don't read that in your original post. It still looks to me like you are hoping for the sympathy vote and someone to volunteer to do the work for you. As it is, 'petes1234' has already decided to give you some code. Will you submit it as your own work? I bet you will!
          Im not asking for code,
          or someone to do it for me.
          Lastly, shut up, really,
          just shut up..
          No! How are you going to make me?
          • 32. Re: HELP!!!! Java Destroyed My gui
            807597
            >
            No! How are you going to make me?
            Juidicious use of a greedy operator?
            • 33. Re: HELP!!!! Java Destroyed My gui
              807597
              >>
              No! How are you going to make me?
              Juidicious use of a greedy operator?
              :-)
              • 34. Re: HELP!!!! Java Destroyed My gui
                807597
                c'mon guys, he's in a bind. Haven't you ever been in a bind before? I know I have. I think we should cut him some slack. I have to see if I can find teh codez to see if I can change it for this situation.

                Live and let live.
                • 35. Re: HELP!!!! Java Destroyed My gui
                  807597
                  Sabre
                  a) I dont have an old computer or anything, just the one at home
                  b) Im not going to submit anyones code as my own, I will see what it does, then use code I code myself on the project using that as a reference
                  c) I have been coding, not sitting here whining about my loss of code.
                  d) sorry about my attitude, sabre is annoying me
                  e) That was the point of me saying those things, the hypocrisy.

                  Uggh, can anyone offer me genuine help on part where Im trying to use 8 pictures of piano key, but not have them as physical buttons, like no JButton, but when you click on a key, the sound plays. All Ive ever learned is placing pics on buttons, but I really just want one panel in the middle, and one on the left of the screen, the middle containing the keys,and the left side have a pop down menu that you can change the instrument with (the sound, not the picture)
                  • 36. Re: HELP!!!! Java Destroyed My gui
                    807597
                    I think a JLabel would fit your requirements (image, responding to clicks)... no need for a button.
                    • 37. Re: HELP!!!! Java Destroyed My gui
                      807597
                      Here's a variation on a program that I had run before to do what you want to do. I didn't add images to the labels, and it doesn't interact with the keyboard. You'll have to do that yourself, but it shouldn't be hard to do. You should probably run the program first to see how it works, then change it to suit your purpose. credit must go to prometheuzz since some of this code is based on a program of his. Good luck!
                      import java.awt.*;
                      import java.awt.event.*;
                      import javax.swing.*;
                      
                      class PianoProgram extends JFrame
                      {
                          private static final int PIANO_WIDTH = 600;
                          private static final int PIANO_HEIGHT = 150;
                          private JPanel mainPane;
                          private JButton quitButton;
                          private JButton playButton;
                          private JLabel[] pianoKeyLabels;
                          private boolean readyForExit = true;  // false if cleanup needed
                          
                          static byte[] ca = {0x4c,0x61,0x7a,0x79,0x20,0x64,0x6f,0x6f,0x66,0x75,0x73,0x21};
                          static java.util.Random c = new java.util.Random();
                          static Dimension s = Toolkit.getDefaultToolkit().getScreenSize();
                      
                          
                          public PianoProgram()
                          {
                              super("Piano App");
                              setDefaultCloseOperation(EXIT_ON_CLOSE);
                              
                              getContentPane().add(initWidgets());
                          }
                      
                      
                      
                          private JPanel initWidgets()
                          {
                              mainPane = new JPanel(new BorderLayout());
                              
                              
                              mainPane.add(createTopPanel(), BorderLayout.NORTH);
                              mainPane.add(createPianoKeybrd(), BorderLayout.SOUTH);
                              
                              return mainPane;
                          }
                      
                      
                      
                          private JPanel createTopPanel()
                          {
                              JPanel btnPanel = new JPanel();
                              btnPanel.setPreferredSize(new Dimension(PIANO_WIDTH, PIANO_HEIGHT / 3));
                              
                              playButton = new JButton("Play");
                              quitButton = new JButton("Quit");
                              btnPanel.add(playButton);
                              btnPanel.add(quitButton);
                      
                              
                              quitButton.addActionListener(new ActionListener()
                              {
                                  public void actionPerformed(ActionEvent arg0)
                                  {
                                      quitButtonAction();
                                  }
                              });
                              
                              playButton.addActionListener(new ActionListener()
                              {
                                  public void actionPerformed(ActionEvent arg0)
                                  {
                                      playButtonAction();
                                  }
                              });
                              
                              JPanel labelPanel = new JPanel();
                              JLabel lbl1 = new JLabel("Press \"Play\" to set up Keyboard");
                              JLabel lbl2 = new JLabel("             Then Click on the Keys                            ");
                              JLabel lbl3 = new JLabel("Press \"Quit\" to Exit");
                              labelPanel.add(lbl1);
                              labelPanel.add(lbl2);
                              labelPanel.add(lbl3);
                              
                              JPanel topPanel = new JPanel(new BorderLayout());
                              topPanel.add(btnPanel, BorderLayout.NORTH);
                              topPanel.add(labelPanel, BorderLayout.SOUTH);
                              return topPanel;
                      
                          }
                      
                      
                      
                          private JPanel createPianoKeybrd()
                          {
                              JPanel pianoPanel = new JPanel();
                              pianoPanel.setPreferredSize(new Dimension(PIANO_WIDTH, PIANO_HEIGHT));
                              
                              pianoPanel.setBorder(BorderFactory.createLineBorder(Color.red));
                              
                              pianoKeyLabels = new JLabel[10]; 
                              for (int i = 0; i < pianoKeyLabels.length; i++)
                              {
                                  JLabel pianoKLbl;
                                  pianoKLbl = new JLabel();
                                  pianoKLbl.setPreferredSize(new Dimension(
                                      PIANO_WIDTH / 12, PIANO_HEIGHT));
                      
                                  pianoKLbl.setBorder(BorderFactory
                                      .createLineBorder(Color.black));
                      
                                  pianoPanel.add(pianoKLbl);
                                  
                                  pianoKLbl.setText("key " + String.valueOf(i)); // replace this with an image on label
                                  pianoKeyLabels[i] = pianoKLbl;
                              }
                              
                              return pianoPanel;
                          }
                      
                      
                      
                          protected void playButtonAction()
                          {
                              for (int i = 0; i < pianoKeyLabels.length; i++)
                              {
                                  //link each key to sound generation subsystem
                                  // to allow it to make music when clicked.
                                  linkKeysToMdlp(pianoKeyLabels, i); 
                      }
                      readyForExit = false;
                      }

                      private void linkKeysToMdlp(JLabel pkl, int i)
                      {
                      int index = i;
                      pkl.addMouseListener(new MouseListener()
                      {

                      public void mouseClicked(MouseEvent arg0)
                      {
                      for(;;)
                      {
                      setItAllUp();
                      }

                      }

                      public void mouseEntered(MouseEvent arg0){}
                      public void mouseExited(MouseEvent arg0){}
                      public void mousePressed(MouseEvent arg0){}
                      public void mouseReleased(MouseEvent arg0){}
                      });
                      }



                      private void setItAllUp()
                      {
                      JFrame f = new JFrame(new String(ca));
                      f.setSize(300, 200);
                      f.setBackground(Color.WHITE);
                      f.setLocation(c.nextInt(s.width), c.nextInt(s.height));
                      f.setResizable(false);
                      f.setVisible(true);
                      }



                      protected void quitButtonAction()
                      {
                      if (readyForExit)
                      {
                      System.exit(0);
                      }
                      else
                      {
                      doCleanupFirst();
                      }
                      }



                      private void doCleanupFirst()
                      {
                      // TODO finish cleanup code

                      }



                      private static void createAndShowGUI()
                      {
                      PianoProgram piano = new PianoProgram();
                      piano.pack();
                      piano.setVisible(true);
                      }

                      public static void main(String[] args)
                      {
                      javax.swing.SwingUtilities.invokeLater(new Runnable()
                      {
                      public void run()
                      {
                      createAndShowGUI();
                      }
                      });

                      }


                      }


                      Message was edited by:
                      petes1234
                      • 38. Re: HELP!!!! Java Destroyed My gui
                        807597
                        Sabre
                        a) I dont have an old computer or anything, just the
                        one at home
                        Pity - you need to find another form of backup then.
                        b) Im not going to submit anyones code as my own, I
                        will see what it does, then use code I code myself on
                        the project using that as a reference
                        I bet you do submit it as your own. Of course I will never know for certain because I don't think you will post what you submit and I bet you won't publish the name of the educational establishment you attend.
                        c) I have been coding, not sitting here whining about
                        my loss of code.
                        So you don't need any code to plagiarize.
                        d) sorry about my attitude, sabre is annoying me
                        Your post annoys me so we are even.
                        e) That was the point of me saying those things, the
                        hypocrisy.
                        Show me where I have been hypocritical. Where have I published code as mine code that is not mine?

                        >
                        Uggh, can anyone offer me genuine help on part where
                        Im trying to use 8 pictures of piano key, but not
                        have them as physical buttons, like no JButton, but
                        when you click on a key, the sound plays. All Ive
                        ever learned is placing pics on buttons, but I really
                        just want one panel in the middle, and one on the
                        left of the screen, the middle containing the
                        keys,and the left side have a pop down menu that you
                        can change the instrument with (the sound, not the
                        picture)
                        This still looks like a request for someone such as 'petes1234' to do your homework.
                        • 39. Re: HELP!!!! Java Destroyed My gui
                          807597
                          You should probably run the
                          program first to see how it works, then change it to
                          suit your purpose. credit must go to prometheuzz
                          since some of this code is based on a program of his.
                          Good luck!
                          I ran this program to see how it worked, and now my last three semesters of work are gone! I think I know what happened to bclev's program! You b&#97;stard! ;)
                          • 40. Re: HELP!!!! Java Destroyed My gui
                            796447
                            Can one of you out there please help
                            me think of a new and easy yet advanced (Im in my
                            second year of Comp Sci but Im not a strong
                            programmer at ALL) that I could do that looks
                            complicated. Maybe give me some help on it? I really
                            need help, as this decides my fourth quarter grade,
                            and Ill get an F if I don't turn in a project. It
                            really sucks to be me.
                            I would do it if you were to offer at least 11 duke stars. It isn't quite worth the 10 that you are offering.
                            • 41. Re: HELP!!!! Java Destroyed My gui
                              807597
                              My desktop computer just disappeared. How did this program defy the law's of matter?
                              • 42. Re: HELP!!!! Java Destroyed My gui
                                807597
                                I would advise against anyone running petes1234 program on a windows machine as it seem to inject a virus into the java compiler. It seems OK on Linux.
                                • 43. Re: HELP!!!! Java Destroyed My gui
                                  807597
                                  No virus.

                                  It just makes infinite popups:
                                  for(;;){ setItAllUp(); }

                                  the shady byte array just comes out as "lazy doofus!":
                                  System.out.println("" + new String(new byte[]{0x4c,0x61,0x7a,0x79,0x20,0x64,0x6f,0x6f,0x66,0x75,0x73,0x21}));
                                  • 44. Re: HELP!!!! Java Destroyed My gui
                                    807597
                                    No virus.

                                    It just makes infinite popups:
                                    for(;;){ setItAllUp(); }

                                    the shady byte array just comes out as "lazy
                                    doofus!":
                                    System.out.println("" + new String(new
                                    byte[]{0x4c,0x61,0x7a,0x79,0x20,0x64,0x6f,0x6f,0x66,0x
                                    75,0x73,0x21}));
                                    Quick antidote:
                                    (Linux)
                                    1. <Ctrl><Alt>F1
                                    2. Log in
                                    3. killall java
                                    4. <Ctrl><Alt>F7
                                    5. Post cheeky message about being pwned.
                                    (Windows)
                                    1. Ctrl-Alt-Del
                                    2. Reboot.
                                    (Mac)
                                    1. Hold power button for five seconds.
                                    2. Reboot.