LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-25-2007, 04:59 PM   #1
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Rep: Reputation: 30
java super() main class


Hello all,
I know that there are probably a million posts about this however I can not find any that can answer my question.
I have two forms in Netbeans( Java ) one of the frames loads up another to enter a text address but the information is not passed back to the main form.

I have tried to use the super() function but it just passes a NullPointerException. I think that I'm close but haven't quite got it:


main.java:
Code:
public class main extends javax.swing.JFrame 
{   

    private winTwo           winTwo      = new winTwo();


    public main() 
    {
        
        super( "main" );
        
        initComponents();
        
        
    }


    private void initComponents() 
    {

        // some generic components

    }

    
    private void button(java.awt.event.ActionEvent evt) 
    {

        winTwo ss = new winTwo( this );
        
        ss.main( null );

    }    


    public void setName( String name )
    {

        System.out.println( "Set name: " + name );

    }


}

winTwo.java:
Code:
public class serverSettings extends javax.swing.JFrame 
{
    
    private static helpClient              parent      = null;

    
    public serverSettings( JFrame parent, String s )
    {
        
        super( s );
        
        initComponents();
        
    }
    
    
    public serverSettings( JFrame parent )
    {
        
        super();
        
    }


    private void btnAccept(java.awt.event.ActionEvent evt) 
    {                                          
        
        parent.setName( "Hello World" );
        
    }      



    public static void main( String args[] )
    {
        
        java.awt.EventQueue.invokeLater( new Runnable() 
        {
            
            public void run() 
            {
                
                main Main = new main( parent );
                
                Main.setVisible( true );
                
            }
            
        } );
}

Last edited by trscookie; 09-26-2007 at 03:27 AM.
 
Old 09-26-2007, 02:10 PM   #2
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Original Poster
Rep: Reputation: 30
there have got to be some java programmers out there
 
Old 09-26-2007, 05:34 PM   #3
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Original Poster
Rep: Reputation: 30
here is a better example:

Code:
package multiForm;



public class frameOne extends javax.swing.JFrame 
{
    
    private static frameTwo two     = new frameTwo();
    
    
    
    public frameOne() 
    {
    
        initComponents();
        
    }
    
    
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jButton1.setText("Click Me!");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel1.setText("Should Change");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addContainerGap())
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        
        two.setVisible( true );
        
    }//GEN-LAST:event_jButton1ActionPerformed
    
    
    public static void main( String args[] ) 
    {
        
        java.awt.EventQueue.invokeLater( new Runnable() 
        {
            
            public void run() 
            {
                
                new frameOne().setVisible( true );
                
            }
            
        } );
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration//GEN-END:variables
    
}



Code:
package multiForm;



public class frameTwo extends javax.swing.JFrame 
{
    
    
    public frameTwo() 
    {
        
        initComponents();
        
    }
    
    
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jTextField1 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jTextField1.setText("Set label on frame one");

        jButton1.setText("send text");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        
        String s = jTextField1.getText();
        
        
        // the string should be sent to the first class and set the label here
        // i have tried to used the functions super and parent but i cant get them to work :(
        
        
        this.dispose();
        
    }//GEN-LAST:event_jButton1ActionPerformed
    
    
    public static void main( String args[] ) 
    {
        
        java.awt.EventQueue.invokeLater( new Runnable() 
        {
            
            public void run() 
            {
                
                new frameTwo().setVisible( true );
                
            }
            
        } );
        
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
    
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception in thread "main" java.lang.ClassFormatError: onmyown.Main (unrecognized cla zimboney Fedora 4 07-20-2007 01:00 PM
Error:Failed to load Main-Class manifest attribute from imgbpatch.jar xbc Ubuntu 0 02-18-2007 03:37 PM
'Failed to load Main-Class manifest' while installing JMF on Fedora5 polemon Linux - Software 0 10-27-2006 09:22 AM
C++ Compiling single class without a main() harshnoise Programming 4 08-29-2005 04:59 PM
Array declaration in class or main function??? redhatrosh Programming 4 03-15-2005 02:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration