import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class TB extends Applet implements ActionListener
{
String msg="";
Button yes,no,maybe;
public void init(){
yes=new Button("yes");
no=new Button("no");
maybe=new Button("maybe");
add (yes);
add (no);
add (maybe);
yes.addActionListener(this);
no.addActionListener(this);
maybe.addActionListener(this);
}
public void actionPerformed(ActionEvent ae){
String str=ae.getActionCommand();
if(str.equals("yes")){
new KeyText();
msg="open TextYes";
}
else if(str.equals("no")){
msg="open TextNo";
}
else{
msg="open TextMayBe";
}
repaint();
}
public void paint(Graphics g){
g.drawString(msg,6,100);
}
}
*****************************************************************8
import java.awt.*;
import java.awt.event.*;
public class KeyText extends Frame
{ static String msg="";
int x=50,y=50;
public KeyText (){
addWindowListener(new MyWindowAdapter());
addKeyListener(new MyKeyAdapter(this));
requestFocus();
}
public static void main (String args[]){
KeyText keyText=new KeyText();
keyText.setSize(new Dimension(300,200));
keyText.setTitle("An AWT");
keyText.setVisible(true);
}
public void paint(Graphics g){
g.drawString(msg,x,y);
}
}
class MyKeyAdapter extends KeyAdapter
{
KeyText keyText;
public MyKeyAdapter(KeyText keyText){
this.keyText= keyText;
}
public void keyTyped(KeyEvent ke){
keyText.msg+=ke.getKeyChar();
keyText.repaint();
}
}
class MyWindowAdapter extends WindowAdapter{
public void windowClosing(WindowEvent we){
System.exit(0);
}
}
**************************************************8
我希望点击第一个程序的yes按钮是,第二个程序响应。为什么出现不了效果?
是不是那些地方出错了