Set a Table in a JPanel in Java

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

1K+ Views

Let us first set rows and columns for our table −String[][] rec = {    { "1", "Steve", "AUS" },    { "2", "Virat", "IND" },    { "3", "Kane", "NZ" },    { "4", "David", "AUS" },    { "5", "Ben", "ENG" },    { "6", "Eion", "ENG" }, }; String[] header = { "Rank", "Player", "Country" };Now, set the above in a table as rows and columns −JTable table = new JTable(rec, header);Add the table in the panel −JPanel panel = new JPanel(); panel.add(new JScrollPane(table));The following is an example to create a table in a panel −Examplepackage my; ... Read More

Retrieve Embedded Object as Document via Aggregation Framework in MongoDB

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

324 Views

To retrieve an embedded object as a document, use the aggregation $replaceRoot. Let us first create a collection with documents −> db.embeddedObjectDemo.insertOne(    { _id: new ObjectId(),       "UserDetails": { "UserName": "John", "UserAge": 24, "UserEmailId": "John22@gmail.com" }    } ); {    "acknowledged" : true,    "insertedId" : ObjectId("5ced580fef71edecf6a1f693") } > db.embeddedObjectDemo.insertOne( { _id: new ObjectId(), "UserDetails": { "UserName": "Carol", "UserAge": 26, "UserEmailId": "Carol123@gmail.com" } } ); {    "acknowledged" : true,    "insertedId" : ObjectId("5ced5828ef71edecf6a1f694") }Following is the query to display all documents from a collection with the help of find() method −> db.embeddedObjectDemo.find().pretty();This will produce the ... Read More

Sum of the First N Prime Numbers

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

3K+ Views

The program to print the sum of the first N prime numbers uses the method to find n prime numbers and then add them to find the sum. This sum is saved to an integer that outputs the sum .The code takes a number checks it for prime, if it is prime then adds it to the sum variable. Till n prime number it does the same and then after that it prints the sum.Example Code Live Demo#include int isprime(int j) {    int count=0;    for(int i = 2 ; i

Selenium RC Separate Drivers for Each Browser

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

147 Views

Before we answer the above question, let's understand the architecture on which the selenium RC works upon. RC uses a JavaScript Program called the Selenium core which controls the browser. It works by intimating the user action as commanded by the JavaScript commands but that does not enforce user to write automated test cases in the only JavaScript, let’s see how does RC make that happen.The above diagram depicts the brief architecture of the Selenium RC. (Image Courtesy: www.seleniumhq.org )Now as it is evident that the application under test was being executed on a different system, we can say that selenium ... Read More

Convert Numbers to Millions and Billions Format in MySQL

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

2K+ Views

You can use FORMAT() from MySQL to convert numbers to millions and billions format. Let us first create a table−mysql> create table DemoTable    (    Value BIGINT    ); Query OK, 0 rows affected (0.74 sec)Insert records in the table using insert command −mysql> insert into DemoTable values(78000000000); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(10000000000); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(90000000000); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(450600000000); Query OK, 1 row affected (0.41 sec)Display all records from the table using select statement ... Read More

MySQL Query to Search Exact Word from String

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

2K+ Views

To search exact word from string, use the below syntax −select *from yourTableName where yourColumnName regexp '(^|[[:space:]])yourWord([[:space:]]|$)';Let us first create a table −mysql> create table DemoTable    (    Title text    ); Query OK, 0 rows affected (0.23 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('This is the Introduction to Java'); Query OK, 1 row affected (0.05 sec) mysql> insert into DemoTable values('This is the Introduction to MongoDB'); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable values('This is the Introduction to MySQL'); Query OK, 1 row affected (0.06 ... Read More

Make a Canvas in Java Swing

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

4K+ Views

To make a canvas with Java Swing, use the Graphics2D class −public void paint(Graphics g) {    Graphics2D graphic2d = (Graphics2D) g;    graphic2d.setColor(Color.BLUE);    graphic2d.fillRect(100, 50, 60, 80); }Above, we have created a rectangle and also added color to it.The following is an example to make a canvas in Java −Examplepackage my; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JFrame; import javax.swing.JPanel; public class SwingDemo extends JPanel {    @Override    public void paint(Graphics g) {       Graphics2D graphic2d = (Graphics2D) g;       graphic2d.setColor(Color.BLUE);       graphic2d.fillRect(100, 50, 60, 80);    }    public ... Read More

Dynamically Build MongoDB Query

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

2K+ Views

To build query dynamically, you need to write some script. Let us first create a collection with documents −> db.dynamicQueryDemo.insertOne({"Name":"John", "Subject":["MongoDB", "MySQL"]}); {     "acknowledged" : true,     "insertedId" : ObjectId("5cef5c5def71edecf6a1f69a") } > db.dynamicQueryDemo.insertOne({"Name":"John", "Subject":["C", "C++"]}); {     "acknowledged" : true,     "insertedId" : ObjectId("5cef5c73ef71edecf6a1f69b") } > db.dynamicQueryDemo.insertOne({"Name":"John", "Subject":["MongoDB", "Java"]}); {     "acknowledged" : true,     "insertedId" : ObjectId("5cef5c8bef71edecf6a1f69c") }Display all documents from a collection with the help of find() method −> db.dynamicQueryDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cef5c5def71edecf6a1f69a"),    "Name" : "John",    "Subject" : [       ... Read More

1's and 2's Complement of a Binary Number

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

5K+ Views

Binary Number is expressed in base 2. It uses only two digits ‘0’ and ‘1’. Each digit in a binary number is a bit.Sample binary Number − 01000101111’s ComplementOne's complement of a binary number is obtained by reversing the digits of the binary number i.e. transforming 1 with 0 and 0 with 1.Example1’s Complement of 101100 = 0100112’s ComplementTwo’s complement of a binary number is obtained by adding one to the one’s complement of a binary number i.e. 1’s complement + 1.Example2’s complement of 101101 is 010011.Example CodeCode to find One’s and two’s complement −#include #include using namespace std; ... Read More

What Can Selenium WebDriver Do?

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

437 Views

Selenium’s Webdriver is an automation testing tool. It can help us automate a task that was otherwise done by people.Anywhere there is a need for a human to repeat an action; we can put selenium to use.Below are the some basic and most common usages of selenium −Automation TestingIt automates web application testing by imitating the user action on a web application using selenium commands. It imitates real actions by handling mouse and keyboard events. WebDriver talks to the OS directly using the OS’s native capability. It uses browser driver for this communicationPerformance TestingBy putting the Selenium Grid to use, ... Read More

Advertisements