I need to know how to add a JTextField
if one of the JComboBox
options is selected, and if the other one is selected I don't want to have that text field there any more.
Here is my code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class GUI extends JFrame{
//Not sure if this code is correct
private JTextField text;
private JComboBox box;
private static String[] selector = {"Option 1", "Option 2"};
public GUI(){
super("Title");
setLayout(new FlowLayout());
box = new JComboBox(selector);
add(box);
box.addItemListener(
new ItemListener(){
public void itemStateChanged(ItemEvent e){
if(){
//what should be in the if statement and what should i type down here to add the
//JTextField to the JFrame?
}
}
}
);
}
}