Buongiono!
sto facendo un esercizio grafico che, date due textField, inserisca il segno <,> o = in base ai valori che vengono inseriti, questo è il codice:
codice:
import java.awt.*;
import java.awt.event.*;
class Es7 extends Frame {
public Es7() {
TextField t1 = new TextField();
TextField t2 = new TextField();
Label l1 = new Label("Etichetta");
Button b1 = new Button("Confronta");
Panel p1 = new Panel();
Panel p2 = new Panel();
p1.add(t1);
p1.add(l1);
p1.add(t2);
p2.add(b1);
add(p1,BorderLayout.NORTH);
add(p2,BorderLayout.SOUTH);
Chiudi asc = new Chiudi();
addWindowListener(asc);
b1.addActionListener(new Ascoltatore(t1,t2,l1));
setVisible(true);
pack();
}
}
class Ascoltatore implements ActionListener {
private TextField t1;
private TextField t2;
private Label l1;
public Ascoltatore (TextField t1, TextField t2, Label l1) {
this.t1 = t1;
this.t1 = t2;
this.l1 = l1;
}
public void actionPerformed(ActionEvent e) {
int n1 = Integer.parseInt(t1.getText());
int n2 = Integer.parseInt(t2.getText());
if(n1>n2) {
l1.setText(">"); //SCRITTURA NEL LABEL
}
if(n1<n2) {
l1.setText("<"); //SCRITTURA NEL LABEL
}
if(n1==n2) {
l1.setText("="); //SCRITTURA NEL LABEL
}
}
}
class Chiudi extends WindowAdapter {
public void windowClosed (WindowEvent e) {
System.exit(0);
}
public void windowClosing (WindowEvent e) {
e.getWindow().dispose();
}
}
class UsoEs7 {
public static void main(String[] args) {
Es7 a = new Es7();
}
}
L'errore sta nella scrittura del label, ma non riesco a capirlo, quando lo eseguo mi da una serie di informazioni che riguardano l'AWT, qualcuno può aiutarmi? grazie