Create Titled Border for a Panel in Java

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

582 Views

To create titled border for a panel, use the createTitledBorder() method. Let us create a panel first −JPanel panel = new JPanel(); JButton btn1 = new JButton("One"); JButton btn2 = new JButton("Two"); panel.add(btn1); panel.add(btn2);Now, set titled border with BorderFactory class −panel.setBorder(BorderFactory.createTitledBorder("Title of the border"));The following is an example to create titled border for a panel in Java −Examplepackage my; import java.awt.Component; import java.awt.Dimension; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       frame.getContentPane().setLayout(new ... Read More

Restrictions on Using Enum in Java

Venkata Sai
Updated on 30-Jul-2019 22:30:26

801 Views

Enumeration (enum) in Java is a datatype which stores a set of constant values. You can use enumerations to store fixed values such as days in a week, months in a year etc.You can define an enumeration using the keyword enum followed by the name of the enumeration as −enum Days {    SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }Points to keep in mindYou need to keep the following points in mind while declaring an enum −It is recommended to write the name of the constants in all capital letters as −public class EnumerationExample {    enum Days { ... Read More

HTML DOM Input Email Maxlength Property

AmitDiwan
Updated on 30-Jul-2019 22:30:26

112 Views

The HTML DOM Input Email maxLength property returns/sets the maxLength property for input Email. If not defined this property returns ‘-1’.SyntaxFollowing is the syntax −Returning maxLength attributeinputEmailObject.maxLengthSet maxLength property to a numberinputEmailObject.maxLength = numberExampleLet us see an example of Input Email maxLength property − Live Demo Input Email maxLength    form {       width:70%;       margin: 0 auto;       text-align: center;    }    * {       padding: 2px;       margin:5px;    }    input[type="button"] {       border-radius: 10px;    } ... Read More

Print First N Terms of Series 0.25, 0.5, 0.75 in Fraction Representation

Sunidhi Bansal
Updated on 30-Jul-2019 22:30:26

210 Views

Input N which is equivalent to the number till where series should be printedInput : N=5 Output : 0 ¼ ½ ¾ 1AlgorithmSTART Step 1 -> declare start variables as int num , den, i, n Step 2 -> input number in n Step 3 -> Loop For from i to 0 and i End For Loop STOPExample#include int main(int argc, char const *argv[]) {    int num, den;    int i, n;    printf("Enter series limit");    scanf("%d", &n); //Till where the series will be starting from zero    for (i = 0; i < n; i++) { ... Read More

Setjmp and Longjmp in C

Smita Kapse
Updated on 30-Jul-2019 22:30:26

3K+ Views

In this section, we will see what are the setjump and longjump in C. The setjump() and longjump() is located at setjmp.h library. The syntax of these two functions is like below.setjump(jmp_buf buf) : uses buf to store current position and returns 0. longjump(jmp_buf buf, i) : Go back to place pointed by buf and return i.These are used in C for exception handling. The setjump() can be used as try block, and longjump() can be used as throw statement. The longjump() transfers control the pointe which is pointed by setjump().Here we will see how to print a number 100 ... Read More

Convert Time from 12-Hour to 24-Hour Format in C++

Smita Kapse
Updated on 30-Jul-2019 22:30:26

1K+ Views

This is a C++ program to convert time from 12 hour to 24 hour format.AlgorithmBegin    In main(),    If median = pm       Check if entered hours is less than 12          Then add 12 to hours and print the time in 24 hours format.       Check if entered hours is equal to 12          Then print “00” as hours and print the time in 24 hours format.    Else If median=am       Check if entered hours is less than 12          Then print ... Read More

Check Installed MongoDB Version Using Command Line

Smita Kapse
Updated on 30-Jul-2019 22:30:26

12K+ Views

First open the CMD and then reach the BIN directory of MongoDB. The screenshot to open CMD prompt is as follows.Above we have reached the RUN dialog by pressing START and then typing RUN and ENTER.Now, type CMD and press OK button to get the command line. The screenshot is as follows −Reach the BIN directory of MongoDB. Following is how to reach the BIN −Use the query mongo –version. The screenshot of the query is as follows −Above displays that our current MongoDB version is v4.0.5.

Combine BorderLayout, GridLayout, and FlowLayout in Java Swing

Anvi Jain
Updated on 30-Jul-2019 22:30:26

1K+ Views

Here, we have set panels with BorderLayout, GridLayout and FlowLayout. Within the panels, we have created components such as Button, ComboBox, etc. The following is an example to combine layouts in Java −Examplepackage my; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridLayout; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JPanel; public class SwingDemo {    public static void main(String[] args) {       JButton btnA = new JButton("Button1 (Left)");       JButton btnB = new JButton("Button2 (Right)");       JButton btnC = new JButton("Button3 (Left)");       JButton btnD = new JButton("Button4 (Right)");       ... Read More

Comparison of Exception Handling in C++ and Java

Smita Kapse
Updated on 30-Jul-2019 22:30:26

309 Views

The exception handling feature is present almost any object oriented languages nowadays. In C++ and Java also we can get this kind of feature. There are some similarities between exception handling in C++ and exception handling in Java, like in both languages we have to use the try-catch block. Though there are some difficulties also. These are like below −In C++, we can throw any type of data as exception. Any type of data means primitive datatypes and pointers also. In Java we can only throw the throwable objects. Subclasses of any throwable class will also be throwable.Example Live Demo#include ... Read More

What are Enumerations in Java and How to Retrieve Values from an Enum

Venkata Sai
Updated on 30-Jul-2019 22:30:26

631 Views

Enumeration (enum) in Java is a datatype which stores a set of constant values. You can use enumerations to store fixed values such as days in a week, months in a year etc.You can define an enumeration using the keyword enum followed by the name of the enumeration as −enum Days {    SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }Just like arrays, the elements/constants in an enumeration are identified using numbers starting from 0 in the above example the days are identified using numbers as shown in the following illustration −Retrieving values from an enumYou can retrieve all the ... Read More

Advertisements