찾다
Javajava지도 시간Java 어댑터 클래스

Java 어댑터 클래스

Aug 30, 2024 pm 04:07 PM
java

Java의 어댑터 클래스는 새로운 것이 아닙니다. 이는 Listener 인터페이스 구현을 제공하는 데 사용됩니다. 어댑터 클래스의 장점은 코드를 절약한다는 것입니다. Adapter 인터페이스를 사용하여 어댑터 클래스를 상속하는 경우 모든 리스너 인터페이스 메서드를 구현하지 않아도 됩니다. 즉, Java 어댑터 클래스가 있는 세 가지 패키지가 있습니다. 세 가지 패키지는 다음과 같습니다.

무료 소프트웨어 개발 과정 시작

웹 개발, 프로그래밍 언어, 소프트웨어 테스팅 등

  • java.awt. 이벤트
  • java.awt. 디앤디
  • java.swing. 이벤트

또한 어댑터 클래스의 또 다른 장점은 특정 이벤트 리스너 인터페이스에서 처리하는 몇 가지 이벤트를 처리하려고 할 때 유용하다는 것입니다.

구문을 사용하여 Java에서 어댑터 클래스 작업

소개에서 알 수 있듯이 어댑터 클래스를 찾을 수 있는 세 가지 패키지가 있습니다. 이제 세 패키지 모두에서 해당 어댑터 클래스의 해당 리스너 인터페이스를 살펴보겠습니다.

  • java.awt. 이벤트 어댑터 클래스
  • java.awt.dnd 어댑터 클래스
  • 자바.스윙. 이벤트 어댑터 클래스

1. java.awt. 이벤트 어댑터 클래스

다음은 일부 어댑터 클래스와 해당 리스너 인터페이스입니다. 이는 Java 패키지의 Abstract Window Toolkit에 있습니다.

Adapter Class

Listener Interface

WindowAdapter WindowListener
KeyAdapter KeyListener
MouseAdapter MouseListener
MouseMotionAdapter MouseMotionListener
FocusAdapter FocusListener
ComponentAdapter ComponentListener
ContainerAdapter ContainerListener
HierarchyBoundsAdapter HierarchyBoundsListener
어댑터 클래스

리스너 인터페이스

창 어댑터 창 수신기 키어댑터 키리스너 마우스어댑터 마우스리스너 마우스모션어댑터 MouseMotionListener 포커스어댑터 포커스리스너 컴포넌트 어댑터 컴포넌트 리스너 컨테이너어댑터 컨테이너리스너 HierarchyBoundsAdapter HierarchyBoundsListener WindowAdapter 클래스 아래 코드는 Adapter 클래스의 구문을 제공하며 WindowAdapter 클래스의 모양과 구문에 대한 아이디어를 제공합니다.
AdapterExample()
{
f=new Frame("Hello World");
f.addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)
{
f.close();
}
}
구문:

KeyAdapter 클래스

아래 코드는 KeyAdapter 클래스의 구문을 제공합니다.
public abstract keyAdapter Class
extends Object
Implements KeyListener
구문:

MouseAdapter 클래스

아래 코드는 MouseAdapter 클래스의 구문을 제공합니다.
MouseAdapterExample()
{
f=new Frame("Mouse Adapter");
f.addMouseListener(this);
f.setSize(100,100);
f.setLayout(null);
f.setVisible(false);
}
구문:

MouseMotionAdapter 클래스

아래 코드는 MouseMotionAdapter 클래스의 구문을 제공합니다.
MouseMotionAdapterExample()
{
f=new Frame("Adapter for Mouse Motion");
f.addMouseMotionListener(this);
f.setSize(100,100);
f.setLayout(null);
f.setVisible(false);
}
public void mouseDragged(MouseEvent e)
{
Graphics g=f.getGraphics();
g.setColor(Color.ORANGE);
g.fillOval(e.getX(),e.getY(),20,20);
}
구문:

FocusAdapter 클래스

아래 코드는 FocusAdapter 클래스의 구문을 제공합니다.
public abstract class FocusAdapter
extends Object
Implements FocusListener
구문:

ComponentAdapter 클래스

아래 코드는 ComponentAdapter 클래스의 구문을 제공합니다.
class MyAdapter extends ComponentAdapter
{
public void componentMoved(ComponentEvent e)
{
int a = e.getComponent().getX();
int b = e.getComponent().getY();
System.out.println("Value of X " + a);
System.out.println("Value of Y: " + b);
}
}
구문:

ContainerAdapter 클래스

아래 코드는 ContainerAdapter 클래스의 구문을 제공합니다.
public abstract class ContainerAdapter
extends Object
implements ContainerListener
구문:

HierarchyBoundsAdapter 클래스

아래 코드는 HierarchyBoundsAdapter 클래스의 구문을 제공합니다.
public abstract class HierarchyBoundsAdapter
extends Object
implements HierarchyBoundsListener 

구문:

Adapter Class Listener Interface
DragSourceAdapter DragSourceListener
DragTargetAdapter DragTargetListener
2. java.awt.dnd 어댑터 클래스 다음은 awt.dnd 패키지에 사용되는 일부 어댑터 클래스입니다. 표에 나열되어 있습니다. 어댑터 클래스 리스너 인터페이스 드래그소스 어댑터 드래그소스리스너 DragTargetAdapter DragTargetListener

In this case, there are two Adapter classes under the respective package, which is called. We will see the syntax of the two Adapter classes and study the codes under the respective package.

DragSourceAdapter Class

The below code gives the syntax of the DragSourceAdapter class.

Syntax:

public abstract class DragSourceAdapter
extends Object
implements DragSourceAdapterListener
DragTargetAdapter Class

The below code gives the syntax of the DragTargetAdapter class.

Syntax:

public abstract class DragTargetAdapter
extends Object
implements DragTargetAdapterListener

3. java.swing. event Adapter Classes

Below are some of the classes which are used in the swing. event package. They are listed down in a table.

Adapter Class Listener Interface
MouseInputAdapter MouseInputListener
InternalFrameAdapter InternalFrameListener

In this case, we notice two adapter classes along with their Listener Interface. The package javax. swing. event has two adapter classes which are respectively listed down in the table.

MouseInputAdapter Class

Below is the code which provides the syntax of the MouseInputAdapter class.

Syntax:

public abstract class MouseInputAdapter
extends MouseAdapter
implements MouseInputListener
InternalFrameAdapter Class

Below is the code which provides the syntax of the InternalFrameAdapter class.

Syntax:

public abstract class InternalFrameAdapter
extends Object
implements InternalFrameListener

Explanation

Adapter Classes are basically used in the case when the class is declared as abstract. Only the working is based on different functionalities, including the working of the Java classes, which are part of different Java packages. There are three packages in Java that have different Adapter classes and Listener Interfaces along with them. Adapter Classes are used in numerous cases where servers are used, and there is connectivity with the SQL database.

There are different functionalities, and mostly all of them are being used in Android programming as well. Adapter Classes are well-known functionality in Java programming, which helps coders get the idea of many applications that can be used via Swing methodology. There are many ideas that can be put forward to develop the Adapter Class methodology in Java. Loops can also be incorporated to develop some other types of functionality.

Conclusion

In this article, we see the working, and we see that there are three main packages that contain the adapter classes. We see the syntax of all the adapter classes which are present, as well as some of the codes of the working, are also provided. Adapter classes are basically unique in Java, and they are part of Swing functionality in Java.

위 내용은 Java 어댑터 클래스의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

Atom Editor Mac 버전 다운로드

Atom Editor Mac 버전 다운로드

가장 인기 있는 오픈 소스 편집기

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

DVWA

DVWA

DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는