Disable JCheckbox If Not Checked in Java

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

797 Views

The following is an example to disable JCheckBox if not checked in Java:Exampleimport java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JCheckBox; import javax.swing.JOptionPane; public class SwingDemo {    public static void main(String[] args) {       JCheckBox checkBox = new JCheckBox("Demo", true);       checkBox.addActionListener(new ActionListener() {          public void actionPerformed(ActionEvent e) {             if (checkBox.isEnabled())                checkBox.setEnabled(false);             else                checkBox.setEnabled(true);          }       });       JOptionPane.showMessageDialog(null, checkBox);    } }OutputNow, when you will uncheck the above checkbox, it will get disabled:

DatabaseMetaData supportsBatchUpdates Method with Example

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

349 Views

The supportsBatchUpdates() method of the DatabaseMetaData interface is used to determine whether the underlying database supports batch updates.This method returns a boolean value which is −True, when the underlying database supports stored porcedures.False, when the underlying database doesn't support stored porcedures.To determine whether the underlying database supports stored porcedures −Make sure your database is up and running.Register the driver using the registerDriver() method of the DriverManager class. Pass an object of the driver class corresponding to the underlying database.Get the connection object using the getConnection() method of the DriverManager class. Pass the URL the database and, user name, password of ... Read More

Reverse Array Field in MongoDB

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

302 Views

To reverse array field in MongoDB, you can use forEach(). Let us first create a collection with documents −> db.reverseArrayDemo.insertOne({"Skills":["C", "Java"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ccddf99dceb9a92e6aa1946") }Following is the query to display all documents from a collection with the help of find() method −> db.reverseArrayDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5ccddf99dceb9a92e6aa1946"),    "Skills" : [       "C",       "Java"    ] }Here is the query to reverse array field in MongoDB −> db.reverseArrayDemo.find().forEach(function (myDocument) { ...    var arrayValue = [ myDocument.Skills[1], myDocument.Skills[0] ]; ...    db.reverseArrayDemo.update(myDocument, { ... Read More

C++ Tricks for Competitive Programming

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

458 Views

Here we will see some good tricks of C++ programming language that can help us in different area. Like if we want to participate in some competitive programming events, then these tricks will help us to reduce the time for writing codes. Let us see some of these examples one by one.Checking whether a number is odd or even without using % operator. This trick is simple. We can perform bitwise AND operation with the number and 1. If the result is non-zero then this is odd, otherwise this is even. The logic is too simple. All odd numbers have ... Read More

Use JOptionPane with Array Elements in Java

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

1K+ Views

Let us first create and array and add elements −String[] sports = { "Football", "Cricket", "Squash", "Baseball", "Fencing", "Volleyball", "Basketball" };Now, set the above array elements to the JOptionPane −String res = (String) JOptionPane.showInputDialog(null, "Which sports you play the most?", "Sports",    JOptionPane.PLAIN_MESSAGE, null, sports, sports[0]);Above, we have also set the initial value i.e. sports(0).The following is an example to use JOptionPane with array elements in Java −Examplepackage my; import javax.swing.JOptionPane; public class SwingDemo {    public static void main(String[] args) {       String[] sports = { "Football", "Cricket", "Squash", "Baseball", "Fencing", "Volleyball", "Basketball" };       ... Read More

Insert Data into Inner Array in MongoDB

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

285 Views

You can use $addToSet operator for this. Let us first create a collection with documents −> db.insertDataIntoArrayDemo.insertOne(    {       "UserDetails":[          {             "UserId" :"user121",             "userGroupMessage":[]          },          {             "UserId" :"user221",             "userGroupMessage":["Cool", "Good Morning"]          }       ]    } ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd694e157806ebf1256f128") }Following is the query to display all documents from ... Read More

What is Classic Ethernet MAC Sublayer Protocol

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

6K+ Views

Classic Ethernet is the original form of Ethernet used primarily in LANs. It provides data rates between 3 to 10 Mbps.It operates both in the physical layer and in the MAC sublayer of the OSI model. In the physical layer, the features of the cables and networks are considered. In MAC sublayer, the frame formats for the Ethernet data frame are laid down.Classic Ethernet was first standardized in 1980s as IEEE 802.3 standard.Frame Format of Classic EthernetClassic Ethernet frames can be either of Ethernet (DIX) or of IEEE 802.3 standard. The frames of the two standards are very similar except ... Read More

HTML DOM Input Month DefaultValue Property

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

139 Views

The HTML DOM input month defaultValue property returns and modify the default value of input field of type=”month” in a HTML document.SyntaxFollowing is the syntax −1. Returning default valueobject.defaultValue2. Modifying default valueobject.defaultValue=valueHere, value is any date in form of string for example “2019-03”ExampleLet us see an example of HTML DOM input month defaultValue property − Live Demo    html{       height:100%;    }    body{       text-align:center;       color:#fff;       background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%)       center/cover no-repeat;       height:100%;    }    p{   ... Read More

Print Values of A in Equation A + B, N and A + B is Divisible by X

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

127 Views

Given with equation program must find the value of ‘a’ where a+b Declare start variables b=10, x=9, n=40 and flag=0, divisible Step 2 -> Loop For divisible = (b / x + 1 ) * x and divisible = 1       Print divisible-1       Set flag=1    End END STOPExample#include int main(int argc, char const *argv[]) {    int b=10, x=9, n=40, flag = 0;    int divisible;    for (divisible = (b / x + 1 ) * x ; divisible = 1) {          printf("%d ", divisible - b );          flag = 1;       }    }    return 0; }Outputif we run above program then it will generate following output8 17 26

Get or Set the Selection State of JCheckBox in Java

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

371 Views

The following is an example to get or set the selection state of JCheckBox:Exampleimport java.awt.FlowLayout; import javax.swing.JCheckBox; import javax.swing.JFrame; public class SwingDemo extends JFrame {    public SwingDemo() {       setSize(500, 500);       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       setLayout(new FlowLayout(FlowLayout.CENTER));       JCheckBox checkBox = new JCheckBox("Demo");       checkBox.setSelected(true);       boolean sel = checkBox.isSelected();       if (sel)          System.out.println("Check box selected!");       getContentPane().add(checkBox);    }    public static void main(String[] args) {       new SwingDemo().setVisible(true);    } }OutputSince the checkbox is selected by default, the following output would be visible in EclipseIDE:

Advertisements