Saturday, March 5, 2011

How To Install D2 Bot



Moving Title

'll see how we can make the title of our application is not static but can be moved either to show more information than can be seen in the window or luxury. Images








Code


Master Class



Classes package;


import java.awt.event.ActionEvent ;
import java.awt.event.ActionListener;
import javax.swing .*;


public class Main extends JFrame {

moverTitulo mt
JTextField txt;

public Principal ( ) {

moverTitulo mt = new (this);
mt.start ();

JPanel p = new JPanel ();
txt = new JTextField (15 )
change = new JButton JButton ("Change Title");
cambiar.addActionListener (new ActionListener () {



@ Override public void actionPerformed (ActionEvent e) {
txt.getText mt.titulo = ();
mt.indice = 0;
}

});
p.add (new JLabel ("New Title"));
p.add (txt);
p.add (change);
add (p);
}

public static void main (String arg []) {
Principal p = new Principal ();
p.setVisible (true);
p.setBounds (0, 0, 400, 100);
p.setDefaultCloseOperation (EXIT_ON_CLOSE)
p.setLocationRelativeTo (null )
}


}


Class moverTitulo



Classes package;


moverTitulo public class extends Thread {

Principal p;
String title = "Java Zone, Learn all about java. Visit us at www.java-elrincondetucasa.blogspot.com"
int index = 0;

public moverTitulo (Main main) {
p = main;
p.setTitle (title);
}

public void run () {
while (true) {
try {
Thread.sleep (300);
} catch (InterruptedException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}
p.setTitle (move ());
if (index \u0026lt; titulo.length ()) {
index + +;
} else {
index = 0;

}}
}

public String move () {return
titulo.substring (index);

}}

As we see the class main creates a moverTitulo, we begin to move the title to start () method. Then create a JTextField and JButton, when we press the button changes the text to display in the title.

moverTitulo class inherited from Thread, the run () method, put a while (true) of this as the thread will never die, plus the index increases by 1 every 300 milliseconds. With the method move (), return a String is a substring of the title that starts from the index until the total size of the title. When the index reaches the size of the title index becomes 0 and starts again.

0 comments:

Post a Comment