answersLogoWhite

0


Best Answer

An Adapter is simply a concrete class which implements all the methods of a Listener interface as empty functions. They are convenience classes made because of the tendency to implement Listeners as anonymous classes.

For example, let's say we want to add a Listener to a JFrame to detect a mouse click:

// implementing a Listener

JFrame frame = new JFrame();

frame.addMouseListener(new MouseListener() {

void mouseClicked(MouseEvent e) {

// do something here

}

void mouseEntered(MouseEvent e) {

}

void mouseExited(MouseEvent e) {

}

void mousePressed(MouseEvent e) {

}

void mouseReleased(MouseEvent e) {

}

});

Note how this has a lot of extra code that does nothing.

// implementing an Adapter

JFrame frame = new JFrame();

frame.addMouseListener(new MouseAdapter() {

void mouseClicked(MouseEvent e) {

// do something here

}

});

Note now how we only need to implement one method. This is much cleaner and easier to read.

User Avatar

Wiki User

βˆ™ 15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the function of adapter in java model?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is function in java terminology?

In Java, a function is called a "method". In Java as well as other languages, a method is a function defined specifically for one class. In Java, this is the only way to define functions, therefore, all functions are methods.In Java, a function is called a "method". In Java as well as other languages, a method is a function defined specifically for one class. In Java, this is the only way to define functions, therefore, all functions are methods.In Java, a function is called a "method". In Java as well as other languages, a method is a function defined specifically for one class. In Java, this is the only way to define functions, therefore, all functions are methods.In Java, a function is called a "method". In Java as well as other languages, a method is a function defined specifically for one class. In Java, this is the only way to define functions, therefore, all functions are methods.


What is the function of the adapter?

no i cant


Is main a predefined function in java?

No. It is a user defined function which the person who is creating the java class has to code by himself.


In java public static voidmain function denotes what?

Java's main function denotes the entry point into the execution of your program.


What are functions in JAVA?

for loop function


What is the function of the adapter card?

kambing


Who invoke main function in java?

The Java Runtime Environment invokes main methods.


What is the difference between method and function in java?

A function is a piece of code that can be reused by calling its name while a method is a function that is associated with a class. In Java, functions are usually referred to as static methods.


What is a method in Java?

A Java method is a sequence of statements. It is comparable to a function, subroutine, or procedure in other languages.


Can we execute java program without main function?

no


Will the HP 402018-001 AC Adapter work on a Pavilion?

No the HP AC adapter will not work on a Pavilion. You would need to find the specific adapter for the model you have.


What are adapter classes in java?

An adapter class is a class that provides a dummy (empty) implementation for an interface. That way someone who wants to implement the interface but does not want or does not know how to implement all methods, can use the adapter class instead, and only override the methods he is interested in.