Java - Problema

 
Vista:

Problema

Publicado por Mafmaestro (1 intervención) el 09/08/2010 15:10:13
Porque no me funciona?.
Hos pongo el codigo de las dos class:

La primera:

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.math.*;
import java.awt.event.ActionListener;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

public class felicidades extends JFrame implements ActionListener, ItemListener{
private JButton jbtn_boton;
private JLabel jlbl_label;
private JLabel jlbl2_label;
private JTextField text;

public felicidades () {
super("Felicidades");
setLayout(new FlowLayout());
this.definirVentana();
this.setSize(500, 500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new GridBagLayout());
GridBagConstraints gbc = GridBagConstraints();

combo = new JComboBox(archivos);
label = new JLabel();
label.setIcon(iconos[0]);


gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 2;
gbc.gridheight = 1;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.fill = gbc.BOTH;
this.getContentPane().add(label,gbc);

gbc.gridx = 0;
gbc.gridy = 1;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.fill = gbc.BOTH;
this.getContentPane().add(combo,gbc);

gbc.gridx = 0;
gbc.gridy = 2;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.fill = gbc.BOTH;
this.getContentPane().add(jbtn_boton,gbc);
combo.addItemListener(this);
combo.addActionListener(this);
this.setVisible(true);

}




private GridBagConstraints GridBagConstraints() {
return null;
}



public void definirVentana() {
this.setLayout(new GridBagLayout());
jbtn_boton = new JButton("Sorpresa");
jlbl_label = new JLabel();
jlbl2_label = new JLabel();
this.add(jbtn_boton);
this.add(jlbl_label);
this.add(jlbl2_label);
jbtn_boton.addActionListener(this); }
private JComboBox combo;
private JLabel label;
private String[] archivos = {"1.JPG","2.JPG","3.JPG","4.JPG","5.JPG","6.JPG","7.JPG","8.JPG"};
private Icon[] iconos = {new ImageIcon(getClass().getResource(archivos[0])),new ImageIcon(getClass().getResource(archivos[1])),new ImageIcon(getClass().getResource(archivos[2])),new ImageIcon(getClass().getResource(archivos[3])),new ImageIcon(getClass().getResource(archivos[4])),new ImageIcon(getClass().getResource(archivos[5])),new ImageIcon(getClass().getResource(archivos[6])),new ImageIcon(getClass().getResource(archivos[7]))};






public void actionPerformed(ActionEvent e) {
if(e.getSource()==jbtn_boton);
int text1 = ((int)(Math.random()*8));
label.setIcon(iconos[text1]);}




public void itemStateChanged1(ItemEvent e) {
label.setIcon(iconos[combo.getSelectedIndex()]);
}




public void itemStateChanged(ItemEvent e) {


}


}




Y la otra:

public class felicidadesventana {
public static void main(String[] args){
felicidades vc = new felicidades();

}
}


Gracias.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Problema

Publicado por mayrita (163 intervenciones) el 09/08/2010 18:17:12
debeiras de poner tambien que error te tira
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar