Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error when using spring layout - please advise!

Posted on 2004-03-29
6
Medium Priority
?
338 Views
Last Modified: 2008-03-06
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
0
Comment
Question by:mcowman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 14

Assisted Solution

by:Daniel Junges
Daniel Junges earned 800 total points
ID: 10706075

change
-->import javax.swing.SpringLayout.*;
 to
-->import javax.swing.SpringLayout;
0
 

Author Comment

by:mcowman
ID: 10706138
Junges,
Just tried this and I got the same message, Any ideas???
0
 
LVL 14

Accepted Solution

by:
Daniel Junges earned 800 total points
ID: 10706449

I leave you code unchanged, it compiles and run without this error. After start, an login panel is showed.
Question: the error appear before or after press login button?

if you answer is before, than check you java version again. I hava used the follow version:

java -version
java version "1.4.2_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)
0
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
LVL 5

Assisted Solution

by:twobitadder
twobitadder earned 400 total points
ID: 10706457
Your first problem should have been sorted by junges and the errors should be different....

SpringUtilities isn't in the java api, it's a class that's created in the SpringLayout tutorial.

http://java.sun.com/docs/books/tutorial/uiswing/layout/spring.html
They have a link to the source for it.

0
 
LVL 16

Expert Comment

by:gnoon
ID: 10710478
I think your SringLayout.class file is corrupted or non-exist on the CLASSPATH.
0
 
LVL 16

Assisted Solution

by:gnoon
gnoon earned 400 total points
ID: 10710490
typo: SringLayout.class     --->     SpringLayout.class
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

715 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