Add Internal Frame to a JDesktopPane in Java

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

705 Views

At first, create a JDesktoPane −JDesktopPane desktopPane = new JDesktopPane();Now, create an Internal frame and add it to the JDesktopPane −JInternalFrame intFrame = new JInternalFrame("Our Frame", true, true, true, true); desktopPane.add(intFrame); The following is an example to add Internal Frame to a JDesktopPane − package my; import java.awt.BorderLayout; import javax.swing.JButton; import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JLabel; public class SwingDemo {    public static void main(final String[] args) {       JFrame frame = new JFrame();       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       JDesktopPane desktopPane = new JDesktopPane();       JInternalFrame intFrame = new JInternalFrame("Our Frame", true, ... Read More

Return Specific Values from a MongoDB Query

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

205 Views

Yes, using map(). Let us first create a collection with documents −> dblistOfSpecificValuesDemoinsertOne({"StudentName":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cefcc8fef71edecf6a1f6bb") } > dblistOfSpecificValuesDemoinsertOne({"StudentName":"Chris"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cefcc94ef71edecf6a1f6bc") } > dblistOfSpecificValuesDemoinsertOne({"StudentName":"Robert"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cefcc98ef71edecf6a1f6bd") } > dblistOfSpecificValuesDemoinsertOne({"StudentName":"David"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cefcc9cef71edecf6a1f6be") }Following is the query to display all documents from a collection with the help of find() method −> dblistOfSpecificValuesDemofind();Output{ "_id" : ObjectId("5cefcc8fef71edecf6a1f6bb"), "StudentName" : "John" } { "_id" : ObjectId("5cefcc94ef71edecf6a1f6bc"), "StudentName" : "Chris" } { "_id" : ObjectId("5cefcc98ef71edecf6a1f6bd"), "StudentName" : "Robert" } ... Read More

Get LocalDateTime Object from Java SQL Date using JDBC

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

4K+ Views

The java.time package of Java8 provides a class named LocalDateTime is used to get the current value of local date and time. Using this in addition to date and time values you can also get other date and time fields, such as day-of-year, day-of-week and week-of-year.Converting java.sql.Date to LocalDateTimeThe java.sql.TimeStamp class provides a method with name toLocalDateTime() this method converts the current timestamp object to a LocalDateTime object and returns it.To convert date to LocalDateTime object.Create a Timestamp object from Date object using the getTime() method as −Date date = rs.getDate("DispatchDate"); //Converting Date to Timestamp Timestamp timestamp = new Timestamp(date.getTime());Now, ... Read More

Get Memory Usage at Runtime Using C++

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

8K+ Views

We can get the memory usage like virtual memory usage or resident set size etc. at run time. To get them we can use some system libraries. This process depends on operating systems. For this example, we are using Linux operating system.So here we will see how to get the memory usage statistics under Linux environment using C++. We can get all of the details from “/proc/self/stat” folder. Here we are taking the virtual memory status, and the resident set size.Example#include #include #include #include #include using namespace std; void mem_usage(double& vm_usage, double& resident_set) {   ... Read More

Set Android Notification to a Specific Date in the Future

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

3K+ Views

This example demonstrate about How to set an Android notification to a specific date in the future.Step 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.AlarmManager ; import android.app.DatePickerDialog ; import android.app.Notification ; import android.app.PendingIntent ; import android.content.Context ; import android.content.Intent ; import android.os.Bundle ; import android.support.v4.app.NotificationCompat ; import android.support.v7.app.AppCompatActivity ; import android.view.View ; import android.widget.Button ; import android.widget.DatePicker ; ... Read More

Limited Contention Protocols

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

7K+ Views

Limited Contention Protocols are the media access control (MAC) protocols that combines the advantages of collision based protocols and collision free protocols. They behave like slotted ALOHA under light loads and bitmap protocols under heavy loads.ConceptIn computer networks, when more than one station tries to transmit simultaneously via a shared channel, the transmitted data is garbled, an event called collision. In collision based protocols like ALOHA, all stations are permitted to transmit a frame without trying to detect whether the transmission channel is idle or busy. In slotted ALOHA, the shared channel is divided into a number of discrete time ... Read More

Position Component at the Top of the Grid Cell with GridBagLayout in Java

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

709 Views

To position components at the top fo the grid cell, set the GridBagConstraints. Let’s say we have a panel and within that two CheckBox components −JPanel panel1 = new JPanel(new GridBagLayout()); JCheckBox checkBox1 = new JCheckBox("Undergraduate"); JCheckBox checkBox2 = new JCheckBox("Graduate");Position the components now −panel1.add(checkBox1, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,    GridBagConstraints.NORTH, GridBagConstraints.NORTH, new Insets(0, 0, 0, 0), 0, 0)); panel1.add(checkBox2, new GridBagConstraints(1, 0, 1, 1, 2.0, 0.0,    GridBagConstraints.NORTH, GridBagConstraints.NORTH, new Insets(0, 0, 0, 0), 0, 0));The following is an example to position component at the top of the grid cell with GridBagLayout −Examplepackage my; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; ... Read More

Convert Object to an Array in PHP

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

9K+ Views

In a PHP application, we are working with data in various formats such as string, array, objects or more...In a real-time application, we may need to read a php object result in the form of an associative array to get the desired output.So we will discuss here how to transform a php object to an associative array in PHP.Let's explain what is an object and associative array in PHP? An object is an instance of a class meaning that from one class you can create many objects. It is simply a specimen of a class and has memory allocated. While ... Read More

HTML Button Name Attribute

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

440 Views

The name attribute of the element is used to set the name for a button. More than one button can have the same name, but we can submit different values from these buttons using the name attribute.Following is the syntax −Above, btn_name is the name of the button. Let us now see an example to implement the name attribute if the element −Example Live Demo Get the details of the employee: Address Phone Appraisal % OutputIn the above example, different values will ... Read More

Register JDBC Driver: Is It Mandatory?

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

788 Views

Initially, till Java6 it is needed to register the driver using Class.forname() or the registerDriver() method before establishing connection with the database.But, since Java 1.6, JDBC 4.0 API, there is no need to register the driver explicitly, You Just need to set the Class path for the JDBC 4.X driver, Java automatically detects the Driver class and loads it.ExampleIn the following JDBC program we are trying connect with MySQL database first of all include the dependency for the MySQL driver in the pom.xml of your project.    mysql    mysql-connector-java    8.0.16 Then, without registering the MySQL driver class com.mysql.jdbc.Driver ... Read More

Advertisements