Tuesday, March 8, 2011

Best Bang For The Buck Camcorder

custom icon in the Animation Window Title

Animation Window Icon

We have already seen how we could animate the title of a window, now we'll see how we can make our window icon , also has movement.

icon change need not always, when the program can encourage us something or going to notify every few minutes, depending on each application that we will give.

Images




Code

Master Class

Classes package;

import javax.swing.JFrame;

public class Principal extends JFrame{
moverIcono mi;
public Principal(){
mi=new moverIcono(this);
mi.start();
}
public static void main(String arg[]){
Home p = new Principal ();
p.setBounds (0, 0, 300, 200);
p.setLocationRelativeTo (null);
p.setVisible (true);
}

}

Class moverIcono

package
Classes ;

import java.util.ArrayList;

import javax.swing.ImageIcon;

public class moverIcono extends Thread {
ArrayList < ImageIcon> iconos;
Principal p;
int indice=9;
public moverIcono(Principal prin){
p=prin;
iconos=new ArrayList ();
for(int i=0;i < 10;i++){
iconos.add(new ImageIcon(this.getClass().getResource("../lib/imagennumero"+i+".jpg")));
}
}
public void run(){
while(true){
p.setIconImage (iconos.get (index). GetImage ());
if (index> 0) {
index -;
} else {
index = 9;
try {
Thread.sleep (2000);
} catch (InterruptedException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}
}
try {
Thread.sleep (800);
} catch ( InterruptedException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}
}
}}

The main class creates a moverIcono, this is going to do all the animation, this class inherits from Thread, so it's a thread in the constructor initializes a list which contains ImageIcon the icon. Then we implement the run () method of the Thread class, and assign an icon to the window, then decreased the index and look forward to 0.8 seconds and change the icon, and so on.

The index starts at 9 and will be declining until it reaches 0, then the index takes again the value of 9 and wait 2 seconds before resuming the animation.

Monday, March 7, 2011

Where Did Anna Nicole Smith Die?

23-F "THE ULTIMATE BETRAYAL. KEYS 23-F"

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.

Write Message In Baby Book

Moving Image and Text Place cell in a JTable

Place Image and Text in a JTable cell

already seen as placing some components in the cells of a JTable, but this time not all cells in a column, we'll see We can put a label with image and text in the cell that we want.

Images





Code


Top Class


package classes;


import java.awt.BorderLayout;
import java.awt.event .* ;
import javax.swing .*;
import javax.swing. table.DefaultTableModel;


public class Main extends JApplet {

JTable table;
CeldaConJLabel editor;
JScrollPane scroll;
DefaultTableModel model;
int row = 0;
int col = 0;
ButtonGroup group;
JRadioButton r1, r2;
JButton place;
ImageIcon img1, img2;
JLabel lseleccionada;
JTextField txt;

public void init () {

model = new DefaultTableModel (2, 3);
tabla = new JTable (model);


CeldaConJLabel editor = new (this);
tabla.getColumnModel (). getColumn (0). setCellRenderer (editor);
tabla.getColumnModel (). getColumn (1). setCellRenderer (editor);
tabla.getColumnModel (). GetColumn (2). SetCellRenderer (editor);
tabla.setRowHeight (35);

tabla.addMouseListener (new MouseListener ( ) {



@ Override public void mouseClicked (MouseEvent e) {
/ / TODO Auto-generated method stub
tabla.getSelectedRow row = ( )
tabla.getSelectedColumn col = ();
}



@ Override public void mouseEntered (MouseEvent e) {
/ / TODO Auto-generated method stub

}



@ Override public void mouseExited (MouseEvent e) {
/ / TODO Auto-generated method stub

}



@ Override public void mousePressed (MouseEvent e) {
/ / TODO Auto-generated method stub



}


@ Override public void mouseReleased (MouseEvent e) {
/ / TODO Auto-generated method stub

}

});

scroll = new JScrollPane (table);
add (scroll);

pabajo JPanel = new JPanel ( )
txt = new JTextField (15);
pabajo.add (new JLabel ("Text"));
pabajo.add (txt);
ButtonGroup group = new ();
img1 = new ImageIcon (this.getClass (). getResource ("../ lib/img1.png "));
img2 = new ImageIcon (this.getClass (). GetResource ("../ lib/img2.png "));
r1 = new JRadioButton ("");
r1.setSelected (true);
r2 = new JRadioButton ("");
grupo.add (r1);
grupo.add (r2);
put = new JButton ("Put");
colocar.addActionListener (new ActionListener () {


@ Override
public void actionPerformed(ActionEvent arg0) {
if(r1.isSelected()){
if(lseleccionada!=null){
lseleccionada.setIcon(img1);
lseleccionada.setText(txt.getText());
}
}else{
if(lseleccionada!=null){
lseleccionada.setIcon(img2);
lseleccionada.setText(txt.getText());
}
}}


});

pabajo.add (r1);
pabajo.add (new JLabel (img1));
pabajo.add (r2);
pabajo.add (new JLabel (img2));
pabajo.add (put);

add (pabajo, BorderLayout.SOUTH);

}}



Class CeldaConJLabel


package classes;


import java.awt.Component;
import java.util.ArrayList;
import java.util.EventObject;


import javax.swing.JLabel;
import javax.swing.JTable;
import javax. swing.event.CellEditorListener;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;


public class CeldaConJLabel implements TableCellRenderer{


Principal p;
JLabel l;

public CeldaConJLabel(Principal prin){
p=prin;
l=new JLabel("");
}

@Override
Component public getTableCellRendererComponent (JTable table, Object arg1,
boolean isSelected, boolean arg3, int row, int col) {
/ / TODO Auto-generated method stub
if (isSelected & & row & & col == == p.fila p.col) {
p.lseleccionada = l;
tabla.repaint ();
return l;
} else {
tabla.repaint ();
return null;
}
}}


The main class creates a JTable, DefaultTableModel object, an object of class CeldaConJLabel, also creates two radioButton to select images, a JTextField for the text to be displayed and a JButton to position text and image in the selected cell.

By selecting the cell and press the button to place, we tell the table that displays the image and text in the selected cell.

CeldaConJLabel class implements TableCellRenderer interface, and overwrites the getTableCellRendererComponent method, which allows us to modify an object that is returned to the selected cell, in this case a JLabel, but can be any component.

Applet

must first select the cell that you want to add the image with the text.