How at save list in Jcombobox...
Hi.. everyone..i have used the following codes....the item is added to the current list but while compiling next time the item is not displayed in list of items... how to add item to combobox ...
Code:
import java.awt.*;
import java.sql.*;
import java.awt.event.*;
import javax.swing.*;
public class Item extends Frame implements ActionListener{
JComboBox dep,type,supp;
Button save,back,clr,exit;
String s4,s1;
TextField icode;
Label l1;
public Item()
{
super("ITEM");
setSize(450,500);
setLayout(null);
setBackground(new java.awt.Color(180, 180, 180));
l1=new Label("ITEMNAME");
icode=new TextField();
String su[]={"item1"," iem2","item3" };
supp=new JComboBox(su);
save= new Button("SAVE");
back= new Button("BACK");
clr= new Button("CLEAR");
exit= new Button("EXIT");
l1.setBounds(20,60,100,60);
icode.setBounds(150,70,120,30);
supp.setBounds(20,130,210,30);
save.setBounds(290,80,100,40);
back.setBounds(290,140,100,40);
clr.setBounds(290,200,100,40);
exit.setBounds(290,260,100,40);
save.addActionListener(this);
back.addActionListener(this);
clr.addActionListener(this);
exit.addActionListener(this);
add(l1);
add(icode);
add(supp);
add(save);
add(back);
add(clr);
add(exit);
setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==save)
{
s1=icode.getText();
supp.insertItemAt(s1, 0);
JOptionPane.showMessageDialog(this,new String("ITEM Saved"));
}
if(ae.getSource()==back)
{
this.hide();
Main st=new Main();
}
if(ae.getSource()==clr)
{
}
if(ae.getSource()==exit)
{
System.exit(0);
}
}
public static void main(String args[])
{
Item gi=new Item();
}
}