Lo que tengo implementado
public class VentanaPalabras {
int numpal = 0;
public Component createComponents(Vector fichero) {
final JLabel label = new JLabel("Aqui aparecera la palabra");
final Vector aux = fichero;
label.setFont( new Font( "Helvetica", Font.BOLD, 42 ) );
JButton button = new JButton("Nueva Palabra");
button.setMnemonic('i');
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (numpal < aux.size())
{
String tmp = (String) (aux.elementAt(numpal));
numpal++;
label.setText(" "+tmp);
}
else
label.setText("Ya no hay mas palabras");
}
});
label.setLabelFor(button);
JPanel pane = new JPanel();
pane.setBorder(BorderFactory.createEmptyBorder(
30, //top
30, //left
10, //bottom
30) //right
);
pane.setLayout(new GridLayout(0, 1));
pane.add(button);
pane.add(label);
/* Thread MiThread = new Thread();
MiThread.start();
try {
label.setVisible(true);
MiThread.sleep( 2000 );
label.setVisible(false);
} catch( InterruptedException a ) {
;
}
*/
return pane;
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(
UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception e) { }
//Create the top-level container and add contents to it.
JFrame frame = new JFrame("PALABRAS");
LectFich ejemplo = new LectFich();
VentanaPalabras ventana = new VentanaPalabras();
Component contents = ventana.createComponents(ejemplo.LectFich("palabras.txt"));
frame.getContentPane().add(contents, BorderLayout.CENTER);
//Finish setting up the frame, and show it.
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.pack();
frame.setVisible(false);
}
}
int numpal = 0;
public Component createComponents(Vector fichero) {
final JLabel label = new JLabel("Aqui aparecera la palabra");
final Vector aux = fichero;
label.setFont( new Font( "Helvetica", Font.BOLD, 42 ) );
JButton button = new JButton("Nueva Palabra");
button.setMnemonic('i');
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (numpal < aux.size())
{
String tmp = (String) (aux.elementAt(numpal));
numpal++;
label.setText(" "+tmp);
}
else
label.setText("Ya no hay mas palabras");
}
});
label.setLabelFor(button);
JPanel pane = new JPanel();
pane.setBorder(BorderFactory.createEmptyBorder(
30, //top
30, //left
10, //bottom
30) //right
);
pane.setLayout(new GridLayout(0, 1));
pane.add(button);
pane.add(label);
/* Thread MiThread = new Thread();
MiThread.start();
try {
label.setVisible(true);
MiThread.sleep( 2000 );
label.setVisible(false);
} catch( InterruptedException a ) {
;
}
*/
return pane;
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(
UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception e) { }
//Create the top-level container and add contents to it.
JFrame frame = new JFrame("PALABRAS");
LectFich ejemplo = new LectFich();
VentanaPalabras ventana = new VentanaPalabras();
Component contents = ventana.createComponents(ejemplo.LectFich("palabras.txt"));
frame.getContentPane().add(contents, BorderLayout.CENTER);
//Finish setting up the frame, and show it.
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.pack();
frame.setVisible(false);
}
}