The DOM previousSibling property returns the previous node in the same tree level of the specified node in an HTML document.SyntaxFollowing is the syntax −node.previousSiblingExampleLet us see an example of previousSibling property − Live Demo html{ height:100%; } body{ text-align:center; color:#fff; background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) center/cover no-repeat; height:100%; } p{ font-weight:700; font-size:1.2rem; } .drop-down{ width:50%; border:2px solid #fff; font-weight:bold; ... Read More
In C or C++, we cannot create random float directly. We can create random floats using some trick. We will create two random integer values, then divide them to get random float value.Sometimes it may generate an integer quotient, so to reduce the probability of that, we are multiplying the result with some floating point constant like 0.5.Example#include #include #include using namespace std; main() { srand((unsigned int)time(NULL)); float a = 5.0; for (int i=0;i
The following is an example to display the contents of a text file in JTextArea −Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; public class SwingDemo { private JFrame mainFrame; private JLabel statusLabel; private JPanel controlPanel; public SwingDemo() { prepareGUI(); } public static void main(String[] args) { SwingDemo demo = new SwingDemo(); demo.showTextAreaDemo(); } private void prepareGUI() { mainFrame = new JFrame("Java Swing"); mainFrame.setSize(400, 400); mainFrame.setLayout(new GridLayout(3, 1)); mainFrame.addWindowListener(new WindowAdapter() { ... Read More
This example demonstrate about How to give emojis support in Android push 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.package app.tutorialspoint.com.notifyme ; import android.app.NotificationChannel ; import android.app.NotificationManager ; import android.os.Bundle ; import android.support.v4.app.NotificationCompat ; import android.support.v7.app.AppCompatActivity ; import android.view.View ; public class MainActivity extends AppCompatActivity { public static final String NOTIFICATION_CHANNEL_ID = "10001" ; private final static String default_notification_channel_id = "default" ... Read More
You can use $avg operator along with aggregate framework. Let us first create a collection with documents −> db.averageOfRatingsInArrayDemo.insertOne( ... { ... "StudentDetails":[ ... { ... "StudentId":1, ... "StudentScore":45 ... }, ... { ... "StudentId":2, ... "StudentScore":58 ... }, ... { ... "StudentId":3, ... ... Read More
Yes, we can do that with Java Swings as shown below. Here, we have a panel set with GridLayout and another panel with BorderLayout −JPanel panelGrid = new JPanel(new GridLayout(10, 5, 10, 10)); panelGrid.add(new JCheckBox("Demo CheckBox1")); panelGrid.add(new JCheckBox("Demo CheckBox2")); panelGrid.add(btnAPanel); panelGrid.add(btnBPanel); panelGrid.add(btnCPanel); panelGrid.add(btnDPanel); JPanel panelBrdLayout = new JPanel(new BorderLayout()); panelBrdLayout.add(panelGrid, BorderLayout.NORTH);The following is an example to combine GridLayout and BorderLayout −package my; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.GridLayout; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JPanel; public class SwingDemo { public static void main(String[] args) { JButton btnA = new JButton("Button1"); JButton btnB ... Read More
To make JTable single selectable in Java, you need to set the selection mode to be SINGE_SELECTION. Let’s say the following is our table −String[][] rec = { { "001", "Shirts", "40" }, { "002", "Trousers", "250" }, { "003", "Jeans", "25" }, { "004", "Applicances", "90" }, { "005", "Mobile Phones", "200" }, { "006", "Hard Disk", "150" }, }; String[] header = { "ID", "Product", "Quantity" }; JTable table = new JTable(rec, header);Set the selection more to make it single selectable with setSelectionMode() method −table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);Let us see an example to set the ... Read More
To set all the values in a field to 0, use the update command −update yourTableName set yourColumnName=0;Let us first create a table −mysql> create table DemoTable ( Number int ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(4757); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(48474); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values(35465); Query OK, 1 row affected (0.16 sec)Display all records from ... Read More
Removing HTML tags from a stringWe can remove HTML/XML tags in a string using regular expressions in javascript. HTML elements such as span, div etc. are present between left and right arrows for instance , etc. So replacing the content within the arrows, along with the arrows, with nothing('') can make our task easy.Syntaxstr.replace( /(]+)>)/ig, '');Example-1Live Demo function removeTags(str) { if ((str===null) || (str==='')) return false; else str = str.toString(); ... Read More
One way to get the name of the underlying database you have connected with is by invoking the getDatabaseProductName() method of the DatabaseMetaData interface. This method returns the name of the underlying database in String format.Therefore, to retrieve the name of your current database using Java code −Retrieve the DatabaseMetaData object of the current Connection using the getMetaData() method.//Retrieving the meta data object DatabaseMetaData metaData = con.getMetaData();Then, get the product name of the underlying database you have connected to using the getDatabaseProductName() method of the DatabaseMetaData interface as −//retrieving the name of the database String product_name = metaData.getDatabaseProductName();ExampleFollowing JDBC program ... Read More