Programming Articles

Page 2443 of 2547

C++ Internals?

Arnab Chakraborty
Arnab Chakraborty
Updated on 31-Jul-2019 338 Views

Here we will see the Class internals. Before that we will see Default constructors, which are related to internals. The default constructor is one constructor (defined by user or compiler) that does not take any argument. Now the question comes, why the default constructor is used?If the default constructor is not given, the compiler will implicitly declare default constructor. Default constructors are used to initialize some class internals. It will not affect the data member of the class. The compiler inserts default constructor in some different situations. Suppose a class is derived from another class with default constructor, or one ...

Read More

How to create vertical button column with GridLayout in Java?

Smita Kapse
Smita Kapse
Updated on 30-Jul-2019 2K+ Views

To create a vertical button column, let us first create some buttons and set the layout as well −JPanel btnPanel = new JPanel(new GridLayout(10, 1, 10, 5)); btnPanel.add(new JButton("First Button")); btnPanel.add(new JButton("Second Button")); btnPanel.add(new JButton("Third Button")); btnPanel.add(new JButton("Fourth Button")); btnPanel.add(new JButton("Fifth Button")); btnPanel.add(new JButton("Sixth Button")); btnPanel.add(new JButton("Seventh Button")); btnPanel.add(new JButton("Eighth Button"));Above, we have set the GridLayout to create rows and columns with vertical and horizontal gap.The following is an example to create vertical button column with GridLayout −Examplepackage my; import java.awt.BorderLayout; import java.awt.GridBagLayout; import java.awt.GridLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; public class SwingDemo {    public static ...

Read More

C++ Program to Generate a Sequence of N Characters for a Given Specific Case

Samual Sam
Samual Sam
Updated on 30-Jul-2019 472 Views

This is a C++ program to generate a sequence of N characters for a given specific case.AlgorithmsBegin    function GenerateSequence() generate a Sequence of N Characters for a Given Specific Case:       Use rand() for generating random indexes.       Store the first character directly into the sequence.       If that sequence is used earlier, then it discards that and generates random index again. EndExample#include #include #include using namespace std; void GenerateSequence(char string[], int n, int l, char *sequence) {    int i, j=0, k, in;    for(i = 0; i < n; i++) { ...

Read More

C++ Program to Compute Combinations using Recurrence Relation for nCr

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 704 Views

This is a C++ program to compute Combinations using Recurrence Relation for nCr.AlgorithmsBegin    function CalCombination():       Arguments: n, r.       Body of the function:       Calculate combination by using       the formula: n! / (r! * (n-r)!. EndExample#include using namespace std; float CalCombination(float n, float r) {    int i;       if(r > 0)          return (n/r)*CalCombination(n-1,r-1);       else    return 1; } int main() {    float n, r;    int res;    coutn;    coutr;    res = CalCombination(n,r);    cout

Read More

Java ResultSet getDriverMajorVersion() method with example

Arushi
Arushi
Updated on 30-Jul-2019 221 Views

When we execute certain SQL queries (SELECT query in general) they return tabular data.The java.sql.ResultSet interface represents such tabular data returned by the SQL statements.i.e. the ResultSet object holds the tabular data returned by the methods that execute the statements which quires the database (executeQuery() method of the Statement interface in general).The ResultSet object has a cursor/pointer which points to the current row. Initially this cursor is positioned before first row.The first() method of the ResultSet interface moves the pointer of the current (ResultSet) object to the first row, from the current position.This method returns a boolean value specifying whether the ResultSet cursor ...

Read More

How to display labels in the form of a 4 column table with GridLayout in Java?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 991 Views

We will displays labels in a label with 5 rows and 4 columns using GridLayout −JPanel panel = new JPanel(new GridLayout(5, 4, 10, 10));Use a for loop and loop through 1 to 20 to display 20 labels −for (int i = 1; i

Read More

C++ Program to Perform integer Partition for a Specific Case

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

This is a C++ program to perform integer partition for a specific case. In this program, a positive integer n is given, and shall have to generate all possible unique ways to represent n as sum of positive integers.AlgorithmBegin    function displayAllUniqueParts(int m):    1) Set Index of last element k in a partition to 0    2) Initialize first partition as number itself, p[k]=m    3) Create a while loop which first prints current partition, then generates next partition. The loop stops    when the current partition has all 1s.    4) Display current partition as displayArray(p, k + ...

Read More

Java ResultSet findColumn() method with example

Rishi Raj
Rishi Raj
Updated on 30-Jul-2019 1K+ Views

When we execute certain SQL queries (SELECT query in general) they return tabular data.The java.sql.ResultSet interface represents such tabular data returned by the SQL statements.i.e. the ResultSet object holds the tabular data returned by the methods that execute the statements which quires the database (executeQuery() method of the Statement interface in general).The ResultSet object has a cursor/pointer which points to the current row. Initially this cursor is positioned before first row.The findColumn() method of the ResultSet interface maps the column label to column index. Using this you can find the index of a particular column in the result set.This method accepts a String ...

Read More

How to display JTextArea in the form of a table with GridLayout in Java?

Smita Kapse
Smita Kapse
Updated on 30-Jul-2019 846 Views

Display a component in the form of rows and columns using the GridLayout. Here, we have set a panel, within which we will create a layout with 3 rows and 5 columns −JPanel panel = new JPanel(new GridLayout(3, 5, 5, 5));Now, loop through and display JTextArea from 1 to 15 i.e. 3 rows and 5 columns −for (int i = 1; i

Read More

How to center align component using BoxLayout with Java?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 7K+ 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 that specify alignment to the center of the component −panel.setAlignmentX(Component.CENTER_ALIGNMENT);The following is an example to center align component using BoxLayout −Examplepackage my; import java.awt.Component; import java.awt.Dimension; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class SwingDemo {    public static void main(String[] args) {       ...

Read More
Showing 24421–24430 of 25,466 articles
Advertisements