3 Replies Latest reply: Apr 22, 2013 7:24 AM by TPD-Opitz RSS

    button event handling JFrame

    993724
      I have created a code on NETBEANS IDE contains JFrame that holds some jTextfields and some buttons
      for a certain button I wanted it to add a panel over the same frame contains JTextFields and JComboBoxes, I've written the following code in the implementing method for this button

      private void addActionPerformed(ActionEvent evt)
      {
      JPanel panel = new JPanel();
      panel.getContentPane().add(new JButton("job list");
      panel.getContentPane().add(new JTextField());
      JTextField.setText("job description");
      revalidate();
      repaint();
      }
      but when it executes, nothing appeared on the JFrame, how I could make this work to add as many panels on the same frame each time I pressed that add button
      please, I want the answer as it facilitate my job working on the NETBEANS as the desired layout is got for the created panel.

      the main method exists in other class called joblistTest which declares the first class object

      thank you for your time to the best forum ever for java

      Edited by: Mohamad Samy on Apr 21, 2013 8:39 PM
        • 1. Re: button event handling JFrame
          TPD-Opitz
          Mohamad Samy wrote:
          I have created a code on NETBEANS IDE contains JFrame that holds some jTextfields and some buttons
          for a certain button I wanted it to add a panel over the same frame contains JTextFields and JComboBoxes, I've written the following code in the implementing method for this button
          What does that mean?
          In which class did you put this method?
          private void addActionPerformed(ActionEvent evt)
          This is not the correct signature for the <tt>ActionListener</tt> interface. Thie method must be <b>public</b>.
          So you most likely did not declare your class beeing an <tt>ActionListener</tt>. This also implies that you did not register your class as <tt>AlctionListener</tt> with the Button in question. You would have compile errors otherwise.

          bye
          TPD
          • 2. Re: button event handling JFrame
            993724
            the method is correct, it is generated automatically by NETBEANS and couldn't be modified
            also, the program is compiled without any errors but when clicking the add button nothing appeared on the JFrame.

            the following code is generated in initComponent() at the class constructor

            addJobButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            addJobButtonActionPerformed(evt);

            then the following method is generated to write my handling code but in vain

            private void addJobButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
            // TODO add your handling code here:
            }

            I want what code to be written in this method, so each time I press the add button the needed buttons and textfields are obtained in the same JFrame

            Edited by: Mohamad Samy on Apr 22, 2013 4:46 AM
            • 3. Re: button event handling JFrame
              TPD-Opitz
              Mohamad Samy wrote:
              the method is correct,
              With respect to the ActionListener Interface: no.
              it is generated automatically by NETBEANS and couldn't be modified
              I'ts hard to beleve either one of this statement.
              also, the program is compiled without any errors
              This I do beleve.
              but when clicking the add button nothing appeared on the JFrame.

              the following code is generated in initComponent() at the class constructor

              addJobButton.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
              addJobButtonActionPerformed(evt);

              then the following method is generated to write my handling code but in vain

              private void addJobButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
              // TODO add your handling code here:
              }

              I want what code to be written in this method, so each time I press the add button the needed buttons and textfields are obtained in the same JFrame
              What prevents you from doing so?
              At first you should replace the comment with a log output, to see that you'r really getting here.
              If this is aproved add more Code to create the desired functionality.


              bye
              TPD