Results 1 to 15 of 15
  1. #1
    java_newbie is offline Member
    Join Date
    Jul 2007
    Posts
    8
    Rep Power
    0

    Default Creating Sub forms in java netbeans 5.0

    Hi all,

    you guys didnt helped me in my last post...
    But i am expecting lil help this time...

    How can i create sub forms in java netbeans 5.0..
    for instance i have a parent form and from parent form i press a button which opens a new form...So how to manage this functionality....

    waiting for reply...

    Thanks
    java newbie

  2. #2
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    you guys didnt helped me in my last post...
    I guess you already found solution to that problem since you are using Netbeans GUI Builder. :)

    for instance i have a parent form and from parent form i press a button which opens a new form...So how to manage this functionality....
    Design these forms separately. I guess the first one is a JFrame and the second one will be a JDialog.

    Create a new JDialog form. (File -> New File -> Java GUI Forms -> JDialog Form). Design it just like you did for JFrame by drag and drop. And then from the mouseClicked event of your button in the first form, create a new instance of your JDialog and show it. Like this:

    Java Code:
    MyJDialog myDialog = new MyJDialog(this);
    myDialog.setVisible(true);
    Hope this helps.. ;)

  3. #3
    java_newbie is offline Member
    Join Date
    Jul 2007
    Posts
    8
    Rep Power
    0

    Default

    HI
    its not detecting the new JDialog class...do i hv to include namespace or something...

    this is what i have done

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

    JDialog myJDialog = new JDialog(this);
    myJDialog.setVisible(true);


    }

    but its giving error cannot find symbol...i created JFrame, dragged one button and created JDialog ...Now the code of JFrame button is shown above...how to solve this problem...

    Thanks a lot

  4. #4
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    You are trying to create a new object from JDialog class. But you have a new class which extends JDialog! You should use the name of your class there. And make sure that these two classes are in the same package. If not you need to add correct import statements to your JFrame class so that JVM can find your JDialog class.

  5. #5
    java_newbie is offline Member
    Join Date
    Jul 2007
    Posts
    8
    Rep Power
    0

    Default

    oh i am so confused about this now...well i dont understand how to proceed and there are no tutorials about this....can you explain me from step one till end of creating subforms...
    Like with a start of new project file...it gives default package...So what to add and what not..do i simply add JFrame and JDialog....and write code in JFrame button action performed section ..or wt...pls explain me this from scratch or refer me some good article where they discuss this issue..i.e to create sub forms...
    thanks

  6. #6
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    First of all you need to read/see all tutorials/demos here:

    Java GUIs and Project Matisse Learning Trail
    form: Homepage

    The above tutorials/demos will help you in the long term even if they might not help with your current problem.

    And for this problem, as far as i see the confusion is because of that you cant understand the relation between a Java form and a Java class.

    First of all Netbeans GUI builder is just a tool which helps you design your GUI forms. If you do not use Netbeans GUI builder, you had to write your code without immediate visual feedback. (You will need to write codes which are written automatically by Netbeans GUI builder, and run the code to see the results. But you can see them immediately now with the help of Netbeans GUI builder.)

    So without Netbeans GUI builder, the first thing you will need to do for your JDialog class is to write a class which extends JDialog class:

    Java Code:
    class MyJDialog extends JDialog {
    
       ...
    
    }
    In this way, you are getting all functionality of a JDialog but also have the ability to change the behavior of this class base on your needs.

    So what Netbeans GUI builder does at the background while you create a new JDialog form. (File -> New File -> Java GUI Forms -> JDialog Form)? Lets assume that you gave MyJDialog as the name of your JDialog Form. In that case Netbeans GUI builder creates two files:

    MyJDialog.java -> This is what Java needs! It has a class named MyJDialog which extends JDialog just like the above code lines.

    MyJDialog.form -> This is not needed by Java compiler. It is needed by Netbeans GUI builder to allow you to change your form later.

    For both of these files Netbeans shows you one file and allow you to view it in two modes: Visual and Code.

    When you open your JDialog, check the top left corner of the editor, you will see two buttons for these modes. When you click on "Code" button, you will see your JDialog in Code mode and i think you will understand what i mean if you already studied object oriented programming and read/watch the tutorials/demos above!

    If you still can not solve your problem after these information, write the name of your JDialog class here, i will give you the lines you needed in your button action.

  7. #7
    java_newbie is offline Member
    Join Date
    Jul 2007
    Posts
    8
    Rep Power
    0

    Default

    Now a bit of it is working...
    Ok ill explain what i did...

    well i created new project. and then i started with creating JFrame giving it a name Parent. Now i got source coulumn and design coloumn.

    Under design option i designed the form with one menu button and 1 menu item and the click of that menu item i want to have a sub form open.

    Now before i write a code for that menu item button i created new file...i.e new JFrame with a name "Coder" and it got same source and design option...So similarly i designed the Coder GUI but at the moment i just designed it. i have not given any functionality to it....

    So now getting back to Parent class...under button action section for that menu item i wrote as follows

    public class Parent extends javax.swing.JFrame {

    public static Parent p1;
    public static Coder blow1;

    /** Creates new form Parent */
    public Parent() {
    initComponents();
    }
    ---
    ------
    contd.
    --------- and then code under button action performed is

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

    TestProject.Parent.blow1 = new Coder();
    // TestProject.Parent.p1.setVisible(false);
    TestProject.Parent.blow1.setSize(500,450);
    TestProject.Parent.blow1.setVisible(true);

    }

    So now when i run Parent.Java form ...and click the menu item i am getting the sub form but i also want that the Parent form should go invisible so when i write TestProject.Parent.p1.setVisible(false); it gives me many exceptions...

    any idea why is it doing this and now i am about to start writing code for the sub form....but pls let me know if my approach is right...and why the form is not going invisible...

    and one more thing...do we have to edit manifest file or no....may be its something to do with that file...i am not sure..when is that file used...

    Thanks

  8. #8
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    TestProject.Parent.blow1 = new Coder();
    This naming is strange. What are you doing? Are you designing all these classes as inner class of TestProject class? There is something wrong here. You should design your classes as separate Java classes/files if you don't have any special reason.

    and one more thing...do we have to edit manifest file or no....may be its something to do with that file.
    I guess you mean the manifest file in your executable jar. If you don't need something need to be done via manifest file, you would better not to touch it. :)

    so when i write TestProject.Parent.p1.setVisible(false); it gives me many exceptions...
    Tell us detailed information about the exception.

    And one more thing. Please use [code] tag around your code blocks. That will make them easier to read!

  9. #9
    java_newbie is offline Member
    Join Date
    Jul 2007
    Posts
    8
    Rep Power
    0

    Default

    Ok ill continue with the last problem later...
    I got another probs...Well i am trying to rewrite this encryption application...

    Well i got 2 JFrame and rest are JDialogs...well i am new to Java so i am just copying what the other guy did but it is becoming bit tedious at times...

    Well now from the main parent Jframe i click on button cryptography... now it goes to another jframe and opens another form where all encryption decryption button are available...now when i click on encryption button nothing is happening whereas according to code it should give me open file dialog box...just have a look over the code ....

    private void encryptButtonActionPerformed(java.awt.event.Action Event evt) {
    // TODO add your handling code here:

    int vVal=0;
    int rVal=0;
    state=CipherMethods.ENCRYPT;
    outString="\n"+"Ready"+"\n";
    PasswordDialog pDialog= new PasswordDialog(this,true);
    rVal=eChooser.showOpenDialog(this);
    if (rVal==JFileChooser.APPROVE_OPTION){
    inputFile=eChooser.getSelectedFile();
    pChooser.setFileSelectionMode(JFileChooser.DIRECTO RIES_ONLY);
    if(this.samePathCheck.isSelected()){
    outDirectory=new File(inputFile.getParent());
    }else{
    vVal=pChooser.showOpenDialog(this);
    outDirectory=pChooser.getSelectedFile();
    }
    pDialog.show();
    System.out.println("key from coder is "+keyString);
    //pass the input file to the Cipher Methods class for encryption
    CipherMethods cipherm=new CipherMethods(inputFile,outDirectory,keyString,sta te,deleteCheck.isSelected());

    //Start the Monitor cipher class to monitor the progress of the ecryption operation
    MonitorCipher mc=new MonitorCipher(cipherm);
    cipherm.start();
    mc.start();



    }


    }
    So could you see any problem in this code...and same is for decryption aswell...
    and yeh its giving me exception i.e.
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at line
    rVal=eChooser.showOpenDialog(this);
    Any help pls...

    Thanks

  10. #10
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    eChooser should be null. Make sure it points to a created object.

  11. #11
    java_newbie is offline Member
    Join Date
    Jul 2007
    Posts
    8
    Rep Power
    0

    Default

    Thanks fr reply but ...

    What do you mean by echooser should be null..
    well defination of echooser is
    protected JFileChooser eChooser;

    And yeh all the objects are avaiable by intellisence after eChooser. So it points to right objects i guess..and moreover this application works fine ..So i dont think there is anything wrong in code but i dont know what am i missing...

  12. #12
    sixohseven is offline Member
    Join Date
    Aug 2007
    Posts
    3
    Rep Power
    0

    Default The Next Step

    I was struggling a little bit with this issue also, but the directions above were pretty clear. So, now I've got a button (or menu item, or anything else I want) that will open a simple modal dialog. However, what is considered "best practice" for returning a value to the calling class? I'm opening a dialog to retrieve a string value and when the user clicks "OK" the string needs to return to the calling class before I call dispose() on the dialog.

    Any examples available to look at, or advice to share? Thanks.

  13. #13
    levent Guest

    Default

    What do you mean with calling class? If it is the class where you show your dialog. It already returns the value as return value of showXXX method.

  14. #14
    sixohseven is offline Member
    Join Date
    Aug 2007
    Posts
    3
    Rep Power
    0

    Default

    Where the dialog is called/created:
    Java Code:
        private void displayMessageButtonMouseClicked(java.awt.event.MouseEvent evt) {                                                  
            GenericDialog myDialog = new GenericDialog(this, true);
            myDialog.changeLabel("Text to Display:");
            myDialog.setVisible(true);
            // would like to get the value of a text field here
            String response = myClass.displayMessage(<<response from dialog should go here>>);
            logTextArea.append(new java.util.Date().toString() + " :: displayMessage :: " + response + '\n');
    
        }
    Where the dialog is closed/disposed:
    Java Code:
        private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
            this.dispose();
        }
    What should be added to either of those methods to return the value of a text field in the dialog?

  15. #15
    levent Guest

    Default

    Check showMessageDialog and showOptionDialog examples here. Each returning an int as the result of the selection. Similarly, you can return an object or just a String or int from your dialogs. This way, you will not need to implement this on your application classes and this implementation will be hidden inside your JDialog implementation.

    I am not sure how this is implemented in JDK. You might try looking at the source code of JOptionPane class. I tried to find source code of it but could not find it in a limited time..

Similar Threads

  1. Full Forms of Java Tech
    By Gajesh Tripathi in forum New To Java
    Replies: 1
    Last Post: 10-18-2007, 10:59 AM
  2. Creating a Session Ejb in NetBeans IDE
    By JavaForums in forum NetBeans
    Replies: 0
    Last Post: 07-31-2007, 12:13 AM
  3. Creating J2ee Modules In NetBeans IDE
    By JavaForums in forum NetBeans
    Replies: 0
    Last Post: 07-31-2007, 12:13 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
  •