Nishtha Thakur

Nishtha Thakur

398 Articles Published

Articles by Nishtha Thakur

Page 12 of 40

How to open last activity when tapping on Android notification?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 763 Views

This example demonstrate about How to open last activity when tapping on Android notificationStep 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/MainActivity.javapackage app.tutorialspoint.com.notifyme ; import android.app.NotificationChannel ; import android.app.NotificationManager ; import android.app.PendingIntent ; import android.content.Context ; import android.content.Intent ; import android.support.v4.app.NotificationCompat ; import android.support.v7.app.AppCompatActivity ; import android.os.Bundle ; import android.view.View ; import android.widget.Button ; public class MainActivity extends AppCompatActivity {    public static ...

Read More

How can I set an EtchedBorder from BorderFactory class to a component in Java?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 252 Views

Set an EtchedBorder from BorderFactory class −EtchedBorder etchedBorder = (EtchedBorder)BorderFactory.createEtchedBorder();Now, set it for a component −JButton button = new JButton("Etched Border"); button.setBorder(etchedBorder);The following is an example to set an EtchedBorder from BorderFactory class to a component −Examplepackage my; import java.awt.BorderLayout; import java.awt.Container; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.border.Border; import javax.swing.border.EtchedBorder; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Demo");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       Border raisedBorder = new EtchedBorder(EtchedBorder.RAISED);       EtchedBorder etchedBorder = (EtchedBorder)BorderFactory.createEtchedBorder();       JButton raisedButton = new JButton("Raised Border");   ...

Read More

The best way to check if a file exists using standard C/C++

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 18K+ Views

The only way to check if a file exist is to try to open the file for reading or writing.Here is an example −In CExample#include int main() {    /* try to open file to read */    FILE *file;    if (file = fopen("a.txt", "r")) {       fclose(file);       printf("file exists");    } else {       printf("file doesn't exist");    } }Outputfile existsIn C++Example#include #include using namespace std; int main() {    /* try to open file to read */    ifstream ifile;    ifile.open("b.txt");    if(ifile) {       cout

Read More

Getting a list of values by using MongoDB $group?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 1K+ Views

To get a list of values, use $group aggregation along with $push operator. Let us first create a collection with documents −> db.groupByDemo.insertOne({"UserName":"John", "Subject":"MongoDB"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd69f0457806ebf1256f136") } > db.groupByDemo.insertOne({"UserName":"Larry", "Subject":"MySQL"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd69f0657806ebf1256f137") } > db.groupByDemo.insertOne({"UserName":"John", "Subject":"Java"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd69f0d57806ebf1256f138") } > db.groupByDemo.insertOne({"UserName":"John", "Subject":"C"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd69f1357806ebf1256f139") } > db.groupByDemo.insertOne({"UserName":"Larry", "Subject":"SQL Server"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd69f1c57806ebf1256f13a") }Following is the query to display all documents from a collection with the help ...

Read More

How to start an activity when user clicks a notification in Android?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 466 Views

This example demonstrate about How to start an activity when user clicks a notification 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 − Add the following code to src/MainActivity.javapackage app.tutorialspoint.com.notifyme ; import android.app.NotificationChannel ; import android.app.NotificationManager ; import android.app.PendingIntent ; import android.content.Context ; import android.content.Intent ; import android.support.v4.app.NotificationCompat ; import android.support.v7.app.AppCompatActivity ; import android.os.Bundle ; import android.view.View ; import android.widget.Button ; public class MainActivity extends AppCompatActivity {   ...

Read More

How to set Row Header View for JScrollPane in Java?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 794 Views

Set Row Header View using the setRowHeaderView() method. Let us first create a KScrollPane and set a list −List myList = new ArrayList(10); for (int index = 0; index < 20; index++) {    myList.add("List Item " + index); } final JList list = new JList(myList.toArray(new String[myList.size()])); JScrollPane scrollPane = new JScrollPane(); scrollPane.setViewportView(list);Now, set the row header view −scrollPane.setRowHeaderView(new JLabel("All List Items "));The following is an example to set row header view for JScrollPane in Java −Examplepackage my; import java.awt.BorderLayout; import java.util.ArrayList; import java.util.List; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; public class SwingDemo {    public ...

Read More

Difference between %p and %x in C/C++

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 10K+ Views

Here we will see what are the differences between %p and %x in C or C++. The %p is used to print the pointer value, and %x is used to print hexadecimal values. Though pointers can also be displayed using %u, or %x. If we want to print some value using %p and %x then we will not feel any major differences. The only difference that can be noticed is that the %p will print some leading zeros, but %x doesn’t.Example#include main() {    int x = 59;    printf("Value using %%p: %p", x);    printf("Value using %%x: %x", x); ...

Read More

C++ Program to Implement Levenshtein Distance Computing Algorithm

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 4K+ Views

The Levenshtein distance between two strings means the minimum number of edits needed to transform one string into the other, with the edit operations i.e; insertion, deletion, or substitution of a single character.For example: The Levenshtein Distance between cat and mat is 1 −cat mat(substitution of ‘c’ with ‘m’)Here is a C++ Program to implement Levenshtein Distance computing algorithm.AlgorithmsBegin    Take the strings as input and also find their length.    For i = 0 to l1       dist[0][i] = i    For j = 0 to l2       dist[j][0] = j    For j=1 to l1 ...

Read More

How to remove the notification after the particular time in android?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 796 Views

This example demonstrate about How to remove the notification after the particular time 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 − Add the following code to src/MainActivity.javapackage app.tutorialspoint.com.notifyme ; import android.app.NotificationChannel ; import android.app.NotificationManager ; import android.app.PendingIntent ; import android.content.Context ; import android.content.Intent ; import android.os.Handler ; import android.support.v4.app.NotificationCompat ; import android.support.v7.app.AppCompatActivity ; import android.os.Bundle ; import android.view.View ; import android.widget.Button ; public class MainActivity extends AppCompatActivity ...

Read More

C++ Program to Decode a Message Encoded Using Playfair Cipher

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 536 Views

In this scheme, pairs of letters are encrypted, instead of single letters as in the case of simple substitution cipher.In playfair cipher, initially a key table is created. The key table is a 5×5 grid of alphabets that acts as the key for encrypting the plaintext. Each of the 25 alphabets must be unique and one letter of the alphabet (usually J) is omitted from the table as we need only 25 alphabets instead of 26. If the plaintext contains J, then it is replaced by I.The sender and the receiver deicide on a particular key, say ‘tutorials’. In a ...

Read More
Showing 111–120 of 398 articles
« Prev 1 10 11 12 13 14 40 Next »
Advertisements