Anvi Jain has Published 629 Articles

Java Program to display 5 different cards in a CardLayout

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:26

595 Views

Use CardLayout layout and set it to panel −JPanel panel = new JPanel(); CardLayout cardLayout = new CardLayout(); panel.setLayout(cardLayout);In the same way create 5 panels and 5 buttons to display 5 different cards.The following is an example to display 5 different cards in CardLayout −Examplepackage my; import java.awt.BorderLayout; import java.awt.CardLayout; ... Read More

How to set limit to $inc in MongoDB?

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:26

205 Views

To set limit to $inc, use the below syntax −db.yourCollectionName.update({yourFieldName : {$lt : yourValue}}, {$inc : {yourFieldName : yourIncrementValue}}, false, true);Let us first create a collection with documents −> db.limitIncrementDemo.insertOne({"StudentId":101, "StudentScore":95}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd2ce9eb64f4b851c3a13c3") } > db.limitIncrementDemo.insertOne({"StudentId":102, "StudentScore":55}); {    "acknowledged" : true,   ... Read More

Display tick marks in a JSlider with Java

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:26

646 Views

To display tick marks in a JSlider, you need to use the setPaintTicks() method and set it to TRUE −JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 100, 75); slider.setPaintTicks(true);The following is an example to display tick marks in a slider in Java −Examplepackage my; import java.awt.Color; import java.awt.Font; import javax.swing.JFrame; import ... Read More

How can I get a list of databases and collections on a MongoDB server?

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:26

138 Views

To get a list of all databases, you need to use the below syntax −use admin db.runCommand({listDatabases: 1});To get a list of all collection names of a particular database, you need to use below syntax −use yourDatabaseName; db.getCollectionNames();Let us implement the above syntaxes −Case 1 − To get ... Read More

MongoDB query to remove array elements from a document?

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:26

165 Views

Use the $pull to remove array elements from a MongoDB document as shown in the following syntax −db.yourCollectionName.update( { }, { $pull: { yourFieldName: yourValue }}, {multi:true });Let us first create a collection with documents −>db.removeArrayElementsDemo.insertOne({"AllPlayerName":["John", "Sam", "Carol", "David"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd90d011a844af18acdffc1") } >db.removeArrayElementsDemo.insertOne({"AllPlayerName":["Chris", ... Read More

Can we save content from JTextField to a file in Java?

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:26

1K+ Views

Yes, we can save the content to a file with FileWriter class. Set a JTextFile component as shown below −JTextField emailId = new JTextField(20); emailId.setText("abc@example.com");Set the file location from to where you want to save the content from the JTextField −String file = "E:ew.txt";Now, with FileWriter, save the content −FileWriter ... Read More

pthread_cancel() in C

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:26

575 Views

The threa_cancel() is used to cancel one particular thread by the thread id. This function sends one cancellation request to the thread for termination. The syntax of the pthread_cancel() is like below −int pthread_cancel(pthread_t th);Now, let us see how to cancel threads using this function.Example#include #include #include ... Read More

How to use Notification Inbox style in Android

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:26

273 Views

This example demonstrate about How to use Notification Inbox style in AndroidStep 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 ... Read More

Performing distinct on multiple fields in MongoDB?

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:26

2K+ Views

You can use $group operator along with aggregate framework to perform distinct on multiple fields. Let us first create a collection with documents −> db.distinctOnMultipleFieldsDemo.insertOne( ...    { ...       "StudentFirstName" : "Chris", ...       "StudentAge" : 21, ...       "StudentCountryName": "US" ...   ... Read More

How to store MongoDB result in an array?

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:26

1K+ Views

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") } ... Read More

Advertisements