主题:Java事件actionEven,作业求助高手帮忙帮修改下。。本人写的很糟,在错误的地方加粗了,,
package Mybag;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
[b]class [b]MyWindow[/b] extends JFrame implements [b]ActionListener[/b]{ TextField[/b] text1,text2,text3;
Label Label_1;
PoliceMan police;
MyWindow(String s)
{
setLayout(new FlowLayout());
Label_1=new Label("",Label.CENTER);
Label_1.setBackground(Color.cyan);
text1=new TextField("文本框1");
text2=new TextField("文本框2");
text3=new TextField(15);
[b]text3.setEchoChar("^*");[/b] add(Label_1);
add(text1);
add(text2);
add(text3);
setBounds(100,100,200,200);
text1.addActionListener(this);
text2.addActionListener(this);
text3.addActionListener(police);
setVisible(true);
validate();
}
public void ActionListener(ActionEvent e)
{ if(e.getSource()==text1)
{Label_1.setText(text1.getText());}
else if(e.getSource()==text2)
{Label_1.setText(text2.getText());}
}
class PoliceMan implements ActionListener
{ public void actionPerformed(ActionEvent e)
{String passdword=e.getActionCommand();
Label_1.setText(passdword);
}
}
}
public class Homework_2
{public static void main(String args[])
[b]{MyWindow [b]win[/b]=new MyWindow("ActionEvent事件作业");}[/b]}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
[b]class [b]MyWindow[/b] extends JFrame implements [b]ActionListener[/b]{ TextField[/b] text1,text2,text3;
Label Label_1;
PoliceMan police;
MyWindow(String s)
{
setLayout(new FlowLayout());
Label_1=new Label("",Label.CENTER);
Label_1.setBackground(Color.cyan);
text1=new TextField("文本框1");
text2=new TextField("文本框2");
text3=new TextField(15);
[b]text3.setEchoChar("^*");[/b] add(Label_1);
add(text1);
add(text2);
add(text3);
setBounds(100,100,200,200);
text1.addActionListener(this);
text2.addActionListener(this);
text3.addActionListener(police);
setVisible(true);
validate();
}
public void ActionListener(ActionEvent e)
{ if(e.getSource()==text1)
{Label_1.setText(text1.getText());}
else if(e.getSource()==text2)
{Label_1.setText(text2.getText());}
}
class PoliceMan implements ActionListener
{ public void actionPerformed(ActionEvent e)
{String passdword=e.getActionCommand();
Label_1.setText(passdword);
}
}
}
public class Homework_2
{public static void main(String args[])
[b]{MyWindow [b]win[/b]=new MyWindow("ActionEvent事件作业");}[/b]}