JComboBox GUI AWT Swing 1 Swing 2 |
|
import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class Jcombobox extends JFrame { private JComboBox jComboBox1 = new JComboBox(); private JLabel jLabel1 = new JLabel(); private JLabel jLabel2 = new JLabel(); public Jcombobox(String title) { super(title); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); int frameWidth = 300; int frameHeight = 300; setSize(frameWidth, frameHeight); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); int x = (d.width - getSize().width) / 2; int y = (d.height - getSize().height) / 2; setLocation(x, y); setResizable(false); Container cp = getContentPane(); cp.setLayout(null); cp.setBackground(new Color(0x38C772)); jComboBox1.setBounds(40, 88, 177, 41); jComboBox1.setModel(new DefaultComboBoxModel(new String[] {"Rojo ", "Amarillo", "Verde"})); jComboBox1.setEditable(false); jComboBox1.setEnabled(true); jComboBox1.setSelectedIndex(1); cp.add(jComboBox1); jLabel1.setBounds(48, 8, 171, 57); jLabel1.setText("JComboBox"); jComboBox1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jComboBox1_actionPerformed(evt); } }); jLabel1.setOpaque(false); jLabel1.setForeground(Color.RED); jLabel1.setFont(new Font("3D", Font.BOLD, 28)); cp.add(jLabel1); jLabel2.setBounds(32, 168, 235, 41); jLabel2.setText("Color:"); cp.add(jLabel2); setUndecorated(false); setVisible(true); } public void jComboBox1_actionPerformed(ActionEvent evt){ String mensaje="Color Seleccionado es "; mensaje=mensaje+jComboBox1.getSelectedItem().toString(); jLabel2.setText(mensaje); } public static void main(String[] args) { new Jcombobox("Jcombobox"); } } |
domingo, 17 de febrero de 2013
JComboBox Programador Java Interfaz Gráfico GUI AWT Swing 1 Swing 2
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario