Thursday 12 August 2021

Java Swing Application

import java.lang*

public class Test1
{
   public static void main(String args[])
   {
     System.out.println("Hello World...");
   }

}
Use Look and Feel in Java Swing Application


With the help of Look & Feel you can change GUI of your Swing Application.

First we know that what is the meaning of Look and Feel in this context,

Look refers to the appearance of GUI widgets of Swing like JLabel,JButton,JPanel,JFrame etc.
and 
Feels refers to the behavior of Widgets like OnSelected,Pressed,MouseOver etc.

Available Look and Feels, 

     Oracle JRE provides follwing look and feels

  1.  CrossPlatformLookAndFeel - this is also called Metal look and feel, it is a default L &  F. If you   don't  set any look and feel then this look and feel will show.
  2.  SystemLookAndFeel
  3. Synth—the basis for creating your own look and feel with an XML file.
  4.  Multiplexing— a way to have the UI methods delegate to a number of different look and feel implementations at the same time.

Spring Constructor Injection Part-1

Today we learn "Spring Constructor Injection"

  1. Open Eclipse and Create a New Core Java Project

  2. Then Add Spring Core Jar file to Project

  3. Project -> Properties - > Java Build Path -> Add External Jars

    Add Following Jar Files to Your Project


   4. Now create a package called mypack

   5. And Create init a Class named as DemoClass

   6.
    Class DemoClass

       {
          DemoClass()
         {
            System.out.println("Default Constructor");
         }
       }


7. Now Create a Configuration file called applicationContext.xml in this we defined how to beans are configured

applicationContext.xml 

a.) Firstly defined Spring namespace in top of the xml file like this

     <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

b.) Now we can access Spring bean related xml tag.

c.) Now we declare Bean Tag for Constructor injection, see

<bean name="name of the bean" class="fully qualified class name" scope="Singleton/Prototype"/>

Description:

name - Defined the desired name
class - in this we have to write fully qualified class name like this in our screnrio "mypack.DemoClass"

scope
- Scope are two types

            a.) Singleton: as name shows Singleton means we can create single instance of a bean only in application life.

           b.) Prototype: In this we can create multiple instance of a bean.

Note: Default scope of a bean is Prototype. 

Sometime we need single instance of a Object in whole application like SessionFactory in Hibernate Application or Connection object for Database related operation. According to our need we can choose either Singleton or Prototype.

Now apply this tag into XML configuration, After apply whole configuration file will look like this

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<bean name="Demo" class="mypack.DemoClass" scope="Prototype"/>

</beans>

8.) Now put this file to src folder of Project.

9.) Now we create a Main Class where we have to test how to get the bean.

10.)