domingo, 24 de febrero de 2013

JcomboBox Modelo Programador Java Interfaz Gráfico GUI AWT Swing 1 Swing 2

Java
JcomboBox Modelo Programador Java Interfaz Gráfico GUI AWT Swing 1 Swing 2


 java.awt.*;
 java.awt.event.*;
 javax.swing.*;
 javax.swing.event.*;

public class JcomboBox1 extends JFrame {

  private JLabel jLabel1 = new JLabel();
  private JComboBox jComboBox1 = new JComboBox();
  private JButton Pares = new JButton();
    private ImageIcon ParesIcon = new ImageIcon("../../A.png");
  private JButton jButton2 = new JButton();
    private ImageIcon jButton2Icon = new ImageIcon("../../Apa.png");
    private ImageIcon jButton2SelectedIcon = new ImageIcon("../../Ap2.png");
  private JLabel jLabel2 = new JLabel();

 
  public JcomboBox1(String title) {
 
    super(title);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    int frameWidth = 337;
    int frameHeight = 338;
    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);
   
   
    jLabel1.setBounds(8, 0, 307, 89);
    jLabel1.setText("Cuadro de Listas jComboBox");
    jLabel1.setFont(new Font("Gunplay 3D", Font.BOLD, 22));
    jLabel1.setForeground(Color.MAGENTA);
    cp.add(jLabel1);
    cp.setBackground(new Color(0x4FB09D));
    jComboBox1.setBounds(32, 104, 153, 25);
    cp.add(jComboBox1);
    Pares.setBounds(208, 120, 121, 41);
    Pares.setText("Pares");
    Pares.setMargin(new Insets(2, 2, 2, 2));
    Pares.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        Pares_ActionPerformed(evt);
      }
    });
    Pares.setIcon(ParesIcon);
    cp.add(Pares);
    jButton2.setBounds(208, 184, 121, 41);
    jButton2.setText("Impares");
    jButton2.setMargin(new Insets(2, 2, 2, 2));
    jButton2.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        jButton2_ActionPerformed(evt);
      }
    });
    jButton2.setSelectedIcon(jButton2SelectedIcon);
    jButton2.setIcon(jButton2Icon);
    cp.add(jButton2);
    jLabel2.setBounds(24, 240, 195, 33);
    jLabel2.setText("");
    cp.add(jLabel2);
 
    jComboBox1.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        jComboBox1_ActionPerformed(evt);
      }
    });
    setVisible(true);
  } // end of public JcomboBox1
 
  public void jComboBox1_ActionPerformed(ActionEvent evt) {
   
    jLabel2.setText(jComboBox1.getSelectedItem().toString());
  }
  public void Pares_ActionPerformed(ActionEvent evt) {
    int i;
   
    DefaultComboBoxModel modelo = new DefaultComboBoxModel();
   
    for (i=0;i<10;i+=2) {
      modelo.addElement("Nº "+i);
    }
   
    jComboBox1.setModel(modelo);
   
   
  }
 
  public void jButton2_ActionPerformed(ActionEvent evt) {
    int i;
    DefaultComboBoxModel modelo = new DefaultComboBoxModel();
   
    for (i=1;i<10;i+=2) {
      modelo.addElement("Nº "+i);
    }
   
    jComboBox1.setModel(modelo);
   
   
  }
 

  public static void main(String[] args) {
    new JcomboBox1("JcomboBox1");
  }
}

No hay comentarios:

Publicar un comentario