我正试图制造一个小刀,通过时间交换文字信息。 目前,我曾尝试在行动听众中 lo,但没有成功。
import javax.swing.JPanel;
import javax.swing.Timer;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JLabel;
import java.awt.Rectangle;
public class TimerX extends JPanel{
private static final long serialVersionUID = 1L;
private JLabel jLabelNumber = null;
private Timer timer = new Timer(100, null);
private String [] messages = new String [4];{
messages [0] = "HI";
messages [1] = "How";
messages [2] = "Are";
messages [3] = "You";
}
public TimerX() {
super();
initialize();
}
private void initialize() {
jLabelNumber = new JLabel();
jLabelNumber.setBounds(new Rectangle(99, 85, 38, 16));
this.setSize(300, 200);
this.setLayout(null);
this.add(jLabelNumber, null);
ActionListener updater = new ActionListener(){
public void actionPerformed(ActionEvent event) {
for(int i = 0; i<messages.length;i++)
jLabelNumber.setText(messages[i]);
}
};
timer.addActionListener(updater);
timer.start();
}
}
该守则只显示阵列中最后的强势。 帮助 T.T