Create Arrow Button Positioned North in Java

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

289 Views

To create Arrow Button at position north, use BasicArrowButton:BasicArrowButton arrow = new BasicArrowButton(BasicArrowButton.NORTH);Above, we have set the arrow to NORTH. Now add it to Panel:panel.add(arrow, BorderLayout.NORTH);The following is an example to create Arrow Button positioning North:Exampleimport java.awt.BorderLayout; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.plaf.basic.BasicArrowButton; public class SwingDemo extends JPanel {    public SwingDemo() {       setLayout(new BorderLayout());       JPanel panel = new JPanel(new BorderLayout());       add(panel, BorderLayout.EAST);       BasicArrowButton arrow = new BasicArrowButton(BasicArrowButton.NORTH);       panel.add(arrow, BorderLayout.NORTH);    }    public static void main(String[] args) {       JFrame frame = ... Read More

Map IntStream to String Object in Java

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

217 Views

To Map IntStream to String object, use mapToObj and within that set the values −.mapToObj(val -> "z" + val)Before that, we used range() on IntStream −IntStream.range(1, 10)The following is an example to map IntStream to String object in Java −Exampleimport java.util.stream.IntStream; public class Demo {    public static void main(String[] args) throws Exception {       IntStream.range(1, 10)       .mapToObj(val -> "z" + val)       .forEach(System.out::println);    } }Outputz1 z2 z3 z4 z5 z6 z7 z8 z9

MySQL Search Results by Month in Format

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

84 Views

Use MONTH() and YEAR() for this. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ShippingDate datetime ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(ShippingDate) values('2019-01-21 10:40:21'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(ShippingDate) values('2015-07-01 11:15:30'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(ShippingDate) values('2012-12-31 10:45:56'); Query OK, 1 row affected (0.14 sec)Display all records from the table ... Read More

Select Specific Text in JTextArea

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

464 Views

Yes, we can do that using built-in methods of JTextArea components. Let’say the following is our JTextArea −JTextArea textArea = new JTextArea("This is a text displayed for our example. We have selected some of the text.");Now, use the methods setSelectionStart() and setSelectionEnd() to select some text in a range −textArea.setSelectionStart(5); textArea.setSelectionEnd(20);The following is an example to select some of the text in a JTextArea −Examplepackage my; import java.awt.GridLayout; import javax.swing.*; public class SwingDemo {    SwingDemo() {       JFrame frame = new JFrame("Demo");       JTextArea textArea = new JTextArea("This is a text displayed for our example. ... Read More

Turn Android Device Screen On and Off Programmatically

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

5K+ Views

This example demonstrate about How to turn Android device screen on and off programmatically.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 res/xml/policies.xml               Step 4 − Add the following code to src/DeviceAdminpackage app.tutorialspoint.com.sample ; import android.app.admin.DeviceAdminReceiver ; import android.content.Context ; import android.content.Intent ; import android.widget.Toast ... Read More

Aggregate Array Documents in MongoDB

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

226 Views

For this, use the aggregate framework. Let us first create a collection with documents −> db.aggregateArrayDemo.insertOne(    {       "_id":100,       "UserDetails": [          {             "UserName": "John",             "UserLoginYear":2010          },          {             "UserName": "Carol",             "UserLoginYear":2019          }       ]    } ); { "acknowledged" : true, "insertedId" : 100 }Following is the query to display all documents from a collection with the help of find() method −> db.aggregateArrayDemo.find().pretty();This will produce the following output −{    "_id" : 100,    "UserDetails" : [       {          "UserName" : "John",          "UserLoginYear" : 2010       },       {          "UserName" : "Carol",          "UserLoginYear" : 2019       }    ] }Following is the query to aggregate array documents −> db.aggregateArrayDemo.aggregate([    {       $match: { _id: 100 }    },    {       $project: {          Minimum: { $min: "$UserDetails.UserLoginYear" },          Maximum: { $max: "$UserDetails.UserLoginYear" }       }    } ]);This will produce the following output −{ "_id" : 100, "Minimum" : 2010, "Maximum" : 2019 }

Get List of All Drivers Registered with DriverManager Using JDBC

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

1K+ Views

The java.sql.DriverManager class manages JDBC drivers in your application. This class maintains a list of required drivers and load them whenever it is initialized.Therefore, you need to register the driver class before using it. However, you need to do it only once per application.One way to register a driver class object to Driver manager is the registerDriver() method of the DriverManager class. To this method you need to pass the Driver object as a parameter.//Instantiating a driver class Driver driver = new com.mysql.jdbc.Driver(); //Registering the Driver DriverManager.registerDriver(driver);List of all the DriversYou can get the list of all the drivers registered ... Read More

HTML DOM Input URL Pattern Property

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

268 Views

The HTML DOM Input URL pattern property sets/returns the regular expression corresponding to URL Input. The pattern attribute’s value is checked against the text typed in url field.SytaxFollowing is the syntax −Returning regular expressioninputURLObject.patternSetting pattern to regular expressioninputURLObject.pattern = ‘RegExp’ExampleLet us see an example of Input URL pattern property − Live Demo Input URL pattern    form {       width:70%;       margin: 0 auto;       text-align: center;    }    * {       padding: 2px;       margin:5px;    }    input[type="submit"] {       border-radius: 10px;   ... Read More

Implicit Return Type int in C

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

500 Views

If some function has no return type, then the return type will be int implicitly. If return type is not present, then it will not generate any error. However, C99 version does not allow return type to be omitted even if it is int.Example#include my_function(int x) {    return x * 2; } main(void) {    printf("Value is: %d", my_function(10)); }OutputValue is: 20

Map Double to Int Object Using mapToInt and mapToObj in Java

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

503 Views

At first, we have set the stream −Stream.of(3.5, 4.7, 7.9, 8.2, 9.1, 10.5, 12.3, 15.8)Now to Map double to int Object, use mapToObj −.mapToInt(Double::intValue) .mapToObj(a -> "val" + a)The following is an example to Map double to int Object with mapToInt and mapToObj −Exampleimport java.util.stream.Stream; public class Demo {    public static void main(String[] args) throws Exception {       Stream.of(3.5, 4.7, 7.9, 8.2, 9.1, 10.5, 12.3, 15.8)       .mapToInt(Double::intValue)       .mapToObj(a -> "val" + a)       .forEach(System.out::println);    } }Outputval3 val4 val7 val8 val9 val10 val12 val15

Advertisements