Samual Sam

Samual Sam

1,507 Articles Published

Articles by Samual Sam

Page 132 of 151

How to change JFrame background color in Java

Samual Sam
Samual Sam
Updated on 30-Jul-2019 24K+ Views

At first, create a JFrame −JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setPreferredSize(new Dimension(550, 300));Now, change the background color of the JFrame −frame.getContentPane().setBackground(Color.BLUE);The following is an example to change JFrame background color −Exampleimport java.awt.Color; import java.awt.Dimension; import javax.swing.JFrame; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       frame.setPreferredSize(new Dimension(550, 300));       frame.getContentPane().setBackground(Color.BLUE);       frame.pack();       frame.setVisible(true);    } }Output

Read More

How to close JFrame on the click of a Button in Java

Samual Sam
Samual Sam
Updated on 30-Jul-2019 13K+ Views

Set frame.dispose() on the click of a button to close JFrame. At first create a button and frame −JFrame frame = new JFrame(); JButton button = new JButton("Click to Close!");Now, close the JFrame on the click of the above button with Action Listener −button.addActionListener(e -> {    frame.dispose(); });The following is an example to close JFrame on the click of a Button −Exampleimport java.awt.Color; import java.awt.Dimension; import javax.swing.JButton; import javax.swing.JFrame; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();       JButton button = new JButton("Click to Close!");   ...

Read More

C++ Program to Find k Numbers Closest to Median of S, Where S is a Set of n Numbers

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

This is a C++ Program to find k numbers closest to Median of S, where S is a set of n numbers.AlgorithmsBegin    function partition() for partitioning the array on the basis of values at high as pivot value:    Arguments:       a[]=an array.       l=low    H=high    Body of the function:    Declare variables pivot, in, i    Initialize in = l    Set pivot = h    For i=l to h-1       if(a[i] < a[pivot])          swap a[i] and a[in])       increment in.       ...

Read More

C++ Program to Find the Mode in a Data Set

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

This is a C++ program to find the Mode in a data set.AlgorithmsBegin    function insertinset() to insert data in the set.    Create newnode and temp(t) node.    Node to be inserted in the list using newnode.    If head is null then       assign new node to head and increase the count.    During insertion perform insertion sort for sorting data.    If the newnode->data is equal to any of the element present in the set,       then just increment count. EndExample#include using namespace std; struct set // a structure set to declare ...

Read More

C++ Program to Implement the Alexander Bogomolny's UnOrdered Permutation Algorithm for Elements From 1 to N

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

This is a C++ program to implement the Alexander Bogomolny’s UnOrdered Permutation Algorithm for elements from 1 to NAlgorithmsBegin    function AlexanderBogomolny() to implement the Algorithms    Arguments:       Val[] = an array       N = number of elements taken as input.       K = level       Body of the function:       intialize l = -1       l = l+1       Val[k] = l       if (l == N)          Call function display(Val, N)       else       ...

Read More

How to set default date time as system date time in MySQL?

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

You can use CURRENT_TIMESTAMP to set system date time. Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ClientFirstName varchar(20),    ClientLastName varchar(20),    ClientAge int ); Query OK, 0 rows affected (0.66 sec)Following is the query to set default datetime as system date time in MySQL −mysql> alter table DemoTable add column ClientProjectDeadline timestamp default current_timestamp; Query OK, 0 rows affected (0.46 sec) Records: 0 Duplicates: 0 Warnings: 0Let us check the description of table once again −mysql> desc DemoTable;This will produce the following output −+-----------------------+-------------+------+-----+-------------------+----------------+ | Field   ...

Read More

Create Unit Tuple from another collection in Java

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

To create Unit Tuple from another collection, use the fromCollection() method.Let us first see what we need to work with JavaTuples. To work with the Unit class in JavaTuples, you need to import the following package −import org.javatuples.Unit;Note − Steps to download and run JavaTuples program. If you are using Eclipse IDE to run Unit Class in Java Tuples, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file.The following is an example −Exampleimport java.util.*; import org.javatuples.Unit; public class Demo {    public static void main(String[] args) {   ...

Read More

How to extract part of a URL in MySQL?

Samual Sam
Samual Sam
Updated on 30-Jul-2019 3K+ Views

You need to use SUBSTRING_INDEX() function from MySQL to extract part of a URL. Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    URL text ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(URL) values('https:\www.example.com\homepage'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable(URL) values('https:\www.onlinetest.com\welcome\indexpage'); Query OK, 1 row affected (0.12 sec)Following is the query to display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output. Here, we can ...

Read More

Perform complex MySQL insert by using CONCAT()?

Samual Sam
Samual Sam
Updated on 30-Jul-2019 2K+ Views

To perform complex MySQL insert, you can use CONCAT() function. Let us see an example and create a table with StudentId and StudentFirstName.After that, complex MySQL insert will be performed and 'Web Student’ text will get inserted for every value and unique StudentId will get concatenated.The query to create first table is as follows −mysql> create table DemoTable (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentFirstName varchar(20) ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentFirstName) values('John'); Query OK, 1 row affected (0.16 sec) mysql> insert ...

Read More

How to set time data type to be only HH:MM in MySQL?

Samual Sam
Samual Sam
Updated on 30-Jul-2019 3K+ Views

You can use DATE_FORMAT() to set time data type to be only HH:MM. Following is the syntax −select DATE_FORMAT(yourColumnName, "%H:%i") AS anyAliasName from yourTableName;Let us first create a table −mysql> create table DemoTable (    Arrivaltime time ); Query OK, 0 rows affected (0.61 sec)Insert records in the table using insert command −mysql> insert into DemoTable values('08:20'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('05:40'); Query OK, 1 row affected (0.12 sec)Following is the query to display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+-------------+ | Arrivaltime ...

Read More
Showing 1311–1320 of 1,507 articles
« Prev 1 130 131 132 133 134 151 Next »
Advertisements