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

📄 frame1.java

📁 在JAVA中如何实现两棵树之间的拖拽功能.
💻 JAVA
字号:
package twotreedrag;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.AWTEvent;
import javax.swing.JScrollPane;
import java.awt.event.WindowEvent;
import com.borland.jbcl.layout.XYLayout;
import javax.swing.JLabel;
import com.borland.jbcl.layout.XYConstraints;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */

    public class Frame1 extends JFrame {
   public JPanel contentPane;
   public JScrollPane jScrollPane1 = new JScrollPane();
   public XYLayout xYLayout1 = new XYLayout();
   public DragSourceTree jTree1 = new DragSourceTree();
   public JScrollPane jScrollPane2 = new JScrollPane();
   public DragTargetTree jTree2 = new DragTargetTree();
   public JLabel jLabel1 = new JLabel();
   public JLabel jLabel2 = new JLabel();



//Construct the frame
   public Frame1 () {
   enableEvents(AWTEvent.WINDOW_EVENT_MASK);
   try {
   jbInit();
   }
   catch(Exception e) {
   e.printStackTrace();
   }
   }



//Component initialization
   public void jbInit() throws Exception {
   contentPane = (JPanel) this.getContentPane();
   contentPane.setLayout(xYLayout1);
   this.setSize(new Dimension(400, 300));
   this.setTitle("Frame1");
   jLabel1.setFont(new java.awt.Font("DialogInput", 0, 16));
   jLabel1.setText("源树");
   jLabel2.setEnabled(true);
   jLabel2.setFont(new java.awt.Font("DialogInput", 0, 16));
   jLabel2.setDebugGraphicsOptions(0);
   jLabel2.setDoubleBuffered(false);
   jLabel2.setVerifyInputWhenFocusTarget(true);
   jLabel2.setDisplayedMnemonic('0');
   jLabel2.setText("目标树");
   jLabel2.setVerticalAlignment(javax.swing.SwingConstants.CENTER);
   jLabel2.setVerticalTextPosition(javax.swing.SwingConstants.CENTER);
   contentPane.add(jLabel1, new XYConstraints(35, 8, 139, 27));
   contentPane.add(jLabel2, new XYConstraints(214, 10, 149, 20));
   contentPane.add(jScrollPane2, new XYConstraints(211, 31, 159, 231));
   contentPane.add(jScrollPane1, new XYConstraints(25, 31, 153, 230));
   jScrollPane1.getViewport().add(jTree1, null);
   jScrollPane2.getViewport().add(jTree2, null);
   }



//Overridden so we can exit when window is closed
   protected void processWindowEvent(WindowEvent e) {
   super.processWindowEvent(e);
   if (e.getID() == WindowEvent.WINDOW_CLOSING) {
   System.exit(0);
   }
   }
   }

⌨️ 快捷键说明

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