You are on page 1of 11

import javax.swing.

JOptionPane;

public class methodsofcombobox extends javax.swing.JFrame {

/** Creates new form methodsofcombobox */


public methodsofcombobox() {

initComponents();

private void BTADDActionPerformed(java.awt.event.ActionEvent evt)

String s1=txtadd.getText();

combobox1.addItem(s1);

txtadd.setText(" ");

private void combobox1ItemStateChanged(java.awt.event.ItemEvent


evt) {

String s=(String)combobox1.getSelectedItem();

txtselectitem.setText(s);

int i=combobox1.getSelectedIndex();

txtselectindex.setText(" "+i);

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)


{

String s1=txtdisplay.getText();
int id=Integer.parseInt(txtindex.getText());

combobox1.insertItemAt(s1, id);

private void BTSELECTActionPerformed(java.awt.event.ActionEvent


evt) {

if(selectcb1.isSelected()==true) {

String s=txtselectitem.getText();

combobox1.setSelectedItem(s);

if(selectcb2.isSelected()==true) {

int i=Integer.parseInt(txtselectindex.getText());

combobox1.setSelectedIndex(i);

private void
listremoveValueChanged(javax.swing.event.ListSelectionEvent evt)
{ int index=listremove.getSelectedIndex();

switch(index) {

case 0:JOptionPane.showMessageDialog(null,"All items from


combox will be removed");

combobox1.removeAllItems();

break;

case 1:

int i=combobox1.getSelectedIndex();
JOptionPane.showMessageDialog(null,"Element at Index "+i+ "will be
removed");

combobox1.removeItemAt(i);

break;

case 2:

String s=(String)combobox1.getSelectedItem();

JOptionPane.showMessageDialog(null,"From the combox "+ s+ " will


be removed");

combobox1.removeItem(s);

}
break;

private void btcountActionPerformed(java.awt.event.ActionEvent evt)


{

int count=combobox1.getItemCount();

txtcount.setText(" "+count);

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt)


{

txtadd.setText(" "); txtcount.setText(" ");

txtdisplay.setText(" "); txtindex.setText(" ");

txtselectindex.setText(" "); txtselectitem.setText(" ");

selectcb1.setSelected(false); selectcb2.setSelected(false);

listremove.clearSelection(); combobox1.removeAllItems();

private void btexitActionPerformed(java.awt.event.ActionEvent evt) {

System.exit(0);

public static void main(String args[]) {


java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new methodsofcombobox().setVisible(true);

});

// Variables declaration - do not modify

private javax.swing.JButton BTADD;

private javax.swing.JButton BTSELECT;

private javax.swing.JButton btcount;

private javax.swing.JButton btexit;

private javax.swing.JComboBox combobox1;

private javax.swing.JButton jButton1;

private javax.swing.JButton jButton3;

private javax.swing.JLabel jLabel2;

private javax.swing.JLabel jLabel4;

private javax.swing.JScrollPane jScrollPane1;

private javax.swing.JList listremove;

private javax.swing.JCheckBox selectcb1;


private javax.swing.JCheckBox selectcb2;

private javax.swing.JTextField txtadd;

private javax.swing.JTextField txtcount;

private javax.swing.JTextField txtdisplay;

private javax.swing.JTextField txtindex;

private javax.swing.JTextField txtselectindex;

private javax.swing.JTextField txtselectitem;

// End of variables declaration

}
private void btpalindromActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

String strrev="",s1=txtstr1.getText();

int len=s1.length();

for(int i=len-1;i>=0;i--)

{ strrev=strrev+s1.charAt(i); }

txtres.setText("Reverse of the String is="+strrev);

if(s1.equals(strrev))

{ JOptionPane.showMessageDialog(null,s1+ " is a palindrom"); }

else if(s1.equalsIgnoreCase(strrev.toString()))

{ JOptionPane.showMessageDialog(null,s1+ " is a palindrom if ignore case"); }

else

{ JOptionPane.showMessageDialog(null,s1+ " is not a palindrom"); }

}
private void btjumbledActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

String newstr="",s1=txtstr1.getText();

char ch;

int len=s1.length();

for(int i=0;i<len;i++)

{ ch=s1.charAt(i);

if(Character.isLowerCase(ch))

ch=Character.toUpperCase(ch);

else ch=Character.toLowerCase(ch);

newstr=newstr+ch;

if(i<len-1)

{ newstr=newstr+s1.charAt(i+1);

i++;

txtres.setText(newstr);

private void btcountActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

String s1=txtstr1.getText();

char ch;

int count=0,len=s1.length();
for(int i=0;i<len;i++)

{ ch=s1.charAt(i);

switch(ch)

{ case 'a': case 'A': case 'e': case 'E':

case 'i': case 'I': case 'o': case 'O':

case 'u': case 'U': count++; break;

txtres.setText(" No of vowels in " +s1+ " is= "+count);

private void btconcatActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

String s1=txtstr1.getText();

String s2=txtstr2.getText();

String s3=s1.concat(s2);

String s4=s2.concat(s1);

txtres.setText("Concated Strings are "+s3+ " and "+s4);

System.out.println("Math.pow(2,5)%7="+Math.pow(2,5)%7);

System.out.println("Math.round(94.49)="+Math.round(94.49));

System.out.println("Good".equals("GOOD"));

private void btcompareActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:


String s1=txtstr1.getText();

String s2=txtstr2.getText();

if(s1.compareTo(s2)==0)

txtres.setText("Both Strings are same") ;

else

txtres.setText("Both Strings are different");

private void btreplaceActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

String s1=txtstr1.getText();

String s3=" ";

String s2=txtstr2.getText();

s1=s1.replace(s1.charAt(0),Character.toUpperCase(s1.charAt(0)));
s2=s2.replace(s2.charAt(0),Character.toUpperCase(s2.charAt(0)));

s2=s2.substring(0,1).concat(".");

s1=s1+s3+s2;

txtres.setText(s1);

You might also like