In this article, we will learn to show/hide the echo character of a JPasswordField in Java. The password in this will be hidden with *. And we will be using the setEchoChar() method to toggle between hidden and visible text in a Swing based application. What is a JPasswordField? A JPasswordField is a subclass of JTextField, and each character entered in a JPasswordField can be replaced by an echo character. This allows confidential input for passwords. By default, the echo character is the asterisk(*). The important methods of JPasswordField are get password(), getText(), getAccessibleContext() and etc. What is the echo ... Read More
In this article, we will learn to catch a double click and enter key events for a JList in Java. We will be using Java Swing to detect double click and Enter key events on a JList. When we double click an item in the list or press "Enter" key after selecting an item, the selected item is displayed. What is a JList? A JList can extend the JComponent class, which allows us to choose either a single or multiple selections. A JList can generate a ListSelectionListener interface, and it includes one abstract method, valueChanged(). Below is the graphical representation ... Read More
In this article, we will learn to implement the paintComponent() method of a JPanel in Java. In Swing, custom rendering of components is achieved by overriding the paintComponent() method. What is a JPanel? A JPanel is a lightweight container and it is an invisible component in Java. A JPanel's default layout is FlowLayout. After the JPanel has been created, other components can be added to the JPanel object by calling its add() method inherited from the Container class. What is a paintComponent() Method? The paintComponent() method is needed to draw something on a JPanel other than drawing the background color. This ... Read More
JWindow is a Swing component that is used to create a splash screen easily as splash screen as it displays a screen without a title bar or window management buttons. In this article, we will learn to implement a splash screen using JWindow in Java. What is a JWindow? A JWindow is a container that can be displayed anywhere on the user's desktop. It does not have the title bar, window management buttons, etc, like a JFrame. The JWindow contains a JRootPane as its only child class. The contentPane can be the parent of any children of the JWindow. Like a ... Read More
List is one of the built-in data types in Python, which is a sequence of comma-separated items, enclosed in square brackets [ ]. For example, consider the following lists as input - list1 = [5, 10, 15, 20, 25] list2 = [2, 5, 6, 7, 10, 15, 18, 20] list3 = [10, 20, 30, 40, 50, 60] We will find the common elements in three lists, and the output returned should be - [10, 20] Following are the ways to find common elements in three lists using Sets in Python - Using set.intersection() The set.intersection() method is used ... Read More
In this article, we will learn how to create a simple calculator using a switch-case statement that can perform basic arithmetic operations, such as addition, subtraction, multiplication, or division. If you want to know about switch case, you can refer to this Java switch-case tutorial. Generating a Calculator Using Switch CaseFollowing is the algorithm to generate a calculator using the switch case - Initialize a Scanner object to take user input. ... Read More
In this article, we will understand how to print a multiplication table in triangular form. To print in triangular form, the table will display row and column-wise. And in every row, entries will be up to the same column number. Below is a demonstration of the same - Input : rows = 7 Output: 1 2 4 3 6 9 4 8 12 16 5 10 15 20 25 6 12 18 24 30 36 7 14 21 28 35 42 49 Multiplication Table in a Triangular Shape Multiplication table in triangular form is achieved using a nested ... Read More
In this article, we will understand how to display the factors of a number. Factors are numbers that divide the original number without leaving a remainder. For example, 1, 2, 3, 4, 6, and 12 are factors of 12. If a and b are factors of a number, then a x b is also a factor of the number. If we multiply 3 and 5, we get 15. We say that 3 and 5 are factors of 15. The largest factor of any number is the number itself, and the smallest factor is 1. 1 ... Read More
You are given a number and you need to write a C++ program to check whether a number can be expressed as sum of two prime numbers. Input / Output Scenarios Following is the input-output statement: Input: n = 19 Output: 19 can be expressed as the sum of two prime numbers. Explanation: 19 = 17 + 2, and both 17 and 2 are prime numbers. Input: n = 36 Output: 36 can be expressed as the sum of two prime numbers. Explanation: 36 = 31 + 5, and both 31 and 5 are prime numbers. C++ Program ... Read More
Zooming digits means printing the digits of a given number in an enlarged form using special characters. In this article, we will learn to print (display) enlarged (zoomed) form of the digits of a given number. Below is the representation of digits 01438 in zoom format, Example of Zoom Digits in Integers Form To generate the zoomed digit, we define the pattern logic for each digit based on its respective function prototype. Then, we create a function that sets the switch-case logic which processes the selected digit based on either user input or a given number. In this example, ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP