Magazine
 
URL Example with Desktop class
 

See the output when you type “javajazzup” as a password:

C:\Tips&Tricks>java PasswordPromptingDemo
Enter password:

Access granted

And when you type another password:

C:\Tips&Tricks>java PasswordPromptingDemo
Enter password:

Access denied

Download Example

5. Drag and drop between JTextArea and JtextField

In Java, DnD is a data transfer API. The user transfers the data from one place to another by using the mouse (usually). One selects something with a mouse press, drags it (moves the mouse while keeping the mouse button pressed) and releases the mouse button
someplace else. When the button is released the data is “dropped” at that location.

The example given below shows how to use the drag-and-drop support built into Swing components. This program contains a TextArea and TextField with some specified text. The setDragEnabled method having a true
argument of each swing’s make it as a drag and droppable component.

DnDFieldDemo.java

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class DnDFieldDemo {
public static void main(String[] args) {
JFrame frame = new JFrame(“Drag and
Drop Demo”);
frame.setDefaultCloseOperation
(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(new JPanel());
JTextField textField = new JTextField(25);

 

textField.setText(“www.javajazzup.com”);
frame.add(textField);
JTextArea textArea = new JTextArea(4,
25);
textArea.setText(“drag and drop”);
frame.getContentPane().add(new
JScrollPane(textArea));
textArea.setDragEnabled(true);
textField.setDragEnabled(true);
frame.pack();
frame.setVisible(true);
}
}

The output will be show as:

Now you can drag and drop the text between TextField and TextArea.

Download Example

     
Mar 2008 | Java Jazz Up | 55
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59,

Download PDF