
Originariamente inviata da
Ansharja
codice:
import java.awt.FlowLayout;
import java.awt.event.*;
import javax.swing.*;
public class Main
{
public static void main (String [] a) {
SwingUtilities.invokeLater (new Runnable () {
@Override public void run () {
createAndShowGUI ();
}
});
}
private static void createAndShowGUI () {
StationDialog dialog = new StationDialog (new ViewStationsFrame ());
dialog.pack ();
dialog.setDefaultCloseOperation (JDialog.DISPOSE_ON_CLOSE);
dialog.setLocationRelativeTo (null);
dialog.setVisible (true);
}
}
class StationDialog extends JDialog
{
private JComboBox comboBox;
private JTextField textField;
public StationDialog (ViewStationsFrame vsf) {
// this.viewfs = vsf;
// this.control = vsf.getControl ();
// this.model = vsf.getModel ();
this.createCombo ();
this.verifyComboBox ();
getContentPane ().setLayout (new FlowLayout (FlowLayout.LEFT, 50, 200));
add (comboBox);
add (textField = new JTextField (20));
}
private void createCombo () {
String [] typeStrings = {" ", "I", "D", "A"};
comboBox = new JComboBox (typeStrings);
}
private void verifyComboBox () {
ItemListener itemListener = new ItemListener () {
@Override public void itemStateChanged (ItemEvent event) {
if (event.getStateChange () == ItemEvent.SELECTED) {
Object item = event.getItem ();
if (item.equals ("I")) textField.setEnabled (true);
else textField.setEnabled (false);
}
}
};
comboBox.addItemListener (itemListener);
}
}
class ViewStationsFrame extends JFrame
{
public ViewStationsFrame () {
super ();
}
// ?
}