ciao a tutti mi da errore sui CheckBoxMenuItem,sapete dirmi come mai???
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.JMenuBar;
public class prova extends Frame implements ActionListener {
JButton pulsante1=new JButton("Converti");
JButton pulsante2=new JButton("+");
JButton pulsante3=new JButton("-");
JButton pulsante4=new JButton("Complemento a 2 +");
JButton pulsante5=new JButton("Complemento a 2 -");
TextField testo1=new TextField();
TextField testo2=new TextField();
TextField testo3=new TextField();
TextField testo4=new TextField();
CheckBoxMenuItem inte = new CheckBoxMenuItem("Numeri interi");
CheckBoxMenuItem raz = new CheckBoxMenuItem("Numeri razionali");
MenuItem ab=new MenuItem("About");
MenuBar barra=new MenuBar();
Menu file= new Menu("File");
Menu about= new Menu("?");
public prova()
{
setLayout(null);
JLabel lab=new JLabel();
JLabel lab1=new JLabel();
JLabel lab2=new JLabel();
this.add(lab);
this.add(lab1);
this.add(lab2);
file.add(inte);
file.add(raz);
about.add(ab);
barra.add(file);
barra.add(about);
setMenuBar(barra);
this.add(pulsante1);
this.add(pulsante2);
this.add(pulsante3);
this.add(pulsante4);
this.add(pulsante5);
this.add(testo1);
this.add(testo2);
this.add(testo3);
this.add(testo4);
pulsante1.setBounds(180,105,90,30);
pulsante2.setBounds(50,165,60,30);
pulsante3.setBounds(50,225,60,30);
pulsante4.setBounds(50,295,150,30);
pulsante5.setBounds(250,295,150,30);
testo1.setBounds(220,55,60,30);
testo2.setBounds(50,105,100,30);
testo3.setBounds(200,195,100,30);
testo4.setBounds(170,345,100,30);
lab.setText("Inserisci un numero intero positivo");
lab.setBounds(10,44,205,40);
lab1.setText("Notazione modulo-segno");
lab1.setBounds(30,130,205,40);
lab2.setText("Complemento alla base");
lab2.setBounds(30,250,205,40);
pulsante1.addActionListener(this);
pulsante2.addActionListener(this);
pulsante3.addActionListener(this);
pulsante4.addActionListener(this);
pulsante5.addActionListener(this);
testo1.addActionListener(this);
testo4.addActionListener(this);
testo2.addActionListener(this);
testo3.addActionListener(this);
this.addWindowListener(new MioAscoltaWin());
setTitle("Binary Calculator 1.0 by H");
setLocation(200,100);
setSize(500,500);
setVisible(true);
}
public static void main(String []s)
{
prova p=new prova();
}
public void actionPerformed(ActionEvent e)
{
String c=e.getActionCommand();
String f=testo1.getText();
int i;
long resto;
long aInt=Long.parseLong(f);
i=0;
if(e.getSource()==pulsante1)
{
StringBuffer sb = new StringBuffer();
while(aInt>0)
{
resto=aInt%2;
sb.append(resto);
aInt=aInt/2;
}
testo2.setText(sb.reverse().toString());
}
if(e.getSource()==pulsante2)
{
StringBuffer sb = new StringBuffer();
while(aInt>0)
{
resto=aInt%2;
sb.append(resto);
aInt=aInt/2;
}
testo3.setText("0"+sb.reverse().toString());
}
if(e.getSource()==pulsante3)
{
StringBuffer sb = new StringBuffer();
while(aInt>0)
{
resto=aInt%2;
sb.append(resto);
aInt=aInt/2;
}
testo3.setText("1"+sb.reverse().toString());
}
if(e.getSource()==pulsante4)
{
StringBuffer sb = new StringBuffer();
while(aInt>0)
{
resto=aInt%2;
sb.append(resto);
aInt=aInt/2;
}
testo4.setText("0"+sb.reverse().toString());
}
if(e.getSource()==pulsante5)
{
int found;
StringBuffer sb = new StringBuffer();
while(aInt>0)
{
resto=aInt%2;
sb.append(resto);
aInt=aInt/2;
}
String a=sb.toString();
int length = a.length();
found=0;
char vet[]=a.toCharArray();
for(i=0;i<length;i++)
{
if(vet[i]=='1' && found==0){
vet[i]='1';
found=1;}
else
{
if(vet[i]=='0' && found==0)
vet[i]='1';
else
{
if(vet[i]=='0' && found==1)
vet[i]='1';
else
{
if(vet[i]=='1' && found==1)
vet[i]='0';
}
}
}
}
String g=String.valueOf(vet);
StringBuffer sbr=new StringBuffer(g);
String fv=new StringBuffer(g).reverse().toString();
testo4.setText("1"+fv);
}
}
}