Java Swing Example - Fibonacci Generation - JList - JOptionPane - NetBeans - Internet & Web Programming Lab

Java Swing Example 
Fibonacci Generation 
JList - JOptionPane 
NetBeans - Internet & Web Programming Lab

Source code:
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;

/*
 * Fib2.java
 *
 * Created on Jan 21, 2012, 11:00:27 AM
 */
/**
 *
 * @author nn
 */
public class Fib2 extends javax.swing.JFrame {
    
    DefaultListModel dl;
    /** Creates new form Fib2 */
    public Fib2() {
        super("Fibonacci Series Generation");
        initComponents();
        dl = new DefaultListModel();
        jList1.setModel(dl);
       
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton1.setText("Generate");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel1.setText("Number of Terms");

        jLabel2.setText("Fibonacci Numbers");

        jList1.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(jList1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(44, 44, 44)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))))
                .addGap(92, 92, 92)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(45, 45, 45))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(16, 16, 16)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE)
                        .addGap(27, 27, 27))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(3, 3, 3)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(30, 30, 30)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(69, 69, 69))))
        );

        pack();
    }// </editor-fold>

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        
        if(jTextField1.getText()!= null)
        {       
            dl.removeAllElements();
            int n=Integer.parseInt(jTextField1.getText());
            int ch = JOptionPane.showConfirmDialog(rootPane, "Generate "+n+ " fibonacci numbers ?");
            //System.out.print(ch);
        //String n1 = JOptionPane.showInputDialog("Enter n:");
            if(ch==0)
                 genfib(n);
        }
    }
void genfib(int n)
{
    int t1=0,t2=1,t3;
    if(n>=1)
    {
        dl.addElement(t1);
        
    }
    if(n>=2)
    {
        dl.addElement(t2);
        
    }   
     if(n>2)
    {
        for(int i=2;i<n;i++)
        {
            t3=t1+t2;
            dl.addElement(t3);
            t1=t2;
            t2=t3;
            //System.out.print(t3);
        }
    }
        
}
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Fib2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Fib2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Fib2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Fib2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                Fib2 f1 = new Fib2();
                f1.setVisible(true);
                f1.setSize(600,500);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JList jList1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration
}


Output:



NeST Recruitment 2012 - General ability test and Technical ability test




NeST Software Campus Recruitment 2011-2012




  NeST Software (Network Systems & Technologies ) , a division of SFO Technologies and part of the NeST Group of companies, is a technology company which offers customized software and hardware development services for engineering applications and product development services for customers worldwide.

The selection process includes:
   1. Offline General ability test and technical ability test.(1 hr. 30 mints)
   2. Personal interview (for those who gets short listed in the written test)
NeST aptitude test  consist of 4 sections with 85 questions and total time of 90 minutes.

Section 1: Verbal Ability
This section is to test your language skills & verbal abilities. The section consist of 20 questions which should be answered in 20 minutes. The section contains the following types of questions.
  • Read passage & answer question.
  • Fill in the blanks ( Grammar  ).
  • etc.
 Section 2: Logical Ability
This section is to test your logical skills. The section consist of 20 questions which should be answered in 20 minutes. The section contains the following types of questions.
  •       Select best conclusion from given statements.
         Eg: St1:All men are hard working.
               St2: Suresh is a man.
a.Suresh is hard working.
b.Suresh is not hard working.
c.Suresh is not a man.
d.Men are not hard working.

  • Complete the sequence of numbers.
  • Choose the best matching figure for the series of pictures.
  • Find odd picture from a set of pictures.
  • Find similar picture for the given picture from the option pictures.
  • Find code for given code.
          Eg:  If ABCD --> BCDE  then  PQRS -->  ?
         a)QRSU
         b)QRSV
         c)QRSW
         d)QRST

  • Read a tabular information & answer questions.



A
B
C
1



2



3




Questions regarding filling of the cells A1,A2…C3 with the numbers 1-9 satisfying given conditions.

Eg: What will be the position of 7 in the table?
     a.A1   b.B1   c.C1   d.C3

Section 3: Programming Ability
This section is to test your programming skills. The section consist of 15 questions which should be answered in 30 minutes. The section contains the following types of questions.
  • An algorithm will be given (such as prime number generation). Finding output.
  • Choosing correct algorithm for given problem.
              Eg: Abundant numbers
  • A flow chart will be given. Choosing correct output for the given input.
  • Other questions:
1.       Which operator in c++ can not be overloaded?
a.+     b.-     c.++     d.?:
2.       Preprocessors are expanded at the stage of
a.Compilation   b.Pre compilation    c.Loading    d.Linking


Section 4: IT Concept
This section is to test your knowledge in IT. The section consist of 30 questions which should be answered in 30 minutes. The section contains theory questions (operating systems, microprocessors, computer organization, etc…)


Related Posts Plugin for WordPress, Blogger...