bom galera é o seguinte quando eu seleciono uma opção na minha combobox ele dispara uma ShowmessageDialog indicando qual opção eu escolhi porem eu quero que ele so dispare está menssage quando eu clicar no botão sortear comentei os eventos do Combobox copiei e colei no evento do botão so que tadando pau oq eu to fazendo de errado e pq??
ta dando erro na linha
public class SorteGrande extends JFrame implementes ActionListener
pq ta dando erro
valew
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)
{
JComboBox cb=(JComboBox)e.getSource();
String escolha=(String)cb.getSelectedItem();
System.out.println(escolha);
}
}
public static void main(String args[])
{
SorteGrande ref = new SorteGrande();
}
}