Change JButton Text Dynamically in Java

raja
Updated on 10-Feb-2020 10:41:10

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

Use MySQL IF Function Within SELECT Statement

Monica Mona
Updated on 10-Feb-2020 10:40:37

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

Effect of Negative Value in MySQL TRUNCATE Function

Sravani S
Updated on 10-Feb-2020 10:39:10

418 Views

If we specify the negative value of the second argument then the digits before the decimal point would be deleted without 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 TRUNCATE() function.  mysql> Select TRUNCATE(1789.456, -1); +-----------------------+ | TRUNCATE(1789.456, -1) | +-----------------------+ |                  1780 | +-----------------------+ 1 row in set (0.00 sec)  The query above returns 1780 because the first digit before the decimal point ... Read More

Effect of Negative Second Argument on MySQL ROUND Function

Priya Pallavi
Updated on 10-Feb-2020 10:37:50

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

Median in a Stream of Integers in C++

Narendra Kumar
Updated on 10-Feb-2020 10:23:36

170 Views

Problem statementGiven that integers are read from a data stream. Find median of elements read so for in an efficient wayAfter reading 1st element of stream - 10 -> median - 10After reading 2nd element of stream - 10, 20 -> median - 15After reading 3rd element of stream - 10, 20, 30 -> median - 20, so on...Algorithm1. Use a max heap on left side to represent elements that are less than effective median,    and a min heap on right side to represent elements that are greater than effective median 2. After processing an incoming element, the number ... Read More

Mean and Mode in SQL Server

Narendra Kumar
Updated on 10-Feb-2020 10:08:33

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

Display Value When Selecting a JList Item in Java

raja
Updated on 10-Feb-2020 10:04:57

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
Updated on 10-Feb-2020 10:00:19

848 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
Updated on 10-Feb-2020 09:55:41

336 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
Updated on 10-Feb-2020 09:51:50

472 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

Advertisements