JList Modelo Programador Java Interfaz Gráfico GUI AWT Swing 1 Swing 2
|
|
java.awt.*; java.awt.event.*; javax.swing.*; javax.swing.event.*; public class jlist1 extends JFrame { private JButton jButton1 = new JButton(); private ImageIcon jButton1Icon = new ImageIcon("../../Apons/im.png"); private JButton jButton2 = new JButton(); private ImageIcon jButton2Icon = new ImageIcon("../../Aons/di.png"); private JLabel jLabel1 = new JLabel(); private JLabel jLabel2 = new JLabel(); private JList jList1 = new JList(); private DefaultListModel jList1Model = new DefaultListModel(); private JScrollPane jList1ScrollPane = new JScrollPane(jList1); public jlist1(String title) { super(title); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); int frameWidth = 371; int frameHeight = 367; 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); jButton1.setBounds(200, 120, 113, 41); jButton1.setText("Grupo 1"); jButton1.setMargin(new Insets(2, 2, 2, 2)); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jButton1_ActionPerformed(evt); } }); jButton1.setIcon(jButton1Icon); cp.add(jButton1); jButton2.setBounds(200, 184, 113, 41); jButton2.setText("Grupo 2"); jButton2.setMargin(new Insets(2, 2, 2, 2)); jButton2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jButton2_ActionPerformed(evt); } }); jButton2.setIcon(jButton2Icon); cp.add(jButton2); jLabel1.setBounds(40, 16, 291, 53); jLabel1.setText("JList modelo"); jLabel1.setForeground(Color.MAGENTA); jLabel1.setFont(new Font("Gunplay 3D", Font.BOLD, 48)); cp.add(jLabel1); jLabel2.setBounds(64, 256, 195, 41); jLabel2.setText("text"); cp.add(jLabel2); jList1.setModel(jList1Model); jList1ScrollPane.setBounds(24, 80, 137, 161); jList1Model.addElement("Real Madrid"); jList1Model.addElement("Barcelona"); jList1Model.addElement("Boca"); cp.add(jList1ScrollPane); jList1.addMouseListener(new MouseAdapter() { public void mouseClicked (MouseEvent evt) { jList1_mouseClicked(evt); } }); cp.setBackground(new Color(0x34CB5A)); setVisible(true); } public void jList1_mouseClicked(MouseEvent evt) { jLabel2.setText(jList1.getSelectedValue().toString()); } public void jButton1_ActionPerformed(ActionEvent evt) { DefaultListModel modelo = new DefaultListModel(); modelo.addElement("Chelse"); modelo.addElement("Juventus"); modelo.addElement("Milan"); jList1.setModel(modelo); } public void jButton2_ActionPerformed(ActionEvent evt) { DefaultListModel modelo = new DefaultListModel(); modelo.addElement("Real Madrid"); modelo.addElement("Barcelona"); modelo.addElement("Boca"); jList1.setModel(modelo); } public static void main(String[] args) { new jlist1("jlist1"); } } |
domingo, 24 de febrero de 2013
JList Modelo Programador Java Interfaz Gráfico GUI AWT Swing 1 Swing 2
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario