> Java > java지도 시간 > 본문

Java 어댑터 클래스

PHPz
풀어 주다: 2024-08-30 16:07:15
원래의
487명이 탐색했습니다.

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 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!