Results 1 to 3 of 3
  1. #1
    kryptonian03 is offline Member
    Join Date
    Dec 2010
    Posts
    18
    Rep Power
    0

    Question How to pass values from frames..

    Good day!

    I hava a simple GUI java program built in Netbeans.. I was wondering how could i pass the value of a string to the next frame?

    I have attached my code so that you can view my files... Thank you very much!
    Attached Files Attached Files

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by kryptonian03 View Post
    Good day!

    I hava a simple GUI java program built in Netbeans..

    You're learning how to code Swing, so it's probably a mistake for you to let NetBeans create your GUI code for you. I suggest you do it by hand at this stage and then later when you know how Swing works, sure, let NetBeans create some code for you.


    I was wondering how could i pass the value of a string to the next frame?
    This should probably be clarified. The more effort you put into helping us understand your problem the easier we'll be able to help you.


    I have attached my code so that you can view my files... Thank you very much!
    More will look at your code if you post the actual code itself in the forum (with code tags -- please see my link about this below) rather than as an attachment. Another problem with NetBeans is that the code it produces is quite bloated, making it hard for others to read your code -- another reason to code by hand.

    Much luck!

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    OK, I'll be more direct and see if that will help get a response: what information are you trying to pass from one GUI to another?

    and as a non-NetBeans GUI example:

    Java Code:
    import java.awt.Window;
    import java.awt.Dialog.ModalityType;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.*;
    
    public class JavaAtmBrief {
    
       private static void createAndShowUI() {
          JFrame frame = new JFrame("ATM");
          frame.getContentPane().add(new AtmPanel());
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
       }
    
       public static void main(String[] args) {
          java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
                createAndShowUI();
             }
          });
       }
    }
    
    class AtmPanel extends JPanel {
       private JTextField acctNumberField = new JTextField(10);
       private JButton okBtn = new JButton("OK");
    
       public AtmPanel() {
          okBtn.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                okBtnActionPerformed();
             }
          });
          add(acctNumberField);
          add(okBtn);
       }
    
       private void okBtnActionPerformed() {
          DialogPanel dialogPanel = new DialogPanel(acctNumberField.getText());
    
          Window win = SwingUtilities.getWindowAncestor(this);
          JDialog dialog = new JDialog(win, "Dialog", ModalityType.APPLICATION_MODAL);
          dialog.getContentPane().add(dialogPanel);
          dialog.pack();
          dialog.setLocationRelativeTo(null);
          dialog.setVisible(true);
       }
    }
    
    class DialogPanel extends JPanel {
       private String acctNumber;
    
       // gui's constructor accepts a String
       public DialogPanel(String acctNumber) {
          this.acctNumber = acctNumber; // that initializes a field
          add(new JLabel("Account Number: " + acctNumber)); // and is displayed
    
          add(new JButton(new AbstractAction("Close") {
             @Override
             public void actionPerformed(ActionEvent e) {
                Window win = SwingUtilities.getWindowAncestor(DialogPanel.this);
                win.dispose();
             }
          }));
       }
    
    }
    Last edited by Fubarable; 05-06-2011 at 09:32 PM.

Similar Threads

  1. how to pass values from jsp to servlet
    By jksathya in forum Eclipse
    Replies: 1
    Last Post: 02-01-2011, 09:13 AM
  2. Replies: 14
    Last Post: 01-22-2011, 02:36 PM
  3. Pass Values into 2D Array?
    By noble in forum New To Java
    Replies: 7
    Last Post: 11-09-2010, 07:30 AM
  4. Replies: 0
    Last Post: 05-22-2008, 10:53 AM

Posting Permissions

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