Link to home
Start Free TrialLog in
Avatar of mcowman
mcowman

asked on

Error when using spring layout - please advise!

When I try to run the below program.  I get the error message "noclassdeffoundError" javax/swing/SpringLayout"
I'm using Java 1_4_2 which should support this layout, I've also tried it on another machine with the same error.  Can anyone tell me whats going wrong
Heres the code - Thanks!!!

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.SpringLayout.*;
import java.util.*;
import java.sql.*;
import java.net.*;


      class Test extends JFrame
            { //class open
            //Step 2:: Global definitions of Panels
            JPanel z1;
            JPanel m1;
            JPanel a1;
            Container cont;
            
            private JButton b1,b2,b3;
            private JLabel l1,l2,l3,addmemberlabel2,addmemberlabel3,addmemberlabel4,addmemberlabel5,addmemberlabel6,addmemberlabel7,addmemberlabel8,addmemberlabel9,addmemberlabel10;
            private JTextField t1,t2,addmembertfield1,addmembertfield2,addmembertfield3,addmembertfield4addmembertfield5,addmembertfield6,addmembertfield7,addmembertfield8,addmembertfield9,addmembertfield10;
            private String username,password,passwordCpr;

      
            boolean databaseConnect= false;
            private java.sql.Connection con=null;


      // Constructor
      public Test()
            { // constructor open
            setTitle("Technofit");
            setSize(250,425); // default is 0,0
            setLocation(10,100); // default is 0,0 (top left corner)
            WindowUtilities.setNativeLookAndFeel();
            databaseConnect();      


                
      //Step 3:: initialise panels
      m1 = new JPanel();
      a1 = new JPanel(new SpringLayout());
      z1 = new JPanel();
      
            //create button      
            b2 = new JButton("Login");
            //create labels
            l2 = new JLabel("Username");
            l3 = new JLabel("Password");
            // create texfields
            t1 = new JTextField(15);
            t2 = new JTextField(15);
            
            //add button as Listener
            b2.addActionListener(new MemberScreen(getContentPane()));
            //add button/texfields/labels to panel
            z1.add(l2);
            z1.add(t1);
            z1.add(l3);
            z1.add(t2);
            z1.add(b2);

         

            // create button
                b1 = new JButton("Add Member ");
                // add button as an event listener
                b1.addActionListener(new MemberAddScreen(getContentPane()));
            // add buttons to current panel
             m1.add(b1);  
                               
     

         
            // create button
            l1 = new JLabel("Firstname ");
            addmemberlabel2 = new JLabel("Lastname");
            addmemberlabel3 = new JLabel("Address1 ");
            addmemberlabel4 = new JLabel("Town ");
            addmemberlabel5 = new JLabel("County ");
            addmemberlabel6 = new JLabel("Height ");
            addmemberlabel7 = new JLabel("phone no ");
            addmemberlabel8 = new JLabel("Age ");
            addmemberlabel9 = new JLabel("Gender");
            addmemberlabel10= new JLabel("Date Registered");
             JTextField addmembertfield1  = new JTextField(15);
            JTextField addmembertfield2  = new JTextField(15);
            JTextField addmembertfield3  = new JTextField(15);
            JTextField addmembertfield4  = new JTextField(15);
            JTextField addmembertfield5  = new JTextField(15);
            JTextField addmembertfield6  = new JTextField(15);
            JTextField addmembertfield7  = new JTextField(15);
            JTextField addmembertfield8  = new JTextField(15);
            JTextField addmembertfield9  = new JTextField(15);
            JTextField addmembertfield10  = new JTextField(15);
            // add button as an event listener
            // add buttons to current panel
            a1.add(l1);
            a1.add(addmembertfield1);
            a1.add(addmemberlabel2);
            a1.add(addmembertfield2);
            a1.add(addmemberlabel3);
            a1.add(addmembertfield3);
            a1.add(addmemberlabel4);
            a1.add(addmembertfield4);
            a1.add(addmemberlabel5);
            a1.add(addmembertfield5);
            a1.add(addmemberlabel6);
            a1.add(addmembertfield6);
            a1.add(addmemberlabel7);
            a1.add(addmembertfield7);
            a1.add(addmemberlabel8);
            a1.add(addmembertfield8);
            a1.add(addmemberlabel9);
            a1.add(addmembertfield9);
            a1.add(addmemberlabel10);
            a1.add(addmembertfield10);
             
         
            

             


            // Add Panels
            Container contentPane = getContentPane();
            //Step 3:: Add Panels to frame
            contentPane.add(z1);
         


            // Window Listener
            addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                  dispose(); //terminates/frees up system resource
                  System.exit(0);
                  } //windowClosing
            } ); //windowAdapter



}  // constructor close
     
      





            //listener class
            class MemberAddScreen implements ActionListener
            { // open class memberadd screen
                        Container cont;
                        public MemberAddScreen(Container c) { // open class member add screen.
                        cont = c;
            } // close class member add screen.
         



            public void actionPerformed(ActionEvent e)
                  {  // open action performed.
                        cont.removeAll();
                        cont.add(a1);
                        ((JComponent)cont).revalidate();
                        ((JComponent)cont).repaint();
                  } //close action performed


            } //close class memberadd screen




            class MemberScreen implements ActionListener
            {
                  String username;
                  String password;
                  String passwordCpr;
                  Container cont;
         
         
            public MemberScreen(Container c) {
                  cont = c;
            }

            

            public void actionPerformed(ActionEvent e)
            {      
                  Container cont;
                  
                  username = t1.getText();
                  password = t2.getText();
                  executeSQL();
            }


                  public void executeSQL(){
                              ResultSet rset = null;
                              int colCount = -1;
                              boolean success = false;
            
                        try
                        {      
                              Statement s = con.createStatement();
                              String sqlStr = "SELECT password FROM Password WHERE username='"+username+"';";      
                              rset = s.executeQuery(sqlStr);            
                              rset.next();
                              passwordCpr = rset.getString(1);
      
                              if(password.compareTo(passwordCpr)==0)
                              {
                                     
                                    
                                      cont.removeAll();
                                      cont.add(m1);
                                      ((JComponent)cont).revalidate();
                                      ((JComponent)cont).repaint();       
                              }
                              else{
                                    l3.setText("Your are not authorised to access");
                                    t1.requestFocus();
                                    t2.setText("");
                                    t2.setText("");
                                    password = "";
                              }

                        }
                        catch (SQLException sqlex)
                        {
                              System.err.println(sqlex.getMessage());
                              success = false;
                        }            }

                        }



      class MainPanel extends JPanel
     {
     
          // members
            private JButton b2;

          // constructors:
            public MainPanel()
          {
               //Container cP = getContentPane();

               //create button      
            b2 = new JButton("Login");
            l2 = new JLabel("Username");
            l3 = new JLabel("Password");
            t1 = new JTextField(20);
            t2 = new JTextField(20);
            //add button as Listener
            b2.addActionListener(new MemberScreen(getContentPane()));
            //add buttons to panel
            z1.add(l2);
            z1.add(t1);
            z1.add(l3);
            z1.add(t2);
            z1.add(b2);

                  setVisible(true);
          } // constructor MainPanel
     } // Class MainPanel



public void databaseConnect()
      {

            String databaseName = null;
                  
            try{
      
                  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                  System.out.println("Found the drivers");
            }
            catch (ClassNotFoundException cnfe){
                  System.err.println(cnfe.getMessage());
                  databaseConnect = false;            
                  return;
            }
            System.out.println("Will try to connect to Database now");
            try{
                  String url ="jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=F:\\pro\\db1.mdb";
                  con = DriverManager.getConnection(url, "", "");
                  databaseConnect = true;
                  System.out.println("Connected to Database");
                  
            }
            catch(SQLException e){
                  System.err.println(e.getMessage());
                  databaseConnect = false;
                  return;
            }
      }


                  


   
     class MemberPanel extends JPanel
     {
     
          // members
            private JButton b1;

          // constructors:
            public MemberPanel()
          {
               
               // create button
                   b1 = new JButton("Add Member ");
                   // add button as an event listener
                   b1.addActionListener(new MemberAddScreen(getContentPane()));
                 

         
                   // add buttons to current panel
                   add(b1);  
                  setVisible(true);
          } // constructor MainPanel
     } // Class MainPanel

     class AddMemberPanel extends JPanel
     {
     
          // members
            private JLabel l1,addmemberlabel2,addmemberlabel3,addmemberlabel4,addmemberlabel5,addmemberlabel6,addmemberlabel7,addmemberlabel8,addmemberlabel9,addmemberlabel10;
            private JTextField ddmembertfield1,addmembertfield2,addmembertfield3,addmembertfield4addmembertfield5,addmembertfield6,addmembertfield7,addmembertfield8,addmembertfield9,addmembertfield10;
          
        
          
            
          // constructors:
            public AddMemberPanel()
          {
               
             SpringUtilities.makeCompactGrid(a1,
                                        9, 2, //rows, cols
                                        6, 6,        //initX, initY
                                        6, 6);       //xPad, yPad

      
               // create button
                 l1 = new JLabel("Firstname ");
            addmemberlabel2 = new JLabel("Lastname");
            addmemberlabel3 = new JLabel("Address");
            addmemberlabel4 = new JLabel("Town");
            addmemberlabel5 = new JLabel("County");
            addmemberlabel6 = new JLabel("Height");
            addmemberlabel7 = new JLabel("Phone no");
            addmemberlabel8 = new JLabel("Age ");
            addmemberlabel9 = new JLabel("Gender");
            addmemberlabel10 = new JLabel("Date Registered");
            JTextField addmembertfield1  = new JTextField(15);
            JTextField addmembertfield2  = new JTextField(15);
            JTextField addmembertfield3  = new JTextField(15);
            JTextField addmembertfield4  = new JTextField(15);
            JTextField addmembertfield5  = new JTextField(15);
            JTextField addmembertfield6  = new JTextField(15);
            JTextField addmembertfield7  = new JTextField(15);
            JTextField addmembertfield8  = new JTextField(15);
            JTextField addmembertfield9  = new JTextField(15);
            JTextField addmembertfield10  = new JTextField(11);
               // add buttons to current panel
               
            
            add(l1);
            add(addmembertfield1);
            add(addmemberlabel2);
            add(addmembertfield2);
            add(addmemberlabel3);
            add(addmembertfield3);
            add(addmemberlabel4);
            add(addmembertfield4);
            add(addmemberlabel5);
            add(addmembertfield5);
            add(addmemberlabel6);
            add(addmembertfield6);
            add(addmemberlabel7);
            add(addmembertfield7);
            add(addmemberlabel8);
            add(addmembertfield8);
            add(addmemberlabel9);
            add(addmembertfield9);
            add(addmemberlabel10);
            add(addmembertfield10);                   
              } // constructor MainPanel
     
      } // Class MainPanel



   
     public static void main(String[] args) {
              JFrame frame1 = new Test();
              frame1.show();
       } ;
} // class close
SOLUTION
Avatar of Daniel Junges
Daniel Junges
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mcowman
mcowman

ASKER

Junges,
Just tried this and I got the same message, Any ideas???
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think your SringLayout.class file is corrupted or non-exist on the CLASSPATH.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial