Found 9150 Articles for Object Oriented Programming

What is the importance of _.initial() function in JavaScript?

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

495 Views

_.initial()_.initial() is a function in underscore.js, which is a library of javascript. This method is used to differentiate the last element of an array from the rest of the elements. This method just ignores the last value of an array.syntax_.initial( array, n );_.Initial() can take 2 parameters. array - The method takes the array and gives out all the elements except the last element.n - It is nothing but a number of elements that are to be trimmed from the given array. It is optional.ExampleLive Demo document.write(_.initial([1, 2, 3, 4, 5])); Output1, ... Read More

How can we implement the paintComponent() method of a JPanel in Java?

Alshifa Hasnain
Updated on 09-Jun-2025 14:18:44

8K+ Views

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

What is the use of _.size() method in JavaScript?

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

631 Views

_.size()_.Size() is from the underscore.js library of javascript. This is used to find the size of an array. One should make sure that before using this method one should use the CDN of the underscore.js to execute the code.syntax_.size(array);Example-1In the following example, a normal array is passed into _.size() method to get the size of the array.Live Demo var arr = [100, 62, 73, 534, 565]; document.write(_.size(arr)); Output5Example-2In the following example, an array that consists of object elements is sent into _.size() method to find the size.Live Demo ... Read More

How can we disable the maximize button of a JFrame in Java?

Alshifa Hasnain
Updated on 18-Apr-2025 17:51:16

2K+ Views

In this article, we will learn to disable the maximize button of a JFrame in Java. When creating Swing GUIs in Java, we might occasionally want to prevent users from maximizing certain windows. Removing the maximize button will do the trick for dialog windows, tool windows, or any window where a fixed size needs to be kept. What is a JFrame? A JFrame is a class from javax. swing package and it can extend java.awt.frame class. It is a top-level window with a border and a title bar. A JFrame class has many methods that can be used to customize ... Read More

What is the use of Math.hypot() function in JavaScript?

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

218 Views

Math.hypot()Math.Hypot() method is used to find the square root of the sum of the squares of the elements that are passed to it as arguments. This method is actually used to find the hypotenuse of a right-angle triangle whose sides are passed as arguments into it. syntaxMath.hypot(arg1, arg2, ....);ExampleIn the following example, sides of a right-angle triangle are passed to find the hypotenuse. If any value is can't be converted to a number then NaN will be displayed as output. Live Demo document.write(Math.hypot(7, 24)); document.write(""); document.write(Math.hypot(7, "hi")); Output25 NaNThis ... Read More

How can we implement different borders using the BorderFactory in Java?

Alshifa Hasnain
Updated on 18-Apr-2025 16:07:39

3K+ Views

In this article, we will learn to implement different borders using the BorderFactory in Java. While building graphical user interfaces (GUIs) with Java Swing, borders can be useful in structuring and managing various sections of our interface. To make it easier to develop several types of borders, Swing offers the BorderFactory class. What is a BorderFactory? The BorderFactory is a Factory class that provides different types of borders in Java BorderFactory, located in the javax.swing package, is a utility class containing static methods to create new Border objects. Because these methods internally manage border instances, you typically get reused border instances whenever ... Read More

How can we implement line wrap and word wrap text inside a JTextArea in Java?

raja
Updated on 07-Feb-2020 11:06:02

1K+ Views

A JTextArea is a multi-line text component to display text or allow the user to enter the text and it will generate a CaretListener interface when we are trying to implement the functionality of the JTextArea component. A JTextArea class inherits the JTextComponent class in Java.In the below example, we can implement a JTextArea class with a user can select either word wrap or line wrap checkboxes using the ItemListener interface.Exampleimport javax.swing.*; import java.awt.*; import java.awt.event.*; public class JTextAreaTest {    public static void main(String[] args ) {       EventQueue.invokeLater(new Runnable() {          @Override          public void run() {   ... Read More

What are the differences between a JScrollBar and a JScrollPane in Java?

Alshifa Hasnain
Updated on 18-Apr-2025 17:51:56

3K+ Views

In this article, we will learn about the differences between a JScrollBar and a JScrollPane in Java. A JScrollBar is a component, and it doesn't handle its own events whereas a JScrollPane is a Container and it handles its own events and performs its own scrolling. A JScrollBar cannot have a JScrollPane whereas a JScrollPane can have a JScrollBar. JScrollBar The object of the JScrollBar class is used to add horizontal and vertical scrollbar which allow the user to select items between a specified minimum and maximum values. A JScrollBar class is an implementation of a scrollbar and inherits the ... Read More

Is it possible to change the HTML content in JavaScript?

vineeth.mariserla
Updated on 30-Jun-2020 08:52:32

2K+ Views

Yes, it is possible to change the content of the HTML in javascript. Usually HTML content will be in HTML tags such as , , etc. In javascript, we have DOM methods that have an ability to access the HTML tags. Those methods, such as document.getElementById(), document.getElementByTagName(), etc., make use of tags to change the HTML content.Example-1In the following example, the content in the span tag is changed using a javascript DOM method document.getElementById(). Live Demo    Is javaScript is java.     Once the above code is executed, we will get the following on the screen If we click ... Read More

How many types of JDialog boxes can be created in Java?

raja
Updated on 07-Feb-2020 11:11:20

179 Views

A JDialog is a subclass of Dialog class and it does not hold minimize and maximize buttons at the top right corner of the window. We can create two types of JDialog boxes.in JavaModal DialogNon-Modal DialogModal JDialogIn Java, When a modal dialog window is active, all the user inputs are directed to it and the other parts of the application are inaccessible until this model dialog is closed.Non-Modal JDialogIn Java, When a non-modal dialog window is active, the other parts of the application are still accessible as normal and inputs can be directed to them, while this non-modal dialog window doesn't need to be ... Read More

Advertisements