Smita Kapse has Published 558 Articles

How to set columnWeights and rowWeights in a GridBagLayout?

Smita Kapse

Smita Kapse

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

137 Views

Create a panel and set the layout −JPanel panel = new JPanel(); GridBagLayout layout = new GridBagLayout(); panel.setLayout(layout);Now, set the constrainst and with that the columnWeights and rowWeights −GridBagConstraints gbc = new GridBagConstraints(); JLabel label = new JLabel("Rank: "); JTextArea text = new JTextArea(); text.setText("Add rank here..."); layout.columnWeights = new ... Read More

What are the rules for calling the superclass constructor C++?

Smita Kapse

Smita Kapse

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

9K+ Views

In C++, we can derive some classes. Sometimes we need to call the super class (Base class) constructor when calling the constructor of the derived class. Unlike Java there is no reference variable for super class. If the constructor is non-parameterized, then it will be called automatically with the derived ... Read More

C++ Program to Solve a Matching Problem for a Given Specific Case

Smita Kapse

Smita Kapse

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

392 Views

This is a C++ Program to solve a matching problem for a Given Specific Case. Here, N men and N women are given, each person has ranked all members of the opposite gender in order of preference, marry the men and women together such that there are no two people ... Read More

Write a one line C function to round floating point numbers

Smita Kapse

Smita Kapse

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

653 Views

Here we will see how to write one-line C function, that can round floating point numbers. To solve this problem, we have to follow these steps.Take the numberif the number is positive, then add 0.5Otherwise, subtract 0.5Convert the floating point value to an integer using typecastingExample#include    int my_round(float ... Read More

How to create a user in MongoDB v3?

Smita Kapse

Smita Kapse

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

130 Views

To create a user in MongoDB v3, use the createUser() method. This allows you to create a user and while creating you need to add user, password, and roles as well. These roles assign permissions. The syntax is as follows −use admin db.createUser(    {       user: “yourUserName", ... Read More

How to add components with a Relative X Position in Java

Smita Kapse

Smita Kapse

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

446 Views

To add components with a relative X position, use the GridBagConstraints.RELATIVE constant. Set this to gridx field −GridBagConstraints constraints = new GridBagConstraints(); constraints.gridx = GridBagConstraints.RELATIVE;The following is an example to add components with a relative X position in Java −Examplepackage my; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JButton; import javax.swing.JFrame; import ... Read More

C++ Program to Demonstrate the Implementation of 4-Color Problem

Smita Kapse

Smita Kapse

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

492 Views

This is a C++ Program to Demonstrate the Implementation of 4-Color Problem.AlgorithmBegin    Develop function issafe() to check if the current color assignment    is safe for vertex v i.e. checks whether the edge exists or not.    If it exists,       then next check whether the color ... Read More

Retrieve the position in an Array in MongoDB?

Smita Kapse

Smita Kapse

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

250 Views

You can use the concept of map reduce to get the position in an array. Let us first create a collection with documents −> db.retrievePositionDemo.find(); { "_id" : ObjectId("5cd569ec7924bb85b3f4893f"), "Subjects" : [ "MySQL", "MongoDB", "Java" ] }Following is the query to display all documents from a collection with the help ... Read More

How to set vertical alignment for a component in Java?

Smita Kapse

Smita Kapse

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

3K+ Views

For vertical alignment, create a frame and set the layout using the BoxLayout manager −JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));Above, we have set the BoxLayout to set the alignment since it is a layout manager that allows multiple components to be laid out either vertically or horizontally. ... Read More

setjump() and longjump() in C

Smita Kapse

Smita Kapse

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

2K+ Views

In this section, we will see what are the setjump and longjump in C. The setjump() and longjump() is located at setjmp.h library. The syntax of these two functions is like below.setjump(jmp_buf buf) : uses buf to store current position and returns 0. longjump(jmp_buf buf, i) : Go back to ... Read More

Advertisements