karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 116 of 143

Java Program to display the contents in JTextArea

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 508 Views

The following is an example to display the contents of a text file in JTextArea −Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; public class SwingDemo {    private JFrame mainFrame;    private JLabel statusLabel;    private JPanel controlPanel;    public SwingDemo() {       prepareGUI();    }    public static void main(String[] args) {       SwingDemo demo = new SwingDemo();       demo.showTextAreaDemo();    }    private void prepareGUI() {       mainFrame = new JFrame("Java Swing");       mainFrame.setSize(400, 400);       mainFrame.setLayout(new GridLayout(3, 1));       mainFrame.addWindowListener(new WindowAdapter() {     ...

Read More

What is the difference between static_cast<> and C style casting?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 4K+ Views

Here we will see what are the differences between static_cast and normal C style cast.The normal cast like (int)x is C style typecasting where static_cast(x) is used in C++.This static_cast() gives compile time checking facility, but the C style casting does not support that. This static_cast() can be spotted anywhere inside a C++ code. And using this C++ cast the intensions are conveyed much better.In C like cast sometimes we can cast some type pointer to point some other type data.Like one integer pointer can also point character type data, as they are quite similar, only difference is character has ...

Read More

How to activate and deactivate JFrame in Java

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 612 Views

Here, we are activating a frame. For deactivation, we have used dispose −Thread.sleep(2000); frame.setVisible(false);The frame first activates and then deactivates after 2 seconds since we have set sleep to 2000 miliseconds.The following is an example to activate and deactivate JFrame −Exampleimport java.awt.Frame; import javax.swing.JFrame; import javax.swing.JLabel; public class SwingDemo {    public static void main(String[] args) throws InterruptedException {       JFrame frame = new JFrame();       frame.add(new JLabel("Demo"));       frame.pack();       frame.setVisible(true);       Thread.sleep(2000);       frame.setState(Frame.ICONIFIED);       Thread.sleep(2000);       frame.setVisible(false);       frame.dispose(); ...

Read More

How to print Unicode character in C++?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 6K+ Views

To print the Unicode characters, the process is very similar to the actual printing process in C++.We can put the Unicode value with the prefix \u. Thus we can successfully print the Unicode character.Note: If the console does not support Unicode, then you cannot get the correct result. Here we have used the Linux system to solve this problem.Example#include using namespace std; int main() {    cout

Read More

Java Program to create JRadioButton from text

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 157 Views

The following is an example to create JRadioButton from text −Examplepackage my; import java.awt.FlowLayout; import java.awt.event.KeyEvent; import javax.swing.ButtonGroup; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JRadioButton; public class SwingDemo {    public static void main(String[] args) {       JRadioButton radio1 = new JRadioButton("Cricket");       JRadioButton radio2 = new JRadioButton("Football");       ButtonGroup group = new ButtonGroup();       group.add(radio1);       group.add(radio2);       radio1.setSelected(true);       JFrame frame = new JFrame();       frame.setLayout(new FlowLayout());       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       frame.add(new JLabel("Fav Sports:"));       frame.add(radio1);     ...

Read More

How can we clear all selections in Java Swing JList?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 733 Views

To clear all selections, use the List clearSelection() method in Java −JList list = new JList(sports); list.clearSelection();Above, the elements in Sports array is a String array −String sports[]= { "Cricket", "Football", "Hockey", "Rugby"};The following is an example to clear all selection in 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 main(String[] args) {       frame = new JFrame("JList Demo");       SwingDemo s = new SwingDemo();       JPanel panel = new JPanel();       String sports[]= ...

Read More

How to set minimum size limit for a JFrame in Java

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 3K+ Views

Use the setMinimumSize() method to set the minimum size limit for a JFrame −JFrame frame = new JFrame(); frame.setMinimumSize(new Dimension(500, 300));The following is an example to set minimum size limit for a JFrame −Exampleimport java.awt.Color; import java.awt.Dimension; import javax.swing.JButton; import javax.swing.JFrame; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();       JButton button = new JButton("Close!");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       frame.setContentPane(button);       button.addActionListener(e -> {          frame.dispose();       });       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       frame.setMinimumSize(new Dimension(500, ...

Read More

How to create modeless and model JDialog in Java?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 666 Views

MODELESS TypeThe following is an example to set JDialog with Modality type MODELESS −Exampleimport java.awt.Cursor; import java.awt.Dialog.ModalityType; import java.awt.Dimension; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();       frame.setSize(new Dimension(600, 400));       JDialog dialog = new JDialog(frame, "New", ModalityType.MODELESS);       dialog.setSize(300, 300);       frame.add(new JButton(new AbstractAction("Click to generate") {          @Override          public void actionPerformed(ActionEvent e) {             frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));   ...

Read More

How to get time in milliseconds using C++ on Linux?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 5K+ Views

Here we will see how to get time (the elapsed time for the program or any other kind of time).Here we are using linux library for C++. There is a structure called timeval. This timeval stores the time in seconds, milliseconds. We can create two time for start and end, then find the difference from them.Example#include #include #include using namespace std; main() {    struct timeval start_time, end_time;    long milli_time, seconds, useconds;    gettimeofday(&start_time, NULL);    cout > ch;    gettimeofday(&end_time, NULL);    seconds = end_time.tv_sec - start_time.tv_sec; //seconds    useconds = end_time.tv_usec - start_time.tv_usec; //milliseconds ...

Read More

Auto insert values into a MySQL table in a range?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 1K+ Views

For this, you can create a stored procedure. Let us first create a table.mysql> create table DemoTable    -> (    -> Value int    -> ); Query OK, 0 rows affected (0.55 sec)Following is the query to create a stored procedure to auto insert values to a table from range 10 to 20 −mysql> DELIMITER // mysql> CREATE PROCEDURE AutoInsertValuesToTable()    -> BEGIN    ->    DECLARE startingRange INT DEFAULT 10;    ->    WHILE startingRange       INSERT DemoTable(Value) VALUES (startingRange );    ->       SET startingRange = startingRange + 1;    ->   ...

Read More
Showing 1151–1160 of 1,421 articles
« Prev 1 114 115 116 117 118 143 Next »
Advertisements