Found 9150 Articles for Object Oriented Programming

What is the importance of JSeparator class in Java?

Alshifa Hasnain
Updated on 22-Apr-2025 18:28:00

243 Views

In this article, we will learn about the importance of the JSeparator class in Java. In GUI programming, appearance is highly important in creating good and user-friendly Java programs. Java Swing provides the JSeparator class as a simple but effective means of accomplishing this. What is JSeparator? A JSeparator is a horizontal or vertical line or an empty area used to split the components. A class called JSeparator is used to paint a line in order to divide the components within a Layout. The simplest way to insert a separator into a menu or a toolbar is by invoking the ... Read More

In how many ways can we find a substring inside a string in javascript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

131 Views

We can find a substring inside a string in two ways. One way is using the indexOf() method and the other is using ES6 includes() method. let's discuss them in detail.indexOf()syntaxindexOf(str);This method tries to check the index of the substring we need. If there is index, which means substring is present, then true will be displayed in the output else false will be displayed as output. This method is case sensitive. ExampleLive Demo var company = "Tutorix"; document.write(company.indexOf('Tutor') !== -1); document.write(""); document.write(company.indexOf('tutor') !== -1); Outputtrue falseincludes()syntaxincludes(str);Unlike the indexOf() ... Read More

What is the importance of JViewport class in Java?

raja
Updated on 11-Feb-2020 11:11:40

489 Views

JViewportA JViewport class defines the basic scrolling model and it is designed to support both logical scrolling and pixel-based scrolling.The viewport's child called the view is scrolled by calling JViewport.setViewPosition() method.A JViewport class supports logical scrolling, that is a kind of scrolling in which view coordinates are not pixels.To support a logical scrolling, JViewport defines a small set of methods that can be used to define the geometry of a viewport and a view. By default, these methods just report the pixel dimensions of the viewport and view.Exampleimport java.awt.*; import javax.swing.*; public class JViewportTest extends JFrame {    public JViewportTest() {       setTitle("JViewport Test"); ... Read More

In how many ways can we split a string in JavaScript?

vineeth.mariserla
Updated on 30-Jun-2020 15:51:27

417 Views

In javascript, we can split a string in 3 ways. One is an old way in which string.split() method is used and later on, ES6 has provided 2 more ways to split a string. In the first way spread operator is used and in the second way array.from() method is used. Let's discuss them in detail.String.split()syntaxstring.split();ExampleIn the following example, string.split() method is used to split the provided string to each individual character.Live Demo           const str = 'Tutorialspoint'       var d = str.split('')       document.write(d);     OutputT, u, t, o, r, i, ... Read More

What are the differences between paint() method and repaint() method in Java?

Alshifa Hasnain
Updated on 15-Apr-2025 19:15:15

7K+ Views

In this article, we will learn about the differences between the paint() method and the repaint() method in Java. In the AWT and Swing frameworks, rendering graphical components is done in two different roles by the two methods paint() and repaint(). The paint() Method This method holds instructions to paint this component. In Java Swing, we can change the paintComponent() method instead of paint() method as paint calls paintBorder(), paintComponent() and paintChildren() methods. We cannot call this method directly instead we can call repaint(). Syntax The following is the syntax: public void paint(Graphics g) { // paint() method ... Read More

How can we catch a double click and enter key events for a JList in Java?

Alshifa Hasnain
Updated on 09-Jun-2025 14:19:19

842 Views

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

How to repeat a string in JavaScript?

Yaswanth Varma
Updated on 18-Jan-2023 11:50:10

717 Views

In this article we are going to learn about how to repeat a string in JavaScript. We can find the three different ways to repeat a string in JavaScript they are listed below. using a while loop using recursion using ES6 repeat() method Let’s dive into the article to learn more about how to repeat a string in JavaScript. While loop method A while loop in JavaScript is a control flow statement that allows code to be executed repeatedly based on a given boolean condition. Syntax Following is the syntax for while loop while (condition) ... Read More

What are the differences between a Font and a FontMetrics in Java?

raja
Updated on 29-Apr-2025 19:12:54

2K+ Views

The Font class in Java is responsible for setting screen fonts, which are mapped to characters of the language in specific regions. But a FontMetrics class is said to be a font metrics object that encapsulates the data about the rendering of a specific font on a particular screen. Font A Font class can be used to create an instance of a Font object to set the font for drawing text, labels, text fields, buttons, etc, and it can be specified by its name, style, and size. Syntax The following is the syntax for Font initialization: Font font = new ... Read More

How to swap variables with destructuring in JavaScript?

vineeth.mariserla
Updated on 30-Jun-2020 15:46:43

232 Views

Swapping variables has become very easy with destructuring. In contemporary javascript swapping takes place by using another variable. It may not be hectic but it is lengthy. But in modern javascript there is no need for the third variable. Let's discuss it in detail.Example-1In the following example, swapping has done using another variable called "temp". Therefore the code got lengthier. Live Demo           var a = "Sachin";       var b = "Tendulkar";       document.write("Before swapping-"+ " "+ a + " " +b);       var tmp = a;       a = b; ... Read More

How can we set the background color to a JPanel in Java?

Alshifa Hasnain
Updated on 08-May-2025 18:46:11

16K+ Views

In this article, we will learn to set the background color of a JPanel in Java. When designing GUIs in Swing, changing the background color of panels is important for creating visually appealing applications. What is a JPanel? A JPanel is a container, and it is an invisible component in Java. The FlowLayout is a default layout for a JPanel. We can add most of the components, like buttons, text fields, labels, tables, lists, trees, etc., into a JPanel. Syntax The following is the syntax for JPanel initialization: JPanel panel = new JPanel(); Methods The important methods of JPanel are: ... Read More

Advertisements