Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: My Programme Not working .. as i used VECTOR and SWING.

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post My Programme Not working .. as i used VECTOR and SWING.

    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.util.Vector;
    import java.util.Enumeration;
    import java.util.NoSuchElementException;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JTextField;

    public class vector1 extends JFrame {
    /**
    *
    */
    private static final long serialVersionUID = 1L;
    private JLabel jlbString = new JLabel("Enter a String");
    public vector1(){
    super("Vector Class Program");
    //Made final as it can be accessed by the inner classes
    final JLabel jlbStatus = new JLabel();
    Container contentPane = getContentPane();

    final Vector<String> vector = new Vector<String>(1);
    contentPane.setLayout(new FlowLayout());
    contentPane.add(jlbString);

    final JTextField jtfInput = new JTextField();
    contentPane.add(jtfInput);
    JButton jbnAdd = new JButton("Add");

    jbnAdd.addActionListener( new ActionListener(){
    public void actionPerformed(ActionEvent e){
    vector.addElement(jtfInput.getText().trim()) ;
    jlbStatus.setText("Append to end: " + jtfInput.getText().trim());
    jtfInput.setText(" ");
    }
    });
    contentPane.add(jbnAdd);

    JButton jbnRemove = new JButton("Remove");
    jbnRemove.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
    //Returns true if element is in vector
    if(vector.removeElement(jtfInput.getText().trim()) )
    jlbStatus.setText("removed: " + jtfInput.getText().trim() + " not in vector");
    }
    });
    contentPane.add(jbnRemove);

    JButton jbnFirst = new JButton();
    jbnFirst.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e){
    try{
    jlbStatus.setText("First elemnt: " + vector.firstElement());
    }catch(NoSuchElementException exception){
    jlbStatus.setText(exception.toString());
    }
    }
    });
    contentPane.add(jbnFirst);

    JButton jbnLast = new JButton("Last");
    jbnLast.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
    try{
    jlbStatus.setText("Last Element" + vector.lastElement());
    }catch(NoSuchElementException exception){
    jlbStatus.setText(exception.toString());
    }

    }
    });
    contentPane.add(jbnLast);

    JButton jbnEmpty = new JButton("Empty Check");
    jbnEmpty.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
    jlbStatus.setText(vector.isEmpty() ? "Vector is Empty" : "Vector is not Empty");
    }
    });
    contentPane.add(jbnEmpty);

    JButton jbnContains = new JButton();
    jbnContains.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
    String searchKey = jtfInput.getText().trim();
    if(vector.contains(searchKey)){
    jlbStatus.setText("Vector contains" + searchKey);
    }else{
    jlbStatus.setText("vector Does not contain " + searchKey);
    }
    }
    });
    contentPane.add(jbnContains);

    JButton jbnFindElement = new JButton("Find");
    jbnFindElement.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
    jlbStatus.setText("Element found at location " + vector.indexOf(jtfInput.getText().trim()));

    }
    });
    contentPane.add(jbnFindElement);

    JButton jbnTrim = new JButton("Trim");
    jbnTrim.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
    vector.trimToSize();
    jlbStatus.setText("vector trimmmed to size");
    }
    });
    contentPane.add(jbnTrim);

    JButton jbnSize = new JButton("Size/Capacity");
    jbnSize.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
    jlbStatus.setText("Size = " + vector.size() + " ; Capacity = " + vector.capacity());
    }
    });
    contentPane.add(jbnSize);

    JButton jbnDisplay = new JButton("Dispaly");
    jbnDisplay.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e){
    Enumeration<String> enum1 = vector.elements();
    StringBuffer buff = new StringBuffer();

    while(enum1.hasMoreElements())
    buff.append(enum1.nextElement()).append(" ");
    JOptionPane.showMessageDialog(null, buff.toString(), "Contents of vector" , JOptionPane.PLAIN_MESSAGE);
    }
    });
    contentPane.add(jbnDisplay);
    contentPane.add(jlbStatus);
    }

    public static void main(String [] args){
    vector1 vector1 = new vector1();
    vector1.addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent e){
    System.exit(0);
    }
    });

    }




    }


    It gives error....

    vector1.java uses unsafe and unchecked operations.
    recompile with -Xlint:unchecked for details.

    wat does that mean... why my prgrammes is not running as it dosen;t have any errors or warnings.

    I tried to run it through eclipse. still the program gets terminated before running.

    please help me guyz....
    Last edited by sanctity4u; June 24th, 2012 at 04:51 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: My Programme Not working .. as i used VECTOR and SWING.

    Did you try compiling the program with the javac option: -Xlint to find the statements that the compiler is concerned about?
    The warning message is because you are not using the generics syntax to define a class like Vector.

    If you only get warnings when you compile the program, there should be a class file created that you can execute. Check that a .class file was created.
    How are you executing the program?

    Please Edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My Programme Not working .. as i used VECTOR and SWING.

    [Code = java]
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.util.Vector;
    import java.util.Enumeration;
    import java.util.NoSuchElementException;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JTextField;

    public class vector1 extends JFrame {
    /**
    *
    */
    private static final long serialVersionUID = 1L;
    private JLabel jlbString = new JLabel("Enter a String");
    public vector1(){
    super("Vector Class Program");
    //Made final as it can be accessed by the inner classes
    final JLabel jlbStatus = new JLabel();
    Container contentPane = getContentPane();

    final Vector<String> vector = new Vector<String>(1);
    contentPane.setLayout(new FlowLayout());
    contentPane.add(jlbString);

    final JTextField jtfInput = new JTextField();
    contentPane.add(jtfInput);
    JButton jbnAdd = new JButton("Add");

    jbnAdd.addActionListener( new ActionListener(){
    public void actionPerformed(ActionEvent e){
    vector.addElement(jtfInput.getText().trim()) ;
    jlbStatus.setText("Append to end: " + jtfInput.getText().trim());
    jtfInput.setText(" ");
    }
    });
    contentPane.add(jbnAdd);

    JButton jbnRemove = new JButton("Remove");
    jbnRemove.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
    //Returns true if element is in vector
    if(vector.removeElement(jtfInput.getText().trim()) )
    jlbStatus.setText("removed: " + jtfInput.getText().trim() + " not in vector");
    }
    });
    contentPane.add(jbnRemove);

    JButton jbnFirst = new JButton();
    jbnFirst.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e){
    try{
    jlbStatus.setText("First elemnt: " + vector.firstElement());
    }catch(NoSuchElementException exception){
    jlbStatus.setText(exception.toString());
    }
    }
    });
    contentPane.add(jbnFirst);

    JButton jbnLast = new JButton("Last");
    jbnLast.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
    try{
    jlbStatus.setText("Last Element" + vector.lastElement());
    }catch(NoSuchElementException exception){
    jlbStatus.setText(exception.toString());
    }

    }
    });
    contentPane.add(jbnLast);

    JButton jbnEmpty = new JButton("Empty Check");
    jbnEmpty.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
    jlbStatus.setText(vector.isEmpty() ? "Vector is Empty" : "Vector is not Empty");
    }
    });
    contentPane.add(jbnEmpty);

    JButton jbnContains = new JButton();
    jbnContains.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
    String searchKey = jtfInput.getText().trim();
    if(vector.contains(searchKey)){
    jlbStatus.setText("Vector contains" + searchKey);
    }else{
    jlbStatus.setText("vector Does not contain " + searchKey);
    }
    }
    });
    contentPane.add(jbnContains);

    JButton jbnFindElement = new JButton("Find");
    jbnFindElement.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
    jlbStatus.setText("Element found at location " + vector.indexOf(jtfInput.getText().trim()));

    }
    });
    contentPane.add(jbnFindElement);

    JButton jbnTrim = new JButton("Trim");
    jbnTrim.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
    vector.trimToSize();
    jlbStatus.setText("vector trimmmed to size");
    }
    });
    contentPane.add(jbnTrim);

    JButton jbnSize = new JButton("Size/Capacity");
    jbnSize.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
    jlbStatus.setText("Size = " + vector.size() + " ; Capacity = " + vector.capacity());
    }
    });
    contentPane.add(jbnSize);

    JButton jbnDisplay = new JButton("Dispaly");
    jbnDisplay.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e){
    Enumeration<String> enum1 = vector.elements();
    StringBuffer buff = new StringBuffer();

    while(enum1.hasMoreElements())
    buff.append(enum1.nextElement()).append(" ");
    JOptionPane.showMessageDialog(null, buff.toString(), "Contents of vector" , JOptionPane.PLAIN_MESSAGE);
    }
    });
    contentPane.add(jbnDisplay);
    contentPane.add(jlbStatus);
    }

    public static void main(String [] args){
    vector1 vector1 = new vector1();
    vector1.addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent e){
    System.exit(0);
    }
    });

    }




    }
    [/code]


    i tried to compile with javac ....
    i don't know how to compile using CXint option.

    yeah the class file is created ..but more than 1 class file is created. one is vector1.class and rest are vector1$1 .......to .....vector1$11.. i don;t know y..

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: My Programme Not working .. as i used VECTOR and SWING.

    The classnames with the $ in them are for inner classes.
    What warnings did the compiler output when you used the -Xlint option?

    Please Edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. help with bookfinder programme
    By kidza12 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 9th, 2011, 02:15 PM
  2. Help with my Range Finder programme
    By kidza12 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 3rd, 2011, 01:53 PM
  3. Replies: 2
    Last Post: December 22nd, 2010, 09:21 AM
  4. Swing Dialog Boxes --- Have no clue why its not working
    By jap2008 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 18th, 2010, 04:20 PM
  5. Simple Programme for Date
    By bhavinsparikh in forum Java Theory & Questions
    Replies: 1
    Last Post: August 28th, 2010, 07:24 AM

Tags for this Thread