⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swingdndtest.java

📁 这个是我老师给的关于Java核心技术2的第7章的源代码
💻 JAVA
字号:
/**
   @version 1.01 2004-08-25
   @author Cay Horstmann
*/

import java.awt.*;
import javax.swing.*;

/**
   This program demonstrates how to easily add data transfer
   capabilities to Swing components. Drag a color from the 
   "Preview" panel of the color chooser into the text field.
*/
public class SwingDnDTest
{  
   public static void main(String[] args)
   {  
      JFrame frame = new SwingDnDFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);
   }
}

/**
   This frame contains a color chooser and a text field. Dragging
   a color into the text field changes its background color.
*/
class SwingDnDFrame extends JFrame
{  
   public SwingDnDFrame()
   {  
      setTitle("SwingDnDTest");

      JColorChooser chooser = new JColorChooser();
      chooser.setDragEnabled(true);
      add(chooser, BorderLayout.CENTER);
      JTextField textField = new JTextField("Drag color here");
      textField.setDragEnabled(true);
      textField.setTransferHandler(new TransferHandler("background"));
      add(textField, BorderLayout.SOUTH);
      pack();
   }
}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -