Articles on Trending Technologies

Technical articles with clear explanations and examples

How can we set the orientation of a JTextArea from right to left in Java?

raja
raja
Updated on 10-Feb-2020 1K+ Views

A JTextArea is a subclass of JTextComponent class and it is a multi-line text component to display the text or allow a user to enter the text. A JTextArea can generate a CaretListener interface when we are trying to implement the functionality of the JTextArea. By default, a JTextarea allows the orientation from left to right, if the user wants to enter a text from right to left by using the setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT) method of JTextArea class.Exampleimport java.awt.*; import javax.swing.event.*; import javax.swing.*; public class JTextAreaOrientationTest extends JFrame {    private JTextArea textArea;    public JTextAreaOrientationTest() {       setTitle("JTextAreaOrientation Test");       textArea = new ...

Read More

How can we combine functions in MySQL?

Chandu yadav
Chandu yadav
Updated on 10-Feb-2020 630 Views

Combining of functions in MySQL is quite possible by providing a function as the argument of other function. It is also called nesting of functions. To understand it, consider some examples belowmysql> Select UPPER(CONCAT('www.', 'tutorialspoint', '.com'))As Tutorials; +------------------------+ | Tutorials              | +------------------------+ | WWW.TUTORIALSPOINT.COM | +------------------------+ 1 row in set (0.00 sec) mysql> Select LOWER(CONCAT('WWW.', 'TUTORIALSPOINT', '.COM'))As Tutorials; +------------------------+ | Tutorials              | +------------------------+ | www.tutorialspoint.com | +------------------------+ 1 row in set (0.00 sec)The above queries combine UPPER() and LOWER() function with CONCAT() function.Similarly, we can combine more ...

Read More

How can we change the JButton text dynamically in Java?\\n

raja
raja
Updated on 10-Feb-2020 9K+ Views

A JButton is a subclass of AbstractButton and it can be used for adding platform-independent buttons in a Java Swing application. A JButon can generate an ActionListener interface when the user clicking on a button, it can also generate the MouseListener and KeyListener interfaces. By default, we can create a JButton with a text and also can change the text of a JButton by input some text in the text field and click on the button, it will call the actionPerformed() method of ActionListener interface and set an updated text in a button by calling setText(textField.getText()) method of a JButton class.Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; public ...

Read More

How can I use MySQL IF() function within SELECT statement?

Monica Mona
Monica Mona
Updated on 10-Feb-2020 4K+ Views

It is quite possible to use MySQL IF() function within SELECT statement by providing the name of the column along with a condition as the first argument of IF() function. To understand it, consider the following data from table ‘Students’.mysql> Select * from Students; +----+-----------+-----------+----------+----------------+ | id | Name      | Country   | Language | Course         | +----+-----------+-----------+----------+----------------+ | 1  | Francis   | UK        | English  | Literature     | | 2  | Rick      | USA       | English  | History        | ...

Read More

What would be effect of negative value of second argument, which specifies the number of decimal places, on the output of MySQL ROUND() function?

Priya Pallavi
Priya Pallavi
Updated on 10-Feb-2020 2K+ Views

If we specify the negative value of the second argument then the digits before the decimal point would be deleted and rounded off. The number of digits to be deleted depends upon the value of the negative second argument. Following examples will demonstrate the change, depending upon the negative value of the second argument, in the output of ROUND() function.mysql> Select ROUND(1789.456, -1); +--------------------+ | ROUND(1789.456, -1) | +--------------------+ |               1790 | +--------------------+ 1 row in set (0.00 sec)  The query above returns 1790 because the first digit (which is to be deleted ...

Read More

Mean and Mode in SQL Server

Narendra Kumar
Narendra Kumar
Updated on 10-Feb-2020 2K+ Views

Problem statementMean is the average of the given data set calculated by dividing the total sum by the number of values in the data set.Mode of a data set is the value that appears most frequently in a series of dataIf our dataset is {1, 2, 3, 4} then mean value is − (1 + 2 + 3 + 4) / 4 = 2.5If our dataset is {1, 2, 3, 4, 1, 1, 1, 1} then mode value is − 1 as it appears 5 times.ExampleFirst, create a table −CREATE TABLE NUMBERS (    value INT )Insert data into the ...

Read More

How to display a value when select a JList item in Java?

raja
raja
Updated on 10-Feb-2020 2K+ Views

A JList is a subclass of JComponent class that allows the user to choose either a single or multiple selections of items. A JList can generate a ListSelectiionListener interface and it includes one abstract method valueChanged(). We can display a value when an item is selected from a JList by implementing MouseListener interface or extending MouseAdapter class and call the getClickCount() method with single-click event (getClickCount() == 1) of MouseEvent class.Exampleimport javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class JListItemSeletionTest extends JFrame {    private JList list;    private JScrollPane jsp;    private Vector data;    public JListItemSeletionTest() {       setTitle("JListItemSeletion Test");       ...

Read More

Maximum XOR value of a pair from a range in C++

Narendra Kumar
Narendra Kumar
Updated on 10-Feb-2020 880 Views

Problem statementGiven a range [L, R], we need to find two integers in this range such that their XOR is maximum among all possible choices of two integersIf the given range is L = 1 and R = 21 then the output will be 31 as − 31 is XOR of 15 and 16 and it is maximum within range.Algorithm1. Calculate the (L^R) value 2. From most significant bit of this value add all 1s to get the final resultExample#include using namespace std; int getMaxXOR(int L, int R){    int LXR = L ^ R;    int msbPos = ...

Read More

Maximum width of a binary tree in C++

Narendra Kumar
Narendra Kumar
Updated on 10-Feb-2020 350 Views

Problem statementGiven a binary tree, write a function to get the maximum width of the given tree. The width of a tree is the maximum of widths of all levels.Consider below tree −      10      / \     7   4    / \   \   9   2   1          / \         2   5 1. Width at level 1: 1 2. Width at level 2: 2 3. Width at level 3: 3 4. Width at level 4: 2 For above tree answer is 3.Algorithm1. Use ...

Read More

Maximum weight transformation of a given string in C++

Narendra Kumar
Narendra Kumar
Updated on 10-Feb-2020 495 Views

Problem statementGiven a string consisting of only A’s and B’s. We can transform the given string to another string by toggling any character. Thus many transformations of the given string are possible. The task is to find the Weight of the maximum weight transformation.Weight of a sting is calculated using below formula −Weight of string = Weight of total pairs + weight of single characters - Total number of toggles.Two consecutive characters are considered a pair only if they are different.Weight of a single pair (both characters are different) = 4Weight of a single character = 1If the input string ...

Read More
Showing 49891–49900 of 61,248 articles
Advertisements