Samual Sam has Published 2310 Articles

What happen when we exceed valid range of built-in data types in C++?

Samual Sam

Samual Sam

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

415 Views

Here we will see what will be the results, if we exceed the range of built-in datatypes in C++. So let us see some examples.First one is the character type data. Here we are using a loop from 0 to 300, so it should print from 0 to 300, then ... Read More

When are Constructors Called in C++?

Samual Sam

Samual Sam

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

660 Views

Here we will see, when constructors are called. Here constructors are of different types. Global, local, static local, dynamic.For the global object, the constructors are called before entering into the main function.Example#include using namespace std; class MyClass {    public:       MyClass() {          cout

How to execute a command and get output of command within C++ using POSIX?

Samual Sam

Samual Sam

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

865 Views

Here we will see how to use the POSIX command through C++. The process is very simple, we have to use the function called system(). Inside this we have to pass string. That string will contain the POSIX command. The syntax is like below.system(“command”)Example#include using namespace std; int main () ... Read More

How to create FileFilter for JFileChooser in Java and display File Type accordingly?

Samual Sam

Samual Sam

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

979 Views

To create FileFilter, use the FileNamExtensionFilter class. The following is an example to display File Type in JFileChooser −Exampleimport javax.swing.JFileChooser; import javax.swing.filechooser.FileNameExtensionFilter; public class SwingDemo {    public static void main(String[] args) {       JFileChooser file = new JFileChooser();       file.setAcceptAllFileFilterUsed(false);       FileNameExtensionFilter extFilter ... Read More

How do I generate random floats in C++?

Samual Sam

Samual Sam

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

4K+ Views

In C or C++, we cannot create random float directly. We can create random floats using some trick. We will create two random integer values, then divide them to get random float value.Sometimes it may generate an integer quotient, so to reduce the probability of that, we are multiplying the ... Read More

How to get Directories from JFileChooser in Java

Samual Sam

Samual Sam

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

217 Views

To get directories from JFileChoose, use the mode setFileSelectionMode −JFileChooser file = new JFileChooser(); file.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);The following is an example to get Directories from JFileChooser −Exampleimport javax.swing.JFileChooser; public class SwingDemo {    public static void main(String[] args) {       JFileChooser file = new JFileChooser(); file.setMultiSelectionEnabled(false);         ... Read More

How to make the program sleep for x milliseconds in C++?

Samual Sam

Samual Sam

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

529 Views

Here we will see how to sleep for x (given by user) milliseconds in C++ program.To do this thing we can use different libraries. But here we are using the clock() function. The clock() will return the current CPU time. Here we will try to find the ending time from ... Read More

How to create JFrame with no border and title bar in Java?

Samual Sam

Samual Sam

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

713 Views

To create a JFrame with no border and title bar, use setUndecorated() −JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setPreferredSize(new Dimension(400, 300)); frame.setUndecorated(true);The following is an example to create JFrame with no border and title bar −Exampleimport java.awt.Dimension; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public ... Read More

How to add background Image to JFrame in Java

Samual Sam

Samual Sam

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

16K+ Views

To add background image to JFrame, use the getImage() method of the Image class −Image img = Toolkit.getDefaultToolkit().getImage("E:\rahul.jpg");Now, draw the image −public void paintComponent(Graphics g) {    super.paintComponent(g);    g.drawImage(img, 0, 0, null); }The following is an example to add Background Image to JFrame −Exampleimport java.awt.Graphics; import java.awt.Image; import java.awt.Toolkit; ... Read More

How to select the second index in Java JList?

Samual Sam

Samual Sam

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

397 Views

To select the second index, use the setSelectedIndex() method −JList new JList(sports); list.setSelectedIndex(2);The following is an example to select the second index in Java JList −Examplepackage my; import java.awt.event.*; import java.awt.*; import javax.swing.*; class SwingDemo extends JFrame {    static JFrame frame;    static JList list;    public static void ... Read More

Advertisements