Sabtu, 17 April 2010

Program Animasi Pakai Java

import java.awt.event.*;
import java.awt.*;
class Animasi_Text extends Thread implements ActionListener,WindowListener{
Frame F=new Frame();
Button btPlay,btStop,btClose;
Label L;
Panel P;
public void actionPerformed(ActionEvent a){
String e=a.getActionCommand();
if(e.equals("Play")){
start();
}
else if(e.equals("Stop")){
suspend();}
else if(e.equals("Close")){
System.exit(0);}
}
public void initKomp(){
btStop = new Button("Stop");
btPlay = new Button("Play");
btClose = new Button("Close");



L = new Label ("Informatika");
btStop.addActionListener(this);
btPlay.addActionListener(this);
btClose.addActionListener(this);}
public void run(){
try{
while(true){
Point p=L.getLocation();
p.x+=1;
if (p.x>F.getHeight()){
for(int i=p.x;i>0;i--){
p.x-=1;L.setLocation(p);
sleep(10);}
}
L.setLocation(p);
sleep(10);
}
}
catch(InterruptedException inEx){}
}
public void layoutKomp(){
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
F.setLayout(gridbag);
c.fill = GridBagConstraints.BOTH;
L.setFont(new Font("Arial", Font.PLAIN, 25));
gridbag.setConstraints(btPlay,c);
F.add(btPlay);
gridbag.setConstraints(btStop,c);
F.add(btStop);
c.gridwidth = GridBagConstraints.REMAINDER;
gridbag.setConstraints(btClose,c);
F.add(btClose);
gridbag.setConstraints(L,c);
F.add(L);
}
public void windowClosing(WindowEvent e){
System.exit(0);}
public Animasi_Text(String title){
F.setTitle(title);
initKomp();
layoutKomp();
F.setSize(375,250);
F.show();}
public static void main(String arg[]){
Animasi_Text obj=new Animasi_Text("Animasi Text" );}
public void windowOpened(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
}

Hasil Outputnya:
selanjutnya

Tidak ada komentar:

Posting Komentar