import javax.swing.JLabel;
import javax.swing.WindowConstants;
import javax.swing.JFrame;
public class NewJFrame extends JFrame{
String top="This is Network Programming Lab";
String bottom="This is also Computer Graphics Lab";
JLabel Jtop=new JLabel();
JLabel Jbottom=new JLabel();
public NewJFrame() {
setLayout(null);
setSize(400,300);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
add(Jtop);
Jtop.setLocation(0, 10);
Jtop.setSize(getWidth(), 20);
Jtop.setText(top);
add(Jbottom);
Jbottom.setLocation(400, getHeight()-50-15);
Jbottom.setSize(getWidth(),20);
Jbottom.setText(bottom);
t.start();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
Thread t=new Thread()
{
public void run()
{
int i=3;
while(true)
{
try {
Thread.sleep(80);
} catch (Exception ex) {}
Jtop.setLocation(Jtop.getX()+i,Jtop.getY());
Jbottom.setLocation(Jbottom.getX()-i,Jbottom.getY());
if(Math.abs(Jtop.getX())>=400)
i*=-1;
}
}
};
}
No comments:
Post a Comment