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....