Non riesco a capire perchè nella mia applicazione non funziona
l'evento di una textfield,eppure ho inserito quello che c'era da
inserire.Vi posto il sorgente per maggiore chiarezza.Grazie mille per
l'eventuale aiuto!
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class sommario extends Applet implements ActionListener {
public void init() {
TextField red1=new TextField();
TextField green1=new TextField();
TextField blue1=new TextField();
TextField yellow1=new TextField();
TextField ciano1=new TextField();
TextField white1=new TextField();
char strcolor=0;
char red,green,blue,yellow,ciano,white;
Color c;
Label label0;
setLayout(new GridLayout(7,1,10,10));
add(new Label("ID"));
add(new Label("Color"));
add(new Label("Change"));
add(label0=new Label("0"));
add(red1);
add(new Label("change"));
add(new Label("2"));
add(green1);
add(new Label("change"));
add(new Label("3"));
add(blue1);
add(new Label("change"));
add(new Label("4"));
add(yellow1);
add(new Label("change"));
add(new Label("5"));
add(ciano1);
add(new Label("change"));
add(new Label("6"));
add(white1);
add(new Label("change"));
red1.addActionListener(this);
green1.addActionListener(this);
switch( strcolor){
case 1:
c= new Color(255,0,0);
red1.setBackground(c);
red1.setText("red");
break;
case 2:
c= new Color(0,255,0);
green1.setText("green");
break;
case 3:
c= new Color(0,0,255);
blue1.setText("blue");
break;
case 4:
c= new Color(255,0,0);
yellow1.setText("Yellow");
break;
case 5:
c= new Color(255,255,0);
ciano1.setText("ciano");
break;
case 6:
c= new Color(255,255,255);
white1.setText("white");
break;
}
}
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() instanceof TextField)
setForeground(Color.red);
repaint();
}
}
l'evento di una textfield,eppure ho inserito quello che c'era da
inserire.Vi posto il sorgente per maggiore chiarezza.Grazie mille per
l'eventuale aiuto!
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class sommario extends Applet implements ActionListener {
public void init() {
TextField red1=new TextField();
TextField green1=new TextField();
TextField blue1=new TextField();
TextField yellow1=new TextField();
TextField ciano1=new TextField();
TextField white1=new TextField();
char strcolor=0;
char red,green,blue,yellow,ciano,white;
Color c;
Label label0;
setLayout(new GridLayout(7,1,10,10));
add(new Label("ID"));
add(new Label("Color"));
add(new Label("Change"));
add(label0=new Label("0"));
add(red1);
add(new Label("change"));
add(new Label("2"));
add(green1);
add(new Label("change"));
add(new Label("3"));
add(blue1);
add(new Label("change"));
add(new Label("4"));
add(yellow1);
add(new Label("change"));
add(new Label("5"));
add(ciano1);
add(new Label("change"));
add(new Label("6"));
add(white1);
add(new Label("change"));
red1.addActionListener(this);
green1.addActionListener(this);
switch( strcolor){
case 1:
c= new Color(255,0,0);
red1.setBackground(c);
red1.setText("red");
break;
case 2:
c= new Color(0,255,0);
green1.setText("green");
break;
case 3:
c= new Color(0,0,255);
blue1.setText("blue");
break;
case 4:
c= new Color(255,0,0);
yellow1.setText("Yellow");
break;
case 5:
c= new Color(255,255,0);
ciano1.setText("ciano");
break;
case 6:
c= new Color(255,255,255);
white1.setText("white");
break;
}
}
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() instanceof TextField)
setForeground(Color.red);
repaint();
}
}