Queria uma ajuda nesse programinha, é uma calculadora com botão de rádio que eu não tô conseguindo rodar, a parte do erro esta em comentário, se alguém puder me ajudar, vlws
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Radio2 extends JFrame implements ItemListener {
JLabel L1,L2,L3;
JRadioButton B1, B2, B3, B4, B5;
JTextField T1, T2, T3;
ButtonGroup botaoradio;
JPanel P2;
public static void main (String args[]) {
JFrame janela = new Radio2();
janela.show();
WindowListener x = new WindowAdapter()
{ public void windowClosing (WindowEvent fecha)
{System.exit(0);}
};
janela.addWindowListener(x);
Radio2();{
getContentPane().setBackground (new Color (0,0,0));
getContentPane().setLayout (new GridLayout(3,4));
L1 = new JLabel("numero 1");
L1.setForeground(Color.green);
L1.setFont(new Font(" ",Font.BOLD,14));
L2 = new JLabel("numero 2");
L2.setForeground(Color.blue);
L2.setFont(new Font(" ",Font.BOLD,14));
L3 = new JLabel("resultado");
L3.setForeground(Color.yellow);
L3.setFont(new Font(" ",Font.BOLD,14));
B1 = new JRadioButton("+");
B1.addItemListener(this);
B2 = new JRadioButton("-");
B2.addItemListener(this);
B3 = new JRadioButton("*");
B3.addItemListener(this);
B4 = new JRadioButton("/");
B4.addItemListener(this);
B5 = new JRadioButton("limpar");
B5.addItemListener(this);
B1.setMnemonic(KeyEvent.VK_1);
B2.setMnemonic(KeyEvent.VK_2);
B3.setMnemonic(KeyEvent.VK_3);
B4.setMnemonic(KeyEvent.VK_4);
B5.setMnemonic(KeyEvent.VK_5);
botaoradio = new ButtonGroup();
botaoradio.add(B1);
botaoradio.add(B2);
botaoradio.add(B3);
botaoradio.add(B4);
botaoradio.add(B5);
P2.setLayout(new GridLayout (2,3));
P2.setBackground (new Color (200,100,100));
P2.add(B1);
P2.add(B2);
P2.add(B3);
P2.add(B4);
P2.add(B5);
getContentPane().add(P2);
T1 = new JTextField();
T1.setBackground(Color.black);
T1.setForeground(Color.white);
T2 = new JTextField();
T2.setBackground(Color.black);
T2.setForeground(Color.white);
T3 = new JTextField();
T3.setBackground(Color.black);
T3.setForeground(Color.white);
T3.setEditable(false);
getContentPane().add(L1);
getContentPane().add(T1);
getContentPane().add(B1);
getContentPane().add(B2);
getContentPane().add(L2);
getContentPane().add(T2);
getContentPane().add(B3);
getContentPane().add(B4);
getContentPane().add(L3);
getContentPane().add(T3);
getContentPane().add(B5);
}
//Essa parte aqui esta dando erro "illegal start of expression"
//public void itemStateChanged(ItemEvent e){
if (e.getSource()==B5)
{
T1.setText(" ");
T2.setText(" ");
T3.setText(" ");
return;
}
float n1=0, n2=0, resultado=0;
try
{
n1 = Float.parseFloat(T1.getText());
n2 = Float.parseFloat(T2.getText());
}
catch (NumberFormatException erro)
{ T3.setText("erro"); return;}
if (e.getSource()==B1)
{
resultado = n1 + n2;
}
if (e.getSource()==B2)
{
resultado = n1 - n2;
}
if (e.getSource()==B3)
{
resultado = n1 * n2;
}
if (e.getSource()==B4)
{
resultado = n1 / n2;
}
T3.setText(" "+resultado);
}
}