I want to take from a list the user's choice and convert it to a string with Jbox. How can I convert the contents to string so I can use it?
public class Graph extends JFrame
{
private String temp;
public Graph()
{ }
public void CreateBox(String[] a)
{
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton jButton1 = new JButton("ok");
final JList jList1 = new JList(a);
jButton1.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Object contents = jList1.getSelectedValue();
//System.out.println(contents);
setChoise((String)contents);//how can i convert it to string ?
}
});
JButton jButton2 = new JButton("close");
jButton2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
frame.add(jList1, "Center");
frame.add(jButton1,"South");
frame.add(jButton2,"North");
frame.setSize(300, 200);
frame.setVisible(true);
}
public void setChoise(String temp)
{
this.temp=temp;
}
public String getChoise()
{
return this.temp;
}
}