1
我試圖獲得跑馬燈效果(我們在HTML相同)。但是我無法使用這段代碼。我如何改進此代碼以獲得選取框效果?
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
class tester {
JLabel l;
tester() {
JFrame fr=new JFrame();
JPanel p=new JPanel();
l=new JLabel("");
fr.add(p);
p.add(l);
fr.setVisible(true);
fr.setSize(400,400);
fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void MarqueeEffect() {
ActionListener ac = new ActionListener() {
public void actionPerformed(ActionEvent ae) {
l.setText("To action alone hast thou a right and never at all to its fruits let not the fruits of action be thy motive; neither let there be in thee any attachment to inaction");
}
};
new Timer(2000,ac).start();
}
public static void main(String args[]) {
tester t=new tester();
t.MarqueeEffect();
}
}
這是功課,不是嗎?你有什麼嘗試? – 2011-04-21 17:06:27