Create JRadioButton from Text in Java

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

147 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

List Available Notification Sounds on Android

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

440 Views

This example demonstrate about How to bring up list of available notification sounds on AndroidStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.package app.tutorialspoint.com.notifyme ; import android.app.Activity ; import android.app.NotificationChannel ; import android.app.NotificationManager ; import android.content.Intent ; import android.media.RingtoneManager ; import android.net.Uri ; import android.os.Bundle ; import android.support.annotation. Nullable ; import android.support.v4.app.NotificationCompat ; import android.support.v7.app.AppCompatActivity ; import android.view.View ; public class ... Read More

MongoDB Update Method to Set Entire Field Records

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

103 Views

You can use $set operator along with update(). Let us first create a collection with documents −> db.workingOfUpdateMethod.insertOne({"ClientCountryName" : "AUS"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd506fe2cba06f46efe9efa") } > db.workingOfUpdateMethod.insertOne({"ClientCountryName" : "AUS"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd507022cba06f46efe9efb") } > db.workingOfUpdateMethod.insertOne({"ClientCountryName" : "AUS"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd507022cba06f46efe9efc") } > db.workingOfUpdateMethod.insertOne({"ClientCountryName" : "AUS"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd507032cba06f46efe9efd") }Following is the query to display all documents from a collection with the help of find() method −> db.workingOfUpdateMethod.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cd506fe2cba06f46efe9efa"), "ClientCountryName" ... Read More

Create DefaultTableModel Implementation of TableModel

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

9K+ Views

Let us create DefaultTableModel −DefaultTableModel tableModel = new DefaultTableModel();Now, set the model to JTable −JTable table = new JTable(tableModel);Add a column −tableModel.addColumn("Languages");Now, we will add rows to our table −tableModel.insertRow(0, new Object[] { "CSS" }); tableModel.insertRow(0, new Object[] { "HTML5" });The following is an example to create DefaultTableModel −Examplepackage my; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; public class SwingDemo {    public static void main(String[] argv) throws Exception {       DefaultTableModel tableModel = new DefaultTableModel();       JTable table = new JTable(tableModel);       tableModel.addColumn("Languages");       tableModel.insertRow(0, new Object[] { "CSS" }); ... Read More

Set Border Color for SoftBevelBorder in Java

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

307 Views

To set the border color for SoftBevelBorder in Java, use the Color class and set the color while creating the border −SoftBevelBorder border = new SoftBevelBorder(    BevelBorder.RAISED, Color.ORANGE, Color.ORANGE.darker(), Color.BLUE, Color.magenta.brighter());We have set the following colors above as parameters −highlightOuterColor: color to use for the bevel outer highlight highlightInnerColor : color to use for the bevel inner highlight shadowOuterColor : color to use for the bevel outer shadow shadowInnerColor : color to use for the bevel inner shadowThe following is an example to set border color for SoftBevelBorde in Java −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import ... Read More

Equality in MongoDB Without Using $eq Operator

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

128 Views

Let us first create a collection with documents -> db.operatorDemo.insertOne({"StudentSubject":["MongoDB", "MySQL", "Java"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cef94eaef71edecf6a1f6a2") } > db.operatorDemo.insertOne({"StudentSubject":["Java", "C", "C++"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cef94faef71edecf6a1f6a3") }Display all documents from a collection with the help of find() method -> db.operatorDemo.find().pretty();Output{    "_id" : ObjectId("5cef94eaef71edecf6a1f6a2"),    "StudentSubject" : [       "MongoDB",       "MySQL",       "Java"    ] } {    "_id" : ObjectId("5cef94faef71edecf6a1f6a3"),    "StudentSubject" : [       "Java",       "C",       "C++"    ] }Following is the query for ... Read More

HTML u Tag

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

86 Views

The element in HTML in HTML 4 was used to underlined a text on a web page, but HTML5 redefined to display text different from normal text.Let us now see an example to implement the tag−Example Live Demo Shortcut Keys Use the following shortcut keys: Cut: CTRL+X Copy: CTRL+C Paste: CTRL+V Undo: CTRL+Z OutputIn the above example, we have used the tag to display a text other than the default normal text−Use the following shortcut keys: Cut: CTRL+X

Order and Display Date Differences from Current Date in MySQL

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

259 Views

For this, use ORDER BY clause. The current date is as follows −mysql> select now(); +---------------------+ | now() | +---------------------+ | 2019-06-09 21:08:16 | +---------------------+ 1 row in set (0.00 sec)Let us first create a table −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> DueDate datetime    -> ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(DueDate) values('2019-06-12'); Query OK, 1 row affected (0.24 sec) ... Read More

Difference Between sizeof and alignof in C++

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

734 Views

Here we will see what are the differences of sizeof and the alignof operator in C++. The alognof() operator is introduced in C++11.The alignof() operator is used to get the alignment in bytes. It requires instances of type. the type is either complete type or a reference type. There is another operator called the sizeof() operator, that returns the size of one type. For normal datatypes the sizeof and the alignof returns the same value. For some user defined datatype, the alignof returns some different value. Let us see the example to get the idea.Example Live Demo#include using namespace std; struct ... Read More

Select Second Index in Java JList

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

415 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 main(String[] args) {       frame = new JFrame("JList Demo");       SwingDemo s = new SwingDemo();       JPanel panel = new JPanel();       String sports[]= { "Cricket","Football","Hockey","Rugby"};       list = new JList(sports);       list.setSelectedIndex(2);       panel.add(list);       frame.add(panel);       frame.setSize(400,400);       frame.setVisible(true);    } }Output

Advertisements