Posts

Assignment-1

  import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Frame; import java.awt.Panel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; public class SimpleAwt extends Frame {     public static void main(String args[])  {         JFrame frame = new JFrame();         JButton button = new JButton("click");         Container c = frame.getContentPane();         c.setBackground(Color.WHITE);         FlowLayout ff = new FlowLayout();         c.setLayout(ff);         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         frame.getContentPane().add(button);         button.addActionListener(new ActionListener() {   ...

Assignment-2

 import java.awt.*; import java.awt.event.*; public class Prac2 implements ItemListener {     Frame f;     Checkbox c1,c2,c3;     Canvas c;     int red=0,blue=0,green=0;     Prac2()     {         f=new Frame("Practical-8");         c1=new Checkbox("Red");         c2=new Checkbox("Green");         c3=new Checkbox("Blue");                  c1.addItemListener(this);         c2.addItemListener(this);         c3.addItemListener(this);                  c=new Canvas();         c.setSize(30,30);         c.setBackground(Color.BLACK);             f.setLayout(new FlowLayout());                  f.add(c1);   ...

Encapsulation in Java

Image
Encapsulation in java:- Encapsulation is defined as the wrapping up of data under a single unit.  It is the mechanism that binds together code and the data it manipulates. Other way to think about encapsulation is, it is a protective shield that prevents the data from being accessed by the code outside this shield. Technically in encapsulation, the variables or data of a class is hidden from any other class and can be accessed only through any member function of own class in which they are declared. As in encapsulation, the data in a class is hidden from other classes using the data hiding concept which is achieved by making the members or methods of class as private and the class is exposed to the end user or the world without providing any details behind implementation using the abstraction concept, so it is also known as combination of data-hiding and abstraction.. Encapsulation can be achieved by: Declaring all the variables in the class as private and writing public methods in...

Abstraction in Java

 Abstraction in Java   Data Abstraction is the property by virtue of which only the essential details are displayed to the user.The trivial or the non-essentials units are not displayed to the user. Ex: A car is viewed as a car rather than its individual components. Ways to achieve Abstraction There are two ways to achieve abstraction in java Abstract class  Interface Abstract class in Java:- A class which is declared with the abstract keyword is known as an abstract class in java. It can have abstract and non-abstract methods (method with the body). A class which is declared as abstract is known as an abstract class . It can have abstract and non-abstract methods. It needs to be extended and its method implemented. It cannot be instantiated. Points to Remember An abstract class must be declared with an abstract keyword. It can have abstract and non-abstract methods. It cannot be instantiated. It can have constructor and static methods also. It can have final method...

this keyword

  There can be a lot of usage of   Java this keyword . In Java, this is a   reference variable   that refers to the current object. Usage of Java this keyword Here is given the 6 usage of java this keyword. this can be used to refer current class instance variable. this can be used to invoke current class method (implicitly) this() can be used to invoke current class constructor. this can be passed as an argument in the method call. this can be passed as argument in the constructor call. this can be used to return the current class instance from the method . 1) this: to refer current class instance variable The this keyword can be used to refer current class instance variable. If there is ambiguity between the instance variables and parameters, this keyword resolves the problem of ambiguity. class  Student{   int  rollno;   String name;   float  fee;   Student( int  rollno,String name, float  ...

Java AWT

  Java AWT Java AWT  (Abstract Window Toolkit) is  an API to develop Graphical User Interface (GUI) or windows-based applications  in Java. Java AWT components are platform-dependent i.e. components are displayed according to the view of operating system. AWT is heavy weight i.e. its components are using the resources of underlying operating system (OS). The java.awt package provides classes for AWT API such as T extField , Label ,   RadioButton, CheckBox etc. The AWT tutorial will help the user to understand Java GUI programming in simple and easy steps. Components All the elements like the button, text fields, scroll bars, etc. are called components. In Java AWT, there are classes for each component as shown in above diagram. In order to place every component in a particular position on a screen, we need to add them to a container. Container The Container is a component in AWT that can contain another components lik...

Program-1 Adv jJava

Image
1.Develop a Programe that has only one button in the frame,clicking on the button cycle through the color RED>GREEN>BLUE ans so on.One color change per Click.(Use getBackGround() method to get the current color)  import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Frame; import java.awt.Panel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; public class SimpleAwt extends Frame {     public static void main(String args[]) {         JFrame frame = new JFrame();         JButton button = new JButton("click");         Container c = frame.getContentPane();         c.setBackground(Color.WHITE);         FlowLayout ff = new FlowLayout();         c.setLayout(ff);     ...