Yes, we can enable drag and drop between two text fields in Java. Let us first create two JTextFields and set content in it as shown below −JTextField one = new JTextField(20); one.setText("You can drag!"); JTextField two = new JTextField(20); two.setText("Drag here or there");Now, we will enable and drag and drop for both the components created above −one.setDragEnabled(true); two.setDragEnabled(true);The following is an example to enable drag and drop between two text fields −Examplepackage my; import java.awt.Container; import java.awt.FlowLayout; import javax.swing.BoxLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.SwingConstants; public class SwingDemo { public static void main(String[] args) throws Exception ... Read More
To store MongoDB result in an array, use the toArray() method −var anyVariableName=db.yourCollectionName.find().toArray();Let us first create a collection with documents −> db.mongoDbResultInArrayDemo.insertOne({"CustomerName":"David Miller", "CustomerAge":24, "isMarried":false}); { "acknowledged" : true, "insertedId" : ObjectId("5cd99bd5b50a6c6dd317ad92") } > db.mongoDbResultInArrayDemo.insertOne({"CustomerName":"Sam Williams", "CustomerAge":46, "isMarried":true}); { "acknowledged" : true, "insertedId" : ObjectId("5cd99beab50a6c6dd317ad93") } > db.mongoDbResultInArrayDemo.insertOne({"CustomerName":"Carol Taylor", "CustomerAge":23, "isMarried":false}); { "acknowledged" : true, "insertedId" : ObjectId("5cd99bf9b50a6c6dd317ad94") }Following is the query to display all documents from a collection with the help of find() method −> db.mongoDbResultInArrayDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cd99bd5b50a6c6dd317ad92"), "CustomerName" : "David Miller", "CustomerAge" ... Read More
The HTML DOM Input Color value property returns a string, which represents the value of the input color value attribute. User can also set it to a new string.SyntaxFollowing is the syntax −Returning string valueinputColorObject.valueSetting value attribute to a string valueinputColorObject.value = ‘String’ExampleLet us see an example of Input Color value property − Live Demo Input Color Value Primary-Color: Get type & change to text var inputColor = document.getElementById("Color"); var divDisplay = document.getElementById("divDisplay"); divDisplay.textContent = 'value: '+inputColor.value; function changeValue() { if(inputColor.value == '#00ff00'){ ... Read More
The HTML DOM Input Time name property returns a string, which displays the value of the name attribute of input Time. User can also set it to a new string.SyntaxFollowing is the syntax −Returning string valueinputTimeObject.nameSetting name attribute to a string valueinputTimeObject.name = ‘String’ExampleLet us see an example of Input Time name property − Live Demo Input Time name form { width:70%; margin: 0 auto; text-align: center; } * { padding: 2px; margin:5px; } input[type="button"] { ... Read More
Here we will see what will be the effect of pthread_self() in C. The pthread_self() function is used to get the ID of the current thread. This function can uniquely identify the existing threads. But if there are multiple threads, and one thread is completed, then that id can be reused. So for all running threads, the ids are unique.Example#include #include #include void* func(void* p) { printf("From the function, the thread id = %d", pthread_self()); //get current thread id pthread_exit(NULL); return NULL; } main() { pthread_t thread; // declare thread ... Read More
This example demonstrate about How to Show android notification every five minutesStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivitypackage app.tutorialspoint.com.notifyme ; import android.content.Intent ; import android.os.Bundle ; import android.support.v7.app.AppCompatActivity ; import android.view.View ; public class MainActivity extends AppCompatActivity { @Override protected void onCreate (Bundle savedInstanceState) { super .onCreate(savedInstanceState) ; setContentView(R.layout. activity_main ) ; } @Override protected void onStop () { super .onStop() ; startService( new Intent( this, NotificationService. class )) ; } public void closeApp (View view) { finish() ; } }Step ... Read More
To rename a user, you need to use update() and $set to set the new username. Following is the syntax −db.system.users.update({"user":"yourOldUserName"}, {$set:{"user":"yourNewUserName"}});Firstly, display all the users from the MongoDB database −> use admin; switched to db admin > db.getUsers();This will produce the following output −[ { "_id" : "admin.Chris", "user" : "Chris", "db" : "admin", "roles" : [ { "role" : "readWrite", "db" : "test" } ... Read More
Reference-counting garbage collectionThis is the simplest garbage collection algorithm.This algorithm looks out for those objects which have no references left.An object becomes eligible for garbage collection if it has no references attached to it.The garbage collection is explained in the below example.Examplevar obj = { x: { y: 2 } }; // 2 objects created. One is referenced by the other as one of its properties. // Obviously, none can be garbage-collected obj = 1; // what was the 'x' property of the ... Read More
To display tree structured data, use the JTree control in Java Swing.At first, create a node in the tree −DefaultMutableTreeNode node = new DefaultMutableTreeNode("Project");Now, add nodes to the node created above −DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("App"); DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("Website"); DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("WebApp"); node.add(node1); node.add(node2); node.add(node3);Now, create more nodes and set them as child nodes for the nodes we creted above −DefaultMutableTreeNode one = new DefaultMutableTreeNode("Learning website"); DefaultMutableTreeNode two = new DefaultMutableTreeNode("Business website"); DefaultMutableTreeNode three = new DefaultMutableTreeNode("News publishing website"); DefaultMutableTreeNode four = new DefaultMutableTreeNode("Android app"); DefaultMutableTreeNode five = new DefaultMutableTreeNode("iOS app"); DefaultMutableTreeNode six = new DefaultMutableTreeNode("Editor ... Read More
Use $addToSet to create a new field in MongoDB. Let us first create a collection with documents −> db.createFieldDemo.insertOne({"StudentFirstName":"John", "StudentAge":21}); { "acknowledged" : true, "insertedId" : ObjectId("5cd99e28b50a6c6dd317ad95") } > db.createFieldDemo.insertOne({"StudentFirstName":"Larry", "StudentAge":23}); { "acknowledged" : true, "insertedId" : ObjectId("5cd99e2fb50a6c6dd317ad96") } > db.createFieldDemo.insertOne({"StudentFirstName":"Chris", "StudentAge":22}); { "acknowledged" : true, "insertedId" : ObjectId("5cd99e38b50a6c6dd317ad97") } > db.createFieldDemo.insertOne({"StudentFirstName":"David", "StudentAge":25}); { "acknowledged" : true, "insertedId" : ObjectId("5cd99e43b50a6c6dd317ad98") }Following is the query to display all documents from a collection with the help of find() method −> db.createFieldDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cd99e28b50a6c6dd317ad95"), "StudentFirstName" : ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP