Nishtha Thakur has Published 564 Articles

How to center align component using BoxLayout with Java?

Nishtha Thakur

Nishtha Thakur

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

6K+ Views

Let us first create a panel and set some buttons −JPanel panel = new JPanel(); JButton btn1 = new JButton("One"); JButton btn2 = new JButton("Two"); JButton btn3 = new JButton("Three"); JButton btn4 = new JButton("Four"); JButton btn5 = new JButton("Five"); panel.add(btn1); panel.add(btn2); panel.add(btn3); panel.add(btn4); panel.add(btn5);Now, use the setAlignmentX() and within ... Read More

MySQL Select displaying Data type in a separate column?

Nishtha Thakur

Nishtha Thakur

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

65 Views

You can use INFORMATION_SCHEMA.COLUMNS for this. Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(20)    ); Query OK, 0 rows affected (0.73 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name) ... Read More

C++ Program to Implement Johnson’s Algorithm

Nishtha Thakur

Nishtha Thakur

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

1K+ Views

Here we will see the Johnson’s Algorithm to find shortest path between two vertices. The graph is given here. The shortest path between the edges is like below. This program will take the number of vertices, number of edges, and the edges with their costs.Input − Vertices: 3Edges: 5Edge with costs ... Read More

How to set preferred Size for BoxLayout Manager in Java?

Nishtha Thakur

Nishtha Thakur

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

907 Views

Let’s say we have a Frame with layout set as BoxLayout −JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));Set the preferred size using setPreferredSize() and withing that specify the values for width and height −JPanel panel = new JPanel(); panel.setPreferredSize(new Dimension(100, 500));The following is an example to set preferred ... Read More

How do I check whether a field contains null value in MongoDB?

Nishtha Thakur

Nishtha Thakur

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

281 Views

You can use $type operator to check whether a filed contains null value. Let us first create a collection with documents. We have also inserted a null in a field −> db.nullDemo.insertOne({"FirstName":"Chris"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc68a1eac184d684e3fa270") } > db.nullDemo.insertOne({"FirstName":null}); {    "acknowledged" : true,   ... Read More

Distribute extra horizontal and vertical space in a GridBagLayout with Java

Nishtha Thakur

Nishtha Thakur

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

439 Views

To distribute the extra horizontal and vertical space, use the fields weightx and weighty. The following is an example to distribute extra horizontal and vertical space −Examplepackage my; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.WindowConstants; public class SwingDemo {    public static void ... Read More

When to use inline function and when not to use it in C/C++?

Nishtha Thakur

Nishtha Thakur

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

2K+ Views

In C++, there is one good feature called inline function. This kind of functions are like the macros of C or C++. To use inline functions, we have to specify the inline keyword. We can use this type of functions anywhere, but we should follow some guideline.When inline can be ... Read More

How to change the output of printf() in main()?

Nishtha Thakur

Nishtha Thakur

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

247 Views

Here we will see how to change the output of the printf() function from main(). Here we will define a function that will change all of the printf() statements with the given type to another type.We will use the #define macro to do this task. This macro will be defined ... Read More

C++ Program to Find Whether a Path Exists Between 2 Given Nodes

Nishtha Thakur

Nishtha Thakur

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

222 Views

This is a C++ program to find whether a path exists between 2 given nodesAlgorithmBegin    function isReach() is a recursive function to check whether d is reachable to s:    A) Mark all the vertices as unvisited.    B) Mark the current node as visited and enqueue it and ... Read More

How to maintain the top count of array elements in MongoDB?

Nishtha Thakur

Nishtha Thakur

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

92 Views

You can use aggregate framework. Let us first create a collection with documents −> db.topCountArrayDemo.insertOne( ...    {"StudentId":101 , "StudentSubject": ["C", "MongoDB"]} ... ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc6b3209cb58ca2b005e669") } > db.topCountArrayDemo.insertOne( ...    {"StudentId":102 , "StudentSubject": ["C", "Java"]} ... ); {    "acknowledged" : true, ... Read More

Advertisements