Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-07-2007, 01:13 PM
Member
 
Join Date: Jul 2007
Posts: 8
java_newbie is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-07-2007, 02:51 PM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
Quote:
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.

Quote:
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:

Code:
MyJDialog myDialog = new MyJDialog(this); myDialog.setVisible(true);
Hope this helps..
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-07-2007, 09:38 PM
Member
 
Join Date: Jul 2007
Posts: 8
java_newbie is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-07-2007, 10:25 PM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-08-2007, 02:07 PM
Member
 
Join Date: Jul 2007
Posts: 8
java_newbie is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 07-08-2007, 02:33 PM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
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:

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.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 07-08-2007, 08:11 PM
Member
 
Join Date: Jul 2007
Posts: 8
java_newbie is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 07-08-2007, 09:58 PM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
Quote:
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.

Quote:
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.

Quote:
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!
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 07-13-2007, 12:36 AM
Member
 
Join Date: Jul 2007
Posts: 8
java_newbie is on a distinguished road
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 ....

Quote:
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
Quote:
rVal=eChooser.showOpenDialog(this);
Any help pls...

Thanks
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 07-13-2007, 01:27 AM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
eChooser should be null. Make sure it points to a created object.
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 07-13-2007, 01:52 AM
Member
 
Join Date: Jul 2007
Posts: 8
java_newbie is on a distinguished road
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...
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 08-06-2007, 05:43 PM
Member
 
Join Date: Aug 2007
Posts: 3
sixohseven is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 08-06-2007, 06:14 PM
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 08-06-2007, 06:30 PM
Member
 
Join Date: Aug 2007
Posts: 3
sixohseven is on a distinguished road
Where the dialog is called/created:
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:
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?
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 08-06-2007, 08:19 PM
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
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..
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Full Forms of Java Tech Gajesh Tripathi New To Java 1 10-18-2007 10:59 AM
Creating JUnit Test Cases using NetBeans JavaForums Java Blogs 0 08-06-2007 06:30 PM
Creating a Session Ejb in NetBeans IDE JavaForums NetBeans 0 07-31-2007 12:13 AM
Creating J2ee Modules In NetBeans IDE JavaForums NetBeans 0 07-31-2007 12:13 AM
Migration from oracle forms to java Nick15 Advanced Java 3 05-12-2007 08:00 AM


All times are GMT +3. The time now is 12:18 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org