Java Program to place component in bottom-right corner with BorderLayout

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

860 Views

We have created a button component here, which will places in bottom-right corner −JButton button = new JButton("This is Demo Text!"); button.setBackground(Color.blue); button.setForeground(Color.white);Create panels now to arrange the above created button component in the bottom right −JPanel bottomPanel = new JPanel(new BorderLayout()); bottomPanel.add(button, BorderLayout.LINE_END); JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.add(bottomPanel, BorderLayout.PAGE_END);The following is an example to place a component in bottom-right corner with BorderLayout −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class SwingDemo {    public static void main(String[] args) {       JButton button = new JButton("This is Demo Text!");   ... Read More

How can I get a file's size in C++?

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

12K+ Views

To get a file’s size in C++ first open the file and seek it to the end. tell() will tell us the current position of the stream, which will be the number of bytes in the file.Example Live Demo#include #include using namespace std; int main() {    ifstream in_file("a.txt", ios::binary);    in_file.seekg(0, ios::end);    int file_size = in_file.tellg();    cout

How to implement constants in java?

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

1K+ Views

A constant variable is the one whose value is fixed and only one copy of it exists in the program. Once you declare a constant variable and assign value to it, you cannot change its value again throughout the program.You can create a constant in c language using the constant keyword (one way to create it) as −const int intererConstant = 100; or, const float floatConstant = 16.254; ….. etcConstants in javaUnlike in C language constants are not supported in Java(directly). But, you can still create a constant by declaring a variable static and final.Static − Once you declare a ... Read More

HTML DOM Input Month Object

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

83 Views

The HTML DOM input month Object represent the element with type=”month”.Let us create input month object −SyntaxFollowing is the syntax −var monthInput = document.createElement(“INPUT”); monthInput.setAttribute(“type”, ”month”);PropertiesFollowing are the properties of HTML DOM input month Object −PropertyExplanationautocompleteIt returns and alter the value of the autocomplete attribute of month input field.autofocusIt returns and modify whether the input month field should get focused or not when page load.disabledIt returns and modify whether the input month field is disabled or not.defaultValueIt returns and alter the default value of the input month field.formIt returns the reference of the form that contain the input month ... Read More

A Product Array Puzzle in C++?

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

156 Views

Here we will see one interesting problem related to array. There is an array with n elements. We have to create another array of n elements. But the i-th position of second array will hold the product of all elements of the first array except the i-th element. And one constraint is that we cannot use the division operator in this problem.If we can use the division, operation, we can easily solve this problem, by getting the product of all elements, then divide i-th element of first array and store it into i-th place of the second array.Here we are ... Read More

Print n smallest elements from given array in their original order

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

173 Views

Given with array of let’s say k elements the program must find the n smallest elements amongst them in their appearing order.Input : arr[] = {1, 2, 4, 3, 6, 7, 8}, k=3 Ouput : 1, 2, 3 Input k is 3 it means 3 shortest elements among the set needs to be displayed in original order like 1 than 2 and than 3AlgorithmSTART Step 1 -> start variables as int i, max, pos, j, k=4 and size for array size Step 2 -> Loop For i=k and i=0 and j--       If arr[j]>max         ... Read More

Get attribute list from MongoDB object?

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

856 Views

To get attribute list from MongoDB object, you can use for loop to extract key and value for document. Let us create a collection with documents −>db.getAttributeListDemo.insertOne({"StudentId":101, "StudentName":"John", "StudentAdmissi onDate":new ISODate('2019-01-12'), "StudentSUbjects":["MongoDB", "Java", "MySQL"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbdfcc9ac184d684e3fa269") }Display all documents from a collection with the help of find() method −> db.getAttributeListDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cbdfcc9ac184d684e3fa269"),    "StudentId" : 101,    "StudentName" : "John",    "StudentAdmissionDate" : ISODate("2019-01-12T00:00:00Z"),    "StudentSUbjects" : [       "MongoDB",       "Java",       "MySQL"    ] }Following is the ... Read More

How to disable JCheckBox if not checked in Java

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

519 Views

The following is an example to disable JCheckBox if not checked in Java:Exampleimport java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JCheckBox; import javax.swing.JOptionPane; public class SwingDemo {    public static void main(String[] args) {       JCheckBox checkBox = new JCheckBox("Demo", true);       checkBox.addActionListener(new ActionListener() {          public void actionPerformed(ActionEvent e) {             if (checkBox.isEnabled())                checkBox.setEnabled(false);             else                checkBox.setEnabled(true);          }       });       JOptionPane.showMessageDialog(null, checkBox);    } }OutputNow, when you will uncheck the above checkbox, it will get disabled:

Java DatabaseMetaData supportsBatchUpdates() method with example

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

164 Views

The supportsBatchUpdates() method of the DatabaseMetaData interface is used to determine whether the underlying database supports batch updates.This method returns a boolean value which is −True, when the underlying database supports stored porcedures.False, when the underlying database doesn't support stored porcedures.To determine whether the underlying database supports stored porcedures −Make sure your database is up and running.Register the driver using the registerDriver() method of the DriverManager class. Pass an object of the driver class corresponding to the underlying database.Get the connection object using the getConnection() method of the DriverManager class. Pass the URL the database and, user name, password of ... Read More

Reverse array field in MongoDB?

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

190 Views

To reverse array field in MongoDB, you can use forEach(). Let us first create a collection with documents −> db.reverseArrayDemo.insertOne({"Skills":["C", "Java"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ccddf99dceb9a92e6aa1946") }Following is the query to display all documents from a collection with the help of find() method −> db.reverseArrayDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5ccddf99dceb9a92e6aa1946"),    "Skills" : [       "C",       "Java"    ] }Here is the query to reverse array field in MongoDB −> db.reverseArrayDemo.find().forEach(function (myDocument) { ...    var arrayValue = [ myDocument.Skills[1], myDocument.Skills[0] ]; ...    db.reverseArrayDemo.update(myDocument, { ... Read More

Advertisements