Cerrar ventana

Qtal bueno tengo una i nkietud nose como hacer lo siguiente
Tengo una ventana de acceso del sistema yo kisiera que la ventana despues de 1 minuto se cierre que me ponga un reloj en el jform y despues quet termienle minuto se cierre alguna idea gracias o un ejemplo

1 respuesta

Respuesta
1
¿No eres marabao? Jajajajajaj xD
Bueno mira esto me pregunto un usuario de aqui creo q te servira a ti :
He ido avanzando con el codigo, como podras ver:
Mi intencion es poner una ventanita que se cierre a los 3 segundos al pulsar el boton start.
Es decir, cuando pulso start en la pantalla, ¿aparecera un recuadro que ponga?:
Preparado 3 y vaya bajando hasta 0, y entonces esa ventana se cierre y empieze a funcionar el contador, ¿me podrias ayudar?
Gracias de nuevo
import java.awt.event.KeyEvent;
import javax.swing.JOptionPane;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* jframe.java
*
* Created on 11/04/2011, 09:32:56 AM
*/
/**
*
* @author J6
*/
public class jframe extends javax.swing.JFrame {
/** Creates new form jframe */
public jframe() {
initComponents();
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/stop.gif")));
btnStop.addKeyListener(new java.awt.event.KeyAdapter() {
@Override
public void keyPressed(java.awt.event.KeyEvent evt) {
btnStopKeyPressed(evt);
}
});
}
int hora = 0, min = 0, seg = 000;
Thread hilo = new Thread() {
@Override
public void run() {
try {
while (true) {
if (seg == 59) {
seg = 0;
min++;
}
if (min == 9) {
min = 0;
hora++;
}
seg++;
lblTime.setText(hora + ":" + min + ":" + seg);
hilo.sleep(1);
}
} catch (java.lang.InterruptedException ie) {
System.out.println(ie.getMessage());
}
}
};
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
lblTime = new javax.swing.JLabel();
btnStart = new javax.swing.JButton();
btnStop = new javax.swing.JButton();
lblStatus = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Semaforo");
lblTime.setText("Time");
btnStart.setText("Start");
btnStart.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btnStartMouseClicked(evt);
}
});
btnStop.setText("Stop");
btnStop.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btnStopMouseClicked(evt);
}
});
btnStop.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
btnStopKeyPressed(evt);
}
});
lblStatus.setText("Estado: ");
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Reloj.gif"))); // NOI18N
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
. AddGroup(layout. CreateSequentialGroup()
. AddGroup(layout. CreateParallelGroup(javax. Swing. GroupLayout. Alignment. LEADING)
. AddGroup(layout. CreateSequentialGroup()
. AddGap(38, 38, 38)
. AddGroup(layout. CreateParallelGroup(javax. Swing. GroupLayout. Alignment. Trailing)
. AddComponent(btnStop)
. AddComponent(btnStart))
. AddGap(46, 46, 46)
. AddComponent(lblTime, javax. Swing. GroupLayout.PREFERRED_SIZE, 144, javax. Swing. GroupLayout.PREFERRED_SIZE)
.addGap(6, 6, 6)
. AddComponent(jLabel1))
. AddComponent(lblStatus, javax. Swing. GroupLayout.PREFERRED_SIZE, 141, javax. Swing. GroupLayout.PREFERRED_SIZE))
.addContainerGap(61, Short.MAX_VALUE))
);
Layout. SetVerticalGroup(
layout. CreateParallelGroup(javax. Swing. GroupLayout. Alignment. LEADING)
. AddGroup(layout. CreateSequentialGroup()
. AddGap(39, 39, 39)
. AddComponent(btnStart)
. AddGap(18, 18, 18)
. AddComponent(btnStop)
. AddPreferredGap(javax. Swing. LayoutStyle. ComponentPlacement.RELATED, 92, Short.MAX_VALUE)
. AddComponent(lblStatus))
. AddGroup(layout. CreateSequentialGroup()
. AddGap(41, 41, 41)
. AddGroup(layout. CreateParallelGroup(javax. Swing. GroupLayout. Alignment. LEADING)
. AddComponent(jLabel1)
. AddComponent(lblTime, javax. Swing. GroupLayout.PREFERRED_SIZE, 42, javax. Swing. GroupLayout.PREFERRED_SIZE))
.addContainerGap(118, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
public boolean issuspended = false;
private void btnStartMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnStartMouseClicked
btnStart.setVisible(false);
btnStop.setVisible(true);
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Reloj.gif")));
if (!issuspended) {
hilo = new Thread() {
public void run() {
try {
int hora = 0, min = 0, seg = 000;
while (true) {
if (seg == 59) {
seg = 0;
min++;
}
if (min == 9) {
min = 0;
hora++;
}
if (hora == 1) {
btnStart.setVisible(true);
btnStop.setVisible(true);
JOptionPane.showMessageDialog(null, "Fallaste", "Error",
JOptionPane.ERROR_MESSAGE);
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/stop.gif")));
lblTime.setText("0:0:0");
hilo.stop();
}
seg++;
lblTime.setText(hora + ":" + min + ":" + seg);
hilo.sleep(1);
}
} catch (java.lang.InterruptedException ie) {
System.out.println(ie.getMessage());
}
}
};
hilo.start();
lblStatus.setText("Estado: GO!!!");
} else {
hilo.destroy();
issuspended = false;
lblStatus.setText("Estado: Resumido");
}
}//GEN-LAST:event_btnStartMouseClicked
private void btnStopMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnStopMouseClicked
btnStart.setVisible(true);
btnStop.setVisible(true);
hilo.stop();
lblStatus.setText("STOP");
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/stop.gif")));
issuspended = false;
}//GEN-LAST:event_btnStopMouseClicked
private void btnStopKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_btnStopKeyPressed
// TODO add your handling code here:
switch (KeyEvent.VK_S) {
case KeyEvent.VK_S:
btnStopMouseClicked(null);
break;
}
}//GEN-LAST:event_btnStopKeyPressed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new jframe().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnStart;
private javax.swing.JButton btnStop;
private javax.swing.JLabel jLabel1;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JLabel lblStatus;
private javax.swing.JLabel lblTime;
// End of variables declaration//GEN-END:variables
}
y esto conteste:
8/07/2011
Experto
ok mira donde declaras el hilo ponle esto
////////////////////////////////////////////////////////////////////////
hilo = new Thread() {
public void run() {
try {
int hora = 0, min = 0, seg = 000;
while (true) {
if (seg == 59) {
seg = 0;
min++;
}
if (min == 9) {
min = 0;
hora++;
}
seg++;
lblTime.setText(hora + ":" + min + ":" + seg);
if (hora==3)
{
lblTime.setVisible(false);
}
hilo.sleep(1);
}
} catch (java.lang.InterruptedException ie) {
System.out.println(ie.getMessage());
}
}
};
////////////////////////////////////////////////////////////////////
esto lo q hace es q alos 3 segundos oculta la etiqueta pero tu cambia en donde dice
lblTime.setVisible(false);
por
new jframeOTRO().setVisible(true);
y asi alos 3 segumdos te abre otro
lo de mas te toca a ti :)

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas