import java.awt.*; import java.awt.event.*; import java.applet.*; public class Seleccionables extends Applet { private boolean isStandalone = false; Choice choice1 = new Choice(); Button button1 = new Button(); Choice choice2 = new Choice(); TextField tfResult = new TextField(); //Obtener el valor de un parámetro public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } //Construir el applet public Seleccionables() { } //Inicializar el applet public void init() { choice1.addItem("SELECCIONA"); choice1.addItem("Masa"); choice1.addItem("Volumen"); choice1.addItem("Temperatura"); choice1.addItem("Tiempo"); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Inicialización de componentes private void jbInit() throws Exception { this.setLayout(null); choice1.setFont(new java.awt.Font("Dialog", 0, 16)); choice1.setBounds(new Rectangle(26, 17, 159, 25)); choice1.addItemListener(new Seleccionables_choice1_itemAdapter(this)); button1.setBackground(Color.red); button1.setFont(new java.awt.Font("Dialog", 1, 16)); button1.setLabel("Seleccionar"); button1.setBounds(new Rectangle(126, 143, 131, 28)); button1.addActionListener(new Seleccionables_button1_actionAdapter(this)); this.setBackground(Color.black); choice2.setFont(new java.awt.Font("Dialog", 0, 16)); choice2.setBounds(new Rectangle(211, 18, 157, 25)); tfResult.setFont(new java.awt.Font("Dialog", 0, 16)); tfResult.setText(""); tfResult.setBounds(new Rectangle(51, 218, 306, 25)); this.add(choice1, null); this.add(choice2, null); this.add(button1, null); this.add(tfResult, null); } //Iniciar el applet public void start() { } //Detener el applet public void stop() { } //Destruir el applet public void destroy() { } //Obtener información del applet public String getAppletInfo() { return "Información del applet"; } //Obtener información del parámetro public String[][] getParameterInfo() { return null; } void choice1_itemStateChanged(ItemEvent e) { if ("Masa".equals(choice1.getSelectedItem())) { choice2.removeAll(); choice2.addItem("kilogramos (kg)"); choice2.addItem("gramos (g)"); choice2.addItem("miligramos (mg)"); } else if ("Volumen".equals(choice1.getSelectedItem())) { choice2.removeAll(); choice2.addItem("Litros (L)"); choice2.addItem("cm cúbicos cm3"); choice2.addItem("mm cúbicos (mm3)"); } else if ("Temperatura".equals(choice1.getSelectedItem())) { choice2.removeAll(); choice2.addItem("grado Celsius (ºC)"); choice2.addItem("kelvin (K)"); } else if ("Tiempo".equals(choice1.getSelectedItem())) { choice2.removeAll(); choice2.addItem("horas (h)"); choice2.addItem("minutos (min)"); choice2.addItem("segundos (s)"); } else if ("SELECCIONA".equals(choice1.getSelectedItem())) { choice2.removeAll(); } } void button1_actionPerformed(ActionEvent e) { String txt = choice2.getSelectedItem(); tfResult.setText("Has seleccionado: " + txt); } } class Seleccionables_choice1_itemAdapter implements java.awt.event.ItemListener { Seleccionables adaptee; Seleccionables_choice1_itemAdapter(Seleccionables adaptee) { this.adaptee = adaptee; } public void itemStateChanged(ItemEvent e) { adaptee.choice1_itemStateChanged(e); } } class Seleccionables_button1_actionAdapter implements java.awt.event.ActionListener { Seleccionables adaptee; Seleccionables_button1_actionAdapter(Seleccionables adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.button1_actionPerformed(e); } }