oq eu quero é simplesmente exibir a opçao selecionado no JcomboBox quando eu clicar no botão sortear
ta dando pau na linha
public class SorteGrande extedns JFrame implementes ActionListener
e eu num to conseguindo arrumar se alguem tiver uma dica eu agradeço
fui
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class SorteGrande extends JFrame implements ActionListener
{
private JButton sorteio,sair;
private JLabel label;
private JPanel painelnorte,painelcenter,painelsul;
private JComboBox combo;
public SorteGrande()
{
super ("Sorte Grande v.01") ;
setLayout(new BorderLayout());
//tratamento JComboBox
String[] vetor={"Dupla Sena","Loto Fácil","Loto Mania","Mega Sena","Quina"};
JComboBox escolha= new JComboBox(vetor);
escolha.addActionListener(this);
//Tratamento botão sair e sortear com evento
sair = new JButton("Sair");
sair exit =new sair();
sair.addActionListener(exit);
//
sorteio = new JButton("Sortear");
sortear sort =new sortear();
sorteio.addActionListener(sort);
//tramento Painel
painelcenter =new JPanel();
painelnorte =new JPanel();
painelsul =new JPanel();
//Tratamento do label
label =new JLabel("Escolha a opção para gerar o palpite");
//Adicionando paineis
add(painelnorte, BorderLayout.NORTH);
add(painelcenter, BorderLayout.CENTER);
add(painelsul, BorderLayout.SOUTH);
//painel nort
painelnorte. add(label);
painelcenter. add(escolha);
//painel sul
painelsul. add(sorteio);
painelsul. add(sair);
pack();
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
/*
//inicio tratamento evento jcombobox
public void actionPerformed(ActionEvent e){
JComboBox cb=(JComboBox)e.getSource();
String escolha=(String)cb.getSelectedItem();
JOptionPane.showMessageDialog(null,"a opção escolhida foi "+escolha);
}
*/
public class sair implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String opcoes[] = {"Sim","Não"};
int opc = JOptionPane.showOptionDialog(null,"Confirma o encerramento?","Confirmação",JOptionPane.DEFAULT_OPTION,JOptionPane.QUESTION_MESSAGE,null,opcoes,opcoes[1]);
//
if ( opc == 0 )
System.exit(0);
}
}
public class sortear implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==sorteio)
{
JComboBox cb=(JComboBox)e.getSource();
String escolha=(String)cb.getSelectedItem();
JOptionPane.showMessageDialog(null,"a opção escolhida foi "+escolha);
}
}
}
public static void main(String args[])
{
SorteGrande ref = new SorteGrande();
}
}
