elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Rompecabezas de Bitcoin, Medio millón USD en premios


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Java
| | | |-+  Bloquear pantalla
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] 2 Ir Abajo Respuesta Imprimir
Autor Tema: Bloquear pantalla  (Leído 8,270 veces)
Mine Sweeper

Desconectado Desconectado

Mensajes: 29


Ver Perfil
Bloquear pantalla
« en: 6 Septiembre 2013, 15:34 pm »

Necesito hacer un programa, el cual si no se llena cierta informacion en un Textfield que no te permita cambiarte de ventana dentro de windows, osea que no puedas quitar el programa hasta que llenes la informacion que se necesita, existe alguna funcion o algo para hacer esto?


En línea

Stakewinner00


Desconectado Desconectado

Mensajes: 1.426



Ver Perfil WWW
Re: Bloquear pantalla
« Respuesta #1 en: 6 Septiembre 2013, 15:55 pm »

No se java, pero supongo que puedes hacer que el programa vaya poniendo el focus en la ventana que tenga un nombre específico. Así el usuario se vería obligado a rellenar esa información para poder cambiar el focus


En línea

Zoik

Desconectado Desconectado

Mensajes: 91


Ver Perfil
Re: Bloquear pantalla
« Respuesta #2 en: 6 Septiembre 2013, 16:44 pm »

Bueno, podrías programar un evento en ese textfield, que hasta que no escriba esa información mantenga esa ventana con lo siguiente:

Código
  1. ventana.setModal(true);

Y para que no cierren la aplicación:

Código
  1. frame.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

Este último código unicamente se le puede aplicar a tu frame, en el caso en que le den a la X no se cerrara, solo podrán matar el proceso.

Un saludo y comenta que tal te fue.
En línea

Mine Sweeper

Desconectado Desconectado

Mensajes: 29


Ver Perfil
Re: Bloquear pantalla
« Respuesta #3 en: 6 Septiembre 2013, 18:17 pm »

Andube investigando, y encontre este codigo en una pagina, el cual puedo modificar para hacer lo que necesito, pero la situacion es esta.
Si los datos que meten en el campo de texto son correctos, debe desbloquear la pantalla, hasta ahi no hay ningun problema, el problema es que de ahi usan una aplicacion hecha por un provedor y al final imprime una etiqueta, se puede saber cuando cambia el estado de impresion para que cuando imprima volver a bloquear la pantalla y que asi se este repitiendo?

Este es el codigo que encontre:
Código:
import javax.swing.JOptionPane;
/**
 * @web http://www.jc-mouse.net/
 * @author Mouse
 */
public class jFrameBlocked extends javax.swing.JFrame {

    /**
     * Creates new form jFrameBlocked
     */
    public jFrameBlocked() {
       
        this.setUndecorated(true);//quita bordes a jframe
       
        initComponents();
       
        this.setDefaultCloseOperation( DO_NOTHING_ON_CLOSE  );//evita cerra jframe con ALT+C
        this.setExtendedState( MAXIMIZED_BOTH );//maximizado
        this.setAlwaysOnTop(true);//siempre al frente       
        //nueva instancia de jBlocked pasando como parametros e este JFrame
        new jBlocked( this ).block();
       
    }

    /**
     * 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() {
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        user = new javax.swing.JTextField();
        pass = new javax.swing.JTextField();
        btnSalir = new javax.swing.JButton();
        btnEntrar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(51, 51, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jPanel1.setLayout(new java.awt.GridBagLayout());

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel2.setLayout(new java.awt.GridBagLayout());

        jLabel1.setText("Usuario :");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(40, 40, 5, 5);
        jPanel2.add(jLabel1, gridBagConstraints);

        jLabel2.setText("Contraseña :");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 40, 5, 5);
        jPanel2.add(jLabel2, gridBagConstraints);

        user.setPreferredSize(new java.awt.Dimension(200, 32));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(40, 5, 5, 40);
        jPanel2.add(user, gridBagConstraints);

        pass.setPreferredSize(new java.awt.Dimension(200, 32));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 40);
        jPanel2.add(pass, gridBagConstraints);

        btnSalir.setText("Cancelar");
        btnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalirActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(30, 10, 40, 0);
        jPanel2.add(btnSalir, gridBagConstraints);

        btnEntrar.setText("Entrar");
        btnEntrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEntrarActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(30, 0, 40, 0);
        jPanel2.add(btnEntrar, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        jPanel1.add(jPanel2, gridBagConstraints);

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalirActionPerformed
       System.exit(0);
    }//GEN-LAST:event_btnSalirActionPerformed

    private void btnEntrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEntrarActionPerformed
        if( this.user.getText().equals("user") && this.pass.getText().equals("1234") )
        {
            new jFrameGUI().setVisible(true);
            this.dispose();           
        }
        else
        {
            JOptionPane.showMessageDialog( this, "Access denied");
        }
    }//GEN-LAST:event_btnEntrarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(jFrameBlocked.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(jFrameBlocked.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(jFrameBlocked.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(jFrameBlocked.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new jFrameBlocked().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnEntrar;
    private javax.swing.JButton btnSalir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField pass;
    private javax.swing.JTextField user;
    // End of variables declaration//GEN-END:variables
}


Código:
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.swing.JFrame;
/**
 * @web http://www.jc-mouse.net/
 * @author Mouse
 */
public class jBlocked {
   
    private JFrame jframe=null;
   
    /**
     * Constructor de clase
     */
    public jBlocked( JFrame f )
    {
        this.jframe = f;
    }
   
    /**
     * ejecuta una tarea cada "n" tiempo
     * Para evitar que el usuario utilice las teclas (WINDOWS + D)(TAB) y asi perder el foco
     * de la aplicación, cada 50 milisegundos se envia el JFrame al frente y se cambia su propiedad a maximizado
     */
    public void block()
    {
        ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
        scheduler.scheduleAtFixedRate(
            new Runnable()
            {
                @Override
                public void run() {                   
                    front();
                }
              }, 500, 50 , TimeUnit.MILLISECONDS ); //comienza dentro de 1/2 segundo y luego se repite cada N segundos
    }
   
    /**
     *
     */
    public void front()
    {
        jframe.setExtendedState( JFrame.MAXIMIZED_BOTH );//maximizado
        jframe.toFront();
    }
   
}//--> fin


Código:
public class jFrameGUI extends javax.swing.JFrame {

    /**
     * Creates new form jFrameGUI
     */
    public jFrameGUI() {
        initComponents();
        this.setLocationRelativeTo(null);//posicion al centro de la pantalla           
        this.setAlwaysOnTop(true);//siempre al frente       
    }

    /**
     * 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() {
        java.awt.GridBagConstraints gridBagConstraints;

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Access granted");
        getContentPane().setLayout(new java.awt.GridBagLayout());

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Congratulations");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(40, 100, 10, 100);
        getContentPane().add(jLabel1, gridBagConstraints);

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("Access granted");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 50, 10);
        getContentPane().add(jLabel2, gridBagConstraints);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(jFrameGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(jFrameGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(jFrameGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(jFrameGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new jFrameGUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    // End of variables declaration//GEN-END:variables
}

En línea

Zoik

Desconectado Desconectado

Mensajes: 91


Ver Perfil
Re: Bloquear pantalla
« Respuesta #4 en: 8 Septiembre 2013, 00:03 am »

Me interese por el asunto, así que me puse manos a la obra y a salido esto:

Código
  1. /*
  2.  * Autor: Zoik
  3.  */
  4. package base;
  5.  
  6. import graphics.Gui;
  7.  
  8. public class Main {
  9.  
  10. public static void main(String[] args) {
  11. java.awt.EventQueue.invokeLater(new Runnable() {
  12.            public void run() {
  13.                new Gui();
  14.            }
  15.        });
  16.  
  17. }
  18.  
  19. }

Código
  1. /*
  2.  * Autor: Zoik
  3.  */
  4. package graphics;
  5.  
  6. import java.awt.Component;
  7. import java.awt.Container;
  8. import java.awt.Dimension;
  9. import java.awt.GridBagConstraints;
  10. import java.awt.GridBagLayout;
  11. import java.awt.Insets;
  12. import java.awt.event.ActionEvent;
  13. import java.awt.event.ActionListener;
  14.  
  15. import javax.swing.JButton;
  16. import javax.swing.JFrame;
  17. import javax.swing.JInternalFrame;
  18. import javax.swing.JLabel;
  19. import javax.swing.JPanel;
  20. import javax.swing.JPasswordField;
  21. import javax.swing.JTextField;
  22.  
  23. import base.Block;
  24.  
  25. public class Gui extends JFrame implements ActionListener{
  26.  
  27. private static final long serialVersionUID = 1L;
  28. private final String backgroundURL = "src/images/background.jpg";
  29. private final String loginTitle = "Login";
  30. private final String userLabelText = "User:";
  31. private final String passLabelText = "Password:";
  32. private final String loginButtonLabelText = "Login";
  33. private final String cancelButtonLabelText = "Cancel";
  34.  
  35. private final String user = "user";
  36. private final String pass = "1234";
  37.  
  38. private ImageDesktopPane desktopBackground;
  39. private JInternalFrame internalFrameLogin;
  40. private JPanel panelLogin;
  41. private JLabel userLabel;
  42. private JLabel passwordLabel;
  43. private JTextField userTextField;
  44. private JPasswordField passwordTextField;
  45. private JButton loginButton;
  46. private JButton cancelButton;
  47. private Block thread;
  48.  
  49. public Gui(){
  50. initFrame();
  51. }
  52.  
  53.  
  54. public void initFrame(){
  55. setUndecorated(true);
  56.        setDefaultCloseOperation( DO_NOTHING_ON_CLOSE  );
  57.        setExtendedState( MAXIMIZED_BOTH );
  58.        setAlwaysOnTop(true);
  59.        new Block(this);
  60.        initBackground();
  61. initInternalFrame();
  62.        setVisible(true);
  63. }
  64.  
  65. public void initBackground(){
  66. desktopBackground = new ImageDesktopPane(backgroundURL);
  67. desktopBackground.setLayout(new GridBagLayout());
  68. add(desktopBackground);
  69. }
  70.  
  71. public void initInternalFrame(){
  72. internalFrameLogin = new JInternalFrame(loginTitle);
  73. internalFrameLogin.setPreferredSize(new Dimension(300, 200));
  74. desktopBackground.add(internalFrameLogin);
  75. internalFrameLogin.setVisible(true);
  76. initLoginPanel();
  77. }
  78.  
  79. public void initLoginPanel(){
  80. panelLogin = new JPanel();
  81. panelLogin.setLayout(new GridBagLayout());
  82. internalFrameLogin.add(panelLogin);
  83. initLabels();
  84. initTextFields();
  85. initButtons();
  86. }
  87.  
  88. public void initLabels(){
  89. userLabel = new JLabel(userLabelText);
  90. passwordLabel = new JLabel(passLabelText);
  91. addComponentGBL(panelLogin,userLabel,0,0,1,1,GridBagConstraints.WEST, GridBagConstraints.NONE, 10, 75, 0, 0);
  92. addComponentGBL(panelLogin,passwordLabel,0,1,1,1,GridBagConstraints.WEST, GridBagConstraints.NONE, 10, 45, 70, 0);
  93. }
  94.  
  95. public void initTextFields(){
  96. userTextField = new JTextField();
  97. passwordTextField = new JPasswordField();
  98. userTextField.setPreferredSize(new Dimension(90,30));
  99. passwordTextField.setPreferredSize(new Dimension(90,30));
  100. addComponentGBL(panelLogin,userTextField,1,0,1,1,GridBagConstraints.EAST, GridBagConstraints.NONE, 10, 0, 0, 65);
  101. addComponentGBL(panelLogin,passwordTextField,1,1,1,1,GridBagConstraints.EAST, GridBagConstraints.NONE, 10, 0, 70, 65);
  102. userTextField.setFocusable(true);
  103. }
  104.  
  105. public void initButtons(){
  106. loginButton = new JButton(loginButtonLabelText);
  107. cancelButton = new JButton(cancelButtonLabelText);
  108. loginButton.addActionListener(this);
  109. cancelButton.addActionListener(this);
  110. addComponentGBL(panelLogin,loginButton,0,1,1,1,GridBagConstraints.CENTER, GridBagConstraints.NONE, 30, 70, 0, 0);
  111. addComponentGBL(panelLogin,cancelButton,1,1,1,1,GridBagConstraints.CENTER, GridBagConstraints.NONE, 30, 0, 0, 40);
  112. }
  113.  
  114. public void addComponentGBL(Container container, Component component, int gridx, int gridy, int gridwidth, int gridheight, int anchor, int fill, int inset1, int inset2, int inset3, int inset4) {
  115. Insets insets = new Insets(inset1, inset2, inset3, inset4);
  116. GridBagConstraints gbc = new GridBagConstraints(gridx, gridy, gridwidth, gridheight, 1.0, 1.0, anchor, fill, insets, 0, 0);
  117.    container.add(component, gbc);
  118.  }
  119.  
  120.  
  121. public void actionPerformed(ActionEvent e) {
  122. if(e.getSource() == loginButton) {
  123. if(userTextField.getText().equals(user) && passwordTextField.getText().equals(pass)){
  124. dispose();
  125. }
  126. } else if(e.getSource() == cancelButton) {
  127. dispose();
  128. }
  129. }
  130.  
  131. }
  132.  

Código
  1. /*
  2.  * Autor: Zoik
  3.  */
  4. package graphics;
  5.  
  6. import java.awt.Graphics;
  7. import java.awt.image.BufferedImage;
  8. import java.io.File;
  9. import java.io.IOException;
  10.  
  11. import javax.imageio.ImageIO;
  12. import javax.swing.JDesktopPane;
  13.  
  14. public class ImageDesktopPane extends JDesktopPane{
  15.  
  16. private static final long serialVersionUID = 1L;
  17. private BufferedImage image;
  18.  
  19.    public ImageDesktopPane(String path) {
  20.       try {                
  21.          image = ImageIO.read(new File(path));
  22.       } catch (IOException ex) {
  23.            System.out.println("Error al cargar la imagen de fondo");
  24.       }
  25.    }
  26.  
  27.    @Override
  28.    protected void paintComponent(Graphics g) {
  29.        super.paintComponent(g);
  30.        g.drawImage(image, 0, 0, getWidth(), getHeight(), this);          
  31.    }
  32.  
  33. }

Código
  1. /*
  2.  * Autor: Zoik
  3.  */
  4. package base;
  5.  
  6. import java.util.concurrent.Executors;
  7. import java.util.concurrent.ScheduledExecutorService;
  8. import java.util.concurrent.TimeUnit;
  9.  
  10. import javax.swing.JFrame;
  11.  
  12. import graphics.Gui;
  13.  
  14. public class Block{
  15.  
  16. private Gui frame;
  17.  
  18. public Block(Gui gui){
  19. frame = gui;
  20. ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
  21.        scheduler.scheduleAtFixedRate(
  22.            new Runnable()
  23.            {
  24.                public void run() {                  
  25.                    front();
  26.                }
  27.              }, 500, 50 , TimeUnit.MILLISECONDS );
  28. }
  29.  
  30. public void front(){
  31. frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
  32. frame.toFront();
  33. }
  34.  
  35. }
  36.  
  37.  

Un saludo y espero te sirva.
« Última modificación: 9 Septiembre 2013, 17:44 pm por Zoik » En línea

Mine Sweeper

Desconectado Desconectado

Mensajes: 29


Ver Perfil
Re: Bloquear pantalla
« Respuesta #5 en: 9 Septiembre 2013, 14:50 pm »

El codigo es parecido al que puse, pero tiene una pequeña falla de seguridad.
En windows 7 si presionas Windows + tab te deja desplazarte entre las ventanas y aunque regreses a la ventana del programa presionas windows+r y escribes cmd y si te abre la consola aunque no mires lo que haces y ahi se puede finalizar el proceso.
Esa es la falla mas importante que tiene, la otra es que si tengo dos monitores, con pasar el administrador de tareas al segundo monitor puedo finalizar el programa.
En línea

Zoik

Desconectado Desconectado

Mensajes: 91


Ver Perfil
Re: Bloquear pantalla
« Respuesta #6 en: 9 Septiembre 2013, 16:08 pm »

Cierto, e estado probando el que pasaste y también le sucede lo mismo, trastearé un poco con los focus a ver si logro solucionarlo.

Un saludo.

EDITO: Como medida provisional para el taskmgr y el cmd, aunque un poco chapucera, sustituye el método front() por este:

Código
  1. public void front(){
  2. frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
  3. frame.toFront();
  4. String osName = System.getProperty("os.name");
  5. if(osName.toUpperCase().contains("WIN")){
  6. try {
  7. Runtime.getRuntime().exec("tskill cmd");
  8. Runtime.getRuntime().exec("tskill taskmgr");
  9. } catch (IOException e) {
  10. e.printStackTrace();
  11. }
  12. }
  13. }
« Última modificación: 9 Septiembre 2013, 16:42 pm por Zoik » En línea

Mine Sweeper

Desconectado Desconectado

Mensajes: 29


Ver Perfil
Re: Bloquear pantalla
« Respuesta #7 en: 9 Septiembre 2013, 17:09 pm »

Puede ser algo provisional o chapusera como dices tu, pero es una alternativa al problema =P
Para esto hay que tener ingenio y la verdad eso nunca se me ocurrio xD
pero soluciona el problema que teniamos que es lo importante jajaja
En línea

Mine Sweeper

Desconectado Desconectado

Mensajes: 29


Ver Perfil
Re: Bloquear pantalla
« Respuesta #8 en: 9 Septiembre 2013, 17:40 pm »

Me pasa algo raro, lo corro en el Eclipse y funciona a la perfeccion, una vez que acaba  que cierro el programa ya no puedo volver a abrir la consola y ni el task manager, pero ese no es el problema, lo que note, es que si lo hago jar y lo ejecuto, si me permite abrir la consola
En línea

Zoik

Desconectado Desconectado

Mensajes: 91


Ver Perfil
Re: Bloquear pantalla
« Respuesta #9 en: 9 Septiembre 2013, 17:40 pm »

He observado que el schedule se queda abierto cuando finalizas la aplicación, por tanto aunque la cierres seguiras sin poder abrir el cmd y el taskmgr.

Por tanto e vuelto a retocar toda la aplicación y quedaría así:

Código
  1. /*
  2.  * Autor: Zoik
  3.  */
  4. package base;
  5.  
  6. import graphics.Gui;
  7.  
  8. public class Main {
  9.  
  10. public static void main(String[] args) {
  11. java.awt.EventQueue.invokeLater(new Runnable() {
  12.            public void run() {
  13.                new Gui();
  14.            }
  15.        });
  16.  
  17. }
  18.  
  19. }
  20.  

Código
  1. /*
  2.  * Autor: Zoik
  3.  */
  4. package graphics;
  5.  
  6. import java.awt.Component;
  7. import java.awt.Container;
  8. import java.awt.Dimension;
  9. import java.awt.GridBagConstraints;
  10. import java.awt.GridBagLayout;
  11. import java.awt.Insets;
  12. import java.awt.event.ActionEvent;
  13. import java.awt.event.ActionListener;
  14.  
  15. import javax.swing.JButton;
  16. import javax.swing.JFrame;
  17. import javax.swing.JInternalFrame;
  18. import javax.swing.JLabel;
  19. import javax.swing.JPanel;
  20. import javax.swing.JPasswordField;
  21. import javax.swing.JTextField;
  22.  
  23. import base.Block;
  24.  
  25. public class Gui extends JFrame implements ActionListener{
  26.  
  27. private static final long serialVersionUID = 1L;
  28. private final String backgroundURL = "src/images/background.jpg";
  29. private final String loginTitle = "Login";
  30. private final String userLabelText = "User:";
  31. private final String passLabelText = "Password:";
  32. private final String loginButtonLabelText = "Login";
  33. private final String cancelButtonLabelText = "Cancel";
  34.  
  35. private final String user = "user";
  36. private final String pass = "1234";
  37.  
  38. private ImageDesktopPane desktopBackground;
  39. private JInternalFrame internalFrameLogin;
  40. private JPanel panelLogin;
  41. private JLabel userLabel;
  42. private JLabel passwordLabel;
  43. private JTextField userTextField;
  44. private JPasswordField passwordTextField;
  45. private JButton loginButton;
  46. private JButton cancelButton;
  47. private Block thread;
  48.  
  49. public Gui(){
  50. initFrame();
  51. }
  52.  
  53.  
  54. public void initFrame(){
  55. setUndecorated(true);
  56. setDefaultCloseOperation( DO_NOTHING_ON_CLOSE  );
  57. setExtendedState( MAXIMIZED_BOTH );
  58. setAlwaysOnTop(true);
  59. thread = new Block(this);
  60. thread.start();
  61. initBackground();
  62. initInternalFrame();
  63. setVisible(true);
  64. }
  65.  
  66. public void initBackground(){
  67. desktopBackground = new ImageDesktopPane(backgroundURL);
  68. desktopBackground.setLayout(new GridBagLayout());
  69. add(desktopBackground);
  70. }
  71.  
  72. public void initInternalFrame(){
  73. internalFrameLogin = new JInternalFrame(loginTitle);
  74. internalFrameLogin.setPreferredSize(new Dimension(300, 200));
  75. desktopBackground.add(internalFrameLogin);
  76. internalFrameLogin.setVisible(true);
  77. initLoginPanel();
  78. }
  79.  
  80. public void initLoginPanel(){
  81. panelLogin = new JPanel();
  82. panelLogin.setLayout(new GridBagLayout());
  83. internalFrameLogin.add(panelLogin);
  84. initLabels();
  85. initTextFields();
  86. initButtons();
  87. }
  88.  
  89. public void initLabels(){
  90. userLabel = new JLabel(userLabelText);
  91. passwordLabel = new JLabel(passLabelText);
  92. addComponentGBL(panelLogin,userLabel,0,0,1,1,GridBagConstraints.WEST, GridBagConstraints.NONE, 10, 75, 0, 0);
  93. addComponentGBL(panelLogin,passwordLabel,0,1,1,1,GridBagConstraints.WEST, GridBagConstraints.NONE, 10, 45, 70, 0);
  94. }
  95.  
  96. public void initTextFields(){
  97. userTextField = new JTextField();
  98. passwordTextField = new JPasswordField();
  99. userTextField.setPreferredSize(new Dimension(90,30));
  100. passwordTextField.setPreferredSize(new Dimension(90,30));
  101. addComponentGBL(panelLogin,userTextField,1,0,1,1,GridBagConstraints.EAST, GridBagConstraints.NONE, 10, 0, 0, 65);
  102. addComponentGBL(panelLogin,passwordTextField,1,1,1,1,GridBagConstraints.EAST, GridBagConstraints.NONE, 10, 0, 70, 65);
  103. userTextField.setFocusable(true);
  104. }
  105.  
  106. public void initButtons(){
  107. loginButton = new JButton(loginButtonLabelText);
  108. cancelButton = new JButton(cancelButtonLabelText);
  109. loginButton.addActionListener(this);
  110. cancelButton.addActionListener(this);
  111. addComponentGBL(panelLogin,loginButton,0,1,1,1,GridBagConstraints.CENTER, GridBagConstraints.NONE, 30, 70, 0, 0);
  112. addComponentGBL(panelLogin,cancelButton,1,1,1,1,GridBagConstraints.CENTER, GridBagConstraints.NONE, 30, 0, 0, 40);
  113. }
  114.  
  115. public void addComponentGBL(Container container, Component component, int gridx, int gridy, int gridwidth, int gridheight, int anchor, int fill, int inset1, int inset2, int inset3, int inset4) {
  116. Insets insets = new Insets(inset1, inset2, inset3, inset4);
  117. GridBagConstraints gbc = new GridBagConstraints(gridx, gridy, gridwidth, gridheight, 1.0, 1.0, anchor, fill, insets, 0, 0);
  118. container.add(component, gbc);
  119. }
  120.  
  121.  
  122. public void actionPerformed(ActionEvent e) {
  123. if(e.getSource() == loginButton) {
  124. if(userTextField.getText().equals(user) && passwordTextField.getText().equals(pass)){
  125. thread.stopThread();
  126. dispose();
  127. }
  128. } else if(e.getSource() == cancelButton) {
  129. thread.stopThread();
  130. dispose();
  131. }
  132. }
  133.  
  134. }
  135.  

Código
  1. /*
  2.  * Autor: Zoik
  3.  */
  4. package graphics;
  5.  
  6. import java.awt.Graphics;
  7. import java.awt.image.BufferedImage;
  8. import java.io.File;
  9. import java.io.IOException;
  10.  
  11. import javax.imageio.ImageIO;
  12. import javax.swing.JDesktopPane;
  13.  
  14. public class ImageDesktopPane extends JDesktopPane{
  15.  
  16. private static final long serialVersionUID = 1L;
  17. private BufferedImage image;
  18.  
  19. public ImageDesktopPane(String path) {
  20. try {                
  21. image = ImageIO.read(new File(path));
  22. } catch (IOException ex) {
  23. System.out.println("Error al cargar la imagen de fondo");
  24. }
  25. }
  26.  
  27. @Override
  28. protected void paintComponent(Graphics g) {
  29. super.paintComponent(g);
  30. g.drawImage(image, 0, 0, getWidth(), getHeight(), this);          
  31. }
  32.  
  33. }

Código
  1. /*
  2.  * Autor: Zoik
  3.  */
  4. package base;
  5.  
  6. import java.io.IOException;
  7. import javax.swing.JFrame;
  8.  
  9. import graphics.Gui;
  10.  
  11. public class Block extends Thread{
  12.  
  13. private Gui frame;
  14. private final String osName = System.getProperty("os.name");
  15. private boolean running = false;
  16.  
  17. public Block(Gui gui){
  18. frame = gui;
  19. }
  20.  
  21. public void run(){
  22. running = true;
  23. while(running == true){
  24. front();
  25. try {
  26. Thread.sleep(100);
  27. } catch (InterruptedException e) {
  28. e.printStackTrace();
  29. }
  30. }
  31. }
  32.  
  33. public void stopThread(){
  34. running = false;
  35. }
  36.  
  37. public void front(){
  38. frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
  39. frame.toFront();
  40. if(osName.toUpperCase().contains("WIN")){
  41. try {
  42. Runtime.getRuntime().exec("tskill cmd");
  43. Runtime.getRuntime().exec("tskill taskmgr");
  44. } catch (IOException e) {
  45. e.printStackTrace();
  46. }
  47. }
  48. }
  49.  
  50. }
  51.  

Antes de nada reiniciar el PC, porque el schedule sigue abierto y no puedes matarlo...

Un saludo.
« Última modificación: 9 Septiembre 2013, 17:47 pm por Zoik » En línea

Páginas: [1] 2 Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
(Solucionado)Progrma bloquear pantalla con pass en Windows
Software
chaos_override 5 2,172 Último mensaje 19 Octubre 2011, 00:59 am
por chaos_override
entrar en BIOS con pantalla externa (netbook pantalla rota)
Hardware
soko68 4 31,233 Último mensaje 23 Septiembre 2013, 08:28 am
por Peseck
Se cierra la sesión al bloquear pantalla
GNU/Linux
WHK 1 1,922 Último mensaje 18 Mayo 2015, 20:57 pm
por MinusFour
Bloquear Pantalla parecido a TeamViewer [Python]
Programación General
Mathew 0 2,514 Último mensaje 19 Septiembre 2021, 19:25 pm
por Mathew
bloquear pantalla?
Dudas Generales
inma55 2 2,918 Último mensaje 19 Septiembre 2023, 09:44 am
por inma55
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines