Affichage des articles dont le libellé est class. Afficher tous les articles
Affichage des articles dont le libellé est class. Afficher tous les articles

Change Class Name Using Javascript

How To Change DIV Class Name In Javascript

change classname using javascript



In This Javascript Tutorial we will see How To Change DIV Css Class Name In JS Using Netbeans Editor .




Project Source Code:

<!DOCTYPE html>
<html>
    <head>
        <title>JavaScript Tutorial: Change Div Class Name</title>
        <meta charset="windows-1252">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        
        <style>
            
            .DefaultClass{
                width: 200px;
                height: 200px;
                background-color: #000;
                margin-bottom: 20px;
            }
            
            .class1{
                width: 200px;
                height: 200px;
                background-color: red;
                margin-bottom: 20px;
            }
            
            .class2{
                width: 200px;
                height: 200px;
                background-color: green;
                margin-bottom: 20px;
            }
            
        </style>
        
        <script>
            
            function func1()
            {
                document.getElementById('cls').className = "class1";
            }          
            
            function func2()
            {
                document.getElementById('cls').className = "class2";
            }
            
        </script>
        
    </head>

    <body>
        
        <div class="DefaultClass" id="cls"></div>
        <button onclick="func1();">Class 1</button>
        <button onclick="func2();">Class 2</button>

    </body>
</html>




JAVA - How To Use HashMap With Class In Java NetBeans

JAVA Collection - Using HashMap With Class As Value In Java NetBeans

                                                                                                                                                            
using hasmap with your own class in java



In this java Collection Code we will see How To Use HashMap With Our Class As Value In Java NetBeans 


Source Code:

package javaapp;

import java.util.HashMap;

 // Creat a class
   class User{
       private int id;
       private String name;
       
       public User(){}
       
       public User(int _id,String _name){
          this.id = _id;
          this.name =_name;
       }
       
       public int getId(){
           return this.id;
       }
       
       public String getName(){
           return this.name;
       }
       
       public void setId(int id){
           this.id = id;
       }
       
       public void setName(String name){
           this.name = name;
       }
       
// create a tostring methode
       public String ToString(){
           return "ID = "+id+"  NAME = "+name ;
       }
   }

public class Woirk {

    
    public static void main(String[] args){

        HashMap<Integer,User> userList = new HashMap<Integer,User>();

// filling the HashMap with put method
        userList.put(10, new User(1,"omar"));
         userList.put(21, new User(2,"bilal"));
          userList.put(32, new User(3,"kamal"));
           userList.put(43, new User(4,"rachid"));
            userList.put(54, new User(5,"rami"));
             userList.put(65, new User(6,"karim"));
             
// create another hashmap
      HashMap<Integer,User> userList2 = new HashMap<Integer,User>();
        userList2.put(53, new User(62,"khalid"));
          userList2.put(25, new User(18,"mounir"));
          
// replace element in hashmap
        userList.replace(10, new User(100,"tarik"), new User(1,"omar"));

        // insert a map elements in another map
        userList.putAll(userList2);

        printAllData(userList);

        userList.remove(3);
        
        printAllData(userList);
          
        User u = userList.replace(10, new User(8,"morad"));
        
        printAllData(userList);
        
        userList.put(400,null);

/*
       If the specified key is not associated with a value
       or the value is null associates it with the given value                        in this example  the key is 400 and value is null
*/
        userList.putIfAbsent(400, new User(19,"TEXT"));
      
        printAllData(userList);
        
       User us = userList.getOrDefault(400,null);
       System.out.println(us.ToString());
     

      User u1 = userList.get(54);
      User u2 = new User(600, "TheNewUser");
  
    System.out.println("---------------------");
    printAllData(userList);
   userList.remove(54, u1);
       printAllData(userList);
   
    System.out.println("Size: "+userList.size());
    userList.clear();
    System.out.println("The userList is Empty: "+userList.isEmpty());
  }  
    
    // method to print hashmap data
    public static void printAllData(HashMap<Integer,User> list){
      for(Integer i : list.keySet())
        {
          System.out.println(list.get(i).ToString());
        }
      System.out.println("----------------------");
    }
    
 // method to print hashmap keys
    public static void printKeys(HashMap<Integer,User> list){
      for(Integer i : list.keySet())
        {
          System.out.println(i);
        }
      System.out.println("----------------------");
    } 
}

//OUTPUT:

ID = 3  NAME = kamal
ID = 6  NAME = karim
ID = 2  NAME = bilal
ID = 62  NAME = khalid
ID = 5  NAME = rami
ID = 18  NAME = mounir
ID = 1  NAME = omar
ID = 4  NAME = rachid
----------------------
ID = 3  NAME = kamal
ID = 6  NAME = karim
ID = 2  NAME = bilal
ID = 62  NAME = khalid
ID = 5  NAME = rami
ID = 18  NAME = mounir
ID = 1  NAME = omar
ID = 4  NAME = rachid
----------------------
ID = 3  NAME = kamal
ID = 6  NAME = karim
ID = 2  NAME = bilal
ID = 62  NAME = khalid
ID = 5  NAME = rami
ID = 18  NAME = mounir
ID = 8  NAME = morad
ID = 4  NAME = rachid
----------------------
ID = 3  NAME = kamal
ID = 19  NAME = TEXT
ID = 6  NAME = karim
ID = 2  NAME = bilal
ID = 62  NAME = khalid
ID = 5  NAME = rami
ID = 18  NAME = mounir
ID = 8  NAME = morad
ID = 4  NAME = rachid
----------------------
ID = 19  NAME = TEXT
---------------------
ID = 3  NAME = kamal
ID = 19  NAME = TEXT
ID = 6  NAME = karim
ID = 2  NAME = bilal
ID = 62  NAME = khalid
ID = 5  NAME = rami
ID = 18  NAME = mounir
ID = 8  NAME = morad
ID = 4  NAME = rachid
----------------------
ID = 3  NAME = kamal
ID = 19  NAME = TEXT
ID = 6  NAME = karim
ID = 2  NAME = bilal
ID = 62  NAME = khalid
ID = 18  NAME = mounir
ID = 8  NAME = morad
ID = 4  NAME = rachid
----------------------
Size: 8
The userList is Empty: true




JAVA - How To Use List In Java NetBeans With Class

JAVA - How To Use List In Java NetBeans With Class

JAVA - How To Use List In Java NetBeans With Class

__________________________________________________________________________

In This Java Code We Will See How To Use List With Class In Java Programming Language.

Project Source Code:

package javadb_001;

import java.util.ArrayList;
import java.util.List;

public class Users {
    private int id;
    private String fname;
    private String lname;
    private int age;
    private int pos = 0;
    public Users(){}
    public Users(int _id,String _fname,String _lname,int _age){
        this.id = _id;
        this.fname = _fname;
        this.lname = _lname;
        this.age = _age;           
    }
    
    public int getId(){
     return this.id;
    }
    public void setId(int id){
        this.id = id;
    }
    
    public String getFname(){
        return this.fname;
    }
    
    public void setFname(String fname){
     this.fname = fname;    
    }
    
    public String getLname(){
        return this.lname;
    }
    
    public void setLname(String lname){
        this.lname = lname;
    }
    
    public int getAge(){
        return this.age;
    }
    
    public void setAge(int age){
        this.age = age;
    }

    public String showInfo(){
        return this.id+" - "+this.fname+" - "+this.lname+" - "+this.age;
    }
    
      public static void main(String[] args){
          
       List<Users> user = new ArrayList<Users>();
       Users u1 = new Users(1,"A1","B1",10);
       Users u2 = new Users(2,"A2","B2",20);
       Users u3 = new Users(3,"A3","B3",30);
       Users u4 = new Users(4,"A4","B4",40);
       user.add(u1);
       user.add(u2);
       user.add(u3);
       user.add(u4);
       for(int i = 0;i<user.size();i++)
       {
           System.out.println(user.get(i).showInfo());
      }
      }
}


//////////////////////////////////  OUTPUT:  1 - A1 - B1 - 10
                                              2 - A2 - B2 - 20
                                              3 - A3 - B3 - 30
                                              4 - A4 - B4 - 40






JAVA - How To Create A Class In Java NetBeans

JAVA - How To Create A Class In Java NetBeans

JAVA - How To Create A Class In Java Using NetBeans

__________________________________________________________________________

In This Java Code We Will See How To Make A Class In Java NetBeans Programming Language.

Project Source Code:

package javadb_001;

public class User{
    private int id;
    private String fname;
    private String lname;
    private int age;

    public User(){}

    public User(int _id,String _fname,String _lname,int _age){
        this.id = _id;
        this.fname = _fname;
        this.lname = _lname;
        this.age = _age;           
    }
    
    public int getId(){
     return this.id;
    }
    public void setId(int id){
        this.id = id;
    }
    
    public String getFname(){
        return this.fname;
    }
    
    public void setFname(String fname){
     this.fname = fname;    
    }
    
    public String getLname(){
        return this.lname;
    }
    
    public void setLname(String lname){
        this.lname = lname;
    }
    
    public int getAge(){
        return this.age;
    }
    
    public void setAge(int age){
        this.age = age;
    }


public static void main(String[] args){
        
        User u = new User(999,"AAAA","BBBB",100);
        int id = u.getId();
        String fname = u.getFname();
        String lname = u.getLname();
        int age = u.getAge();
        System.out.println("ID: "+id);
        System.out.println("FNAME: "+fname);
        System.out.println("LNAME: "+lname);
        System.out.println("AGE: "+age);
}

}

//////////////////  OUTPUT: ID: 999
                                        FNAME: AAAA
                                        LNAME: BBBB
                                        AGE: 100