1

I want a fullcreen window where I can type a login and a password and then get the login and pass from the textFields. When I run this code in eclipse, the login textfield and the pass textfield are unable to type in. This is the code:

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

public class MostrarBloqueio extends JFrame implements ActionListener
{ 
    private static GraphicsDevice graphicsDevice1;
    private DisplayMode minDisplayMode; 
    private JButton loginButton = new JButton( "login"); 
    private JTextField txtLogin;
    private JPasswordField passwordField;

    public static void main(String[] args)
    { //Get and display a list of graphics devices solely for // information purposes. 
        GraphicsEnvironment graphicsEnvironment =  GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[] devices = graphicsEnvironment.getScreenDevices(); 
        for(int cnt = 0;cnt < 1;cnt++)
        {
            System.out.println(devices[cnt]); 

        }//end for loop
    //Construct a full-screen object //
        new MostrarBloqueio(devices[0]);
    }//end main



//Constructor 
    public MostrarBloqueio(GraphicsDevice graphicsDevice)
    { 
        //Save a reference to the graphics device as an // instance variable so that it can be used later to // exit the full-screen mode.  

        this.graphicsDevice1 = graphicsDevice; 
        setTitle("This title will be hidden (undecorated)"); //Get and save a reference to the original display // mode as an instance variable so that it can be // restored later.  
        minDisplayMode = graphicsDevice.getDisplayMode(); 
        loginButton.setBounds(633, 518, 103, 23);

            //Register an action listener on the loginButton.  
        loginButton.addActionListener(this);  
        getContentPane().setLayout(null);

        passwordField = new JPasswordField();
        passwordField.setBounds(633, 475, 142, 20);
        getContentPane().add(passwordField);
        passwordField.setColumns(10);

            //Place the loginButton in the JFrame
        getContentPane().add(loginButton);
        getContentPane().setBackground(getBackground());

        JLabel lblNewLabel = new JLabel("senha:");
        lblNewLabel.setBounds(578, 478, 45, 14);
        getContentPane().add(lblNewLabel);

        JLabel lblLogin = new JLabel("Login:");
        lblLogin.setBounds(578, 456, 45, 14);
        getContentPane().add(lblLogin);

        txtLogin = new JTextField();
        txtLogin.setBounds(633, 453, 142, 20);
        getContentPane().add(txtLogin);
        txtLogin.setColumns(10);        

        if (graphicsDevice.isFullScreenSupported())
        { 
            // Enter full-screen mode witn an undecorated, // non-resizable JFrame object.  
            setUndecorated(true); 
            setResizable(false);  
            setAlwaysOnTop(true);
            setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
            graphicsDevice.setFullScreenWindow(this);
            AltTabStopper at = new AltTabStopper(this);
            at.create(this);
            validate();

        }
        else
        { 
            System.out.println("Full-screen mode not supported");
        }//end else 
    }//end constructor 

    //The following method is invoked when the used clicks // the loginButton 
    public void actionPerformed(ActionEvent evt)
    {
        //Restore the original display mode 
        String login = txtLogin.getText();
        System.out.println("1"+login);
        graphicsDevice1.setDisplayMode(minDisplayMode); 
        //Terminate the program 
        System.exit(0);
    }
}//end class
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • your code works... what is `AltTabStopper at = new AltTabStopper(this); at.create(this);` – Khinsu Sep 04 '13 at 19:18
  • a solution from here http://stackoverflow.com/questions/6127709/remove-the-possibility-of-using-alt-f4-and-alt-tab-in-java-gui to disable switch windows using alt+tab – Cledson Oliveira Sep 04 '13 at 19:25
  • I launched it and it did have a problem with, apparently, JTextField loosing focus right after clicking on it. – Rekin Sep 04 '13 at 20:25
  • Disabling AltTabStopper helped. – Rekin Sep 04 '13 at 20:26
  • I played a little bit and see it might not be possible to have the AltTabStopper work reliably. – Rekin Sep 04 '13 at 20:46
  • Here the low-level options are discussed - seems impossible even with the native Windows calls: http://www.windowsnetworking.com/kbase/WindowsTips/WindowsNT/AdminTips/Miscellaneous/DisableAltTab.html – Rekin Sep 04 '13 at 20:51
  • Java GUIs might have to work on a number of platforms, on different screen resolutions & using different PLAFs. As such they are not conducive to exact placement of components. To organize the components for a robust GUI, instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556), along with layout padding & borders for [white space](http://stackoverflow.com/q/17874717/418556). – Andrew Thompson Sep 05 '13 at 00:08
  • For better help sooner, post an [SSCCE](http://sscce.org/). BTW - I tried compiling the code supplied - it fails due to the missing `AltTabStopper` (which sounds quite malevolent). After commenting out all references to it and getting a clean compilation, I tried running it 3 times and could **access the text field without problem, every time.** That suggests to me that the ***real problem is in the missing code.*** – Andrew Thompson Sep 05 '13 at 00:14
  • thank you everybody for the the replies, as Rekin said, the problem it's all about focus.i'll find another way to disable the "alt tab" switching. – Cledson Oliveira Sep 05 '13 at 16:39

1 Answers1

0

call txtLogin.setEditable(true) and passwordField.setEditable(true)

Big Al
  • 980
  • 1
  • 8
  • 20