?
Solved

Newbie needs some help

Posted on 2003-03-18
9
Medium Priority
?
182 Views
Last Modified: 2010-03-31
Hey pro's

I'm pretty new to programming and I need a little help with my developing. So far i've been putting all my code into one class. That does not produce very "friendly" code. But I'm having some problems splitting my code into different classes and using them together.
An example: I've made a simple app called Manager wich when run are supposed to call a simple dialog-panel wich askes the user for login and password. This dialog I want to put in a sepatate class. This ain't working.
Code:
public class ZoonOnManager extends JPanel implements ActionListener
{
    .
    .
    public static void main(String[] args)
    {
    .
    .
    }
    public ZoonOnManager()
    {
        TestDialog testdialog = new TestDialog(this);
    }
}
//Dialog code
class TestDialog extends JDialog
 {
     // Instance attributes used in this dialog
     private     JFrame          parentFrame;
     private     JScrollPane     scrollPane1;


     // Dialog constructor
     public TestDialog( JFrame parentFrame )
     {
          // Make sure we call the parent
          super( parentFrame );

          // Save the owner frame in case we need it later
          this.parentFrame = parentFrame;

          // Set the characteristics for this dialog instance
          setTitle( "Test Dialog" );
          setSize( 200, 200 );
          setDefaultCloseOperation( DISPOSE_ON_CLOSE );


          // Create a panel for the components
          JPanel topPanel = new JPanel();
          topPanel.setLayout( new BorderLayout() );
          getContentPane().add( topPanel );

         
     }

}
I know this is elementary, but I can't seem to get a grip on it. Some input would be appreciated.
THNX
0
Comment
Question by:taniar
9 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 8159290
public ZoonOnManager()
{
  TestDialog testdialog = new TestDialog( this );
  testdialog.show() ;
}

.... and then...

 public TestDialog( JFrame parentFrame )
 {
   // Make sure we call the parent
   super( parentFrame, "login Window", true );
0
 
LVL 1

Accepted Solution

by:
pronane earned 80 total points
ID: 8159310
Im not sure on this, but if you are passing a frame do you not have to pass the frame or have that class extend Jframe, your zoonmanager class extends jpanel, but you are not using a jframe you are using a jpanel, so should you not be extending jframe when you pass "this".
0
 

Expert Comment

by:krazeegook
ID: 8159375
First of all, it's not a good practice to pass GUI components around as arguments.

Second, passing in a GUI component does not automatically display that component on the screen. You must:

add these two lines at the end of TestDialog Constructor after getContentPane().add( topPanel );

pack();
setVisible(true);

or

after creating the TestDialog object call show() as follow:
   
public ZoonOnManager()
{
   TestDialog testdialog = new TestDialog(this);
   testdialog.show()
}




Besides that, you have JFrame as argument for constructor of TestDialog.("public TestDialog( JFrame parentFrame )
"), but you're passing in a JPanel. ZoonOnManager should extend JFrame.

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:taniar
ID: 8159482
>TimYates

I'm getting compilation errors in ZoonOnManager class when doing what you posted. Cannot resolve symbol on this line: TestDialog testdialog = new TestDialog( this );
It doesnt seem to like the class TestDialog
     
0
 

Author Comment

by:taniar
ID: 8159603
Actually this error comes if I try the other solutions as well. Any ideas?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 8159709
Like pronane says, you need to pass a JFrame to the constructor of JDialog

You are passing "this" which is an instance of JPanel

You need to pass the main application frame, so you can do this:

JFrame getParentFrame( Component c )
{
  while( ( c != null ) && !( c instanceof JFrame ) )
    c = c.getParent() ;
  return c ;
}

then, construct your dialog by doing this:

TestDialog testdialog = new TestDialog( getParentFrame( this ) );

0
 

Author Comment

by:taniar
ID: 8159724
I have to abandon my post, but please post any any possible solutions and I will get back to you.
0
 

Author Comment

by:taniar
ID: 8236893
Thnx, sorry about the late answer. I've been to hospital. Thnx to everyone else that replied to, good to see experienced programmers helping a wannabe along;).
0
 
LVL 35

Expert Comment

by:TimYates
ID: 8236905
hope ur better :-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month9 days, 12 hours left to enroll

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question