swing help

hey,
i am creating an instant messenger .... for making the GUI i am using the following code ...

[code]
public class GUIHandler {

private JFrame frame = null;

public GUIHandler() {
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(new Dimension(160,340));
JFrame.setDefaultLookAndFeelDecorated(true);
frame.setTitle("Yahoo!!");
initMenu();
initFrame();
frame.show();
}

private void initMenu(){
JMenu loginMenu = new JMenu("Login");
JMenuItem loginItem = new JMenuItem("Login..", KeyEvent.VK_L);
loginItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1,
ActionEvent.ALT_MASK));
loginMenu.add(loginItem);
/*loginItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent action){
SwingUtilities.invokeLater(new Runnable(){
public void run(){
showLoginBox();
}
});*/
loginItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent action){
SwingUtilities.invokeLater(new Runnable(){
public void run(){
showLoginBox();
}
});
}
});
JMenuBar menuBar = new JMenuBar();
menuBar.add(loginMenu);
frame.setJMenuBar(menuBar);
}

private void showLoginBox(){

JPanel outerPanel1 = new JPanel();
Border paneEdge = BorderFactory.createEmptyBorder(0,10,10,10);
outerPanel1.setBorder(paneEdge);
outerPanel1.setLayout(new BoxLayout(outerPanel1, BoxLayout.Y_AXIS));

JPanel newUserPanel = new JPanel();

JButton registerButton = new JButton("Register");
registerButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent action){
registerNewUser();
}
});

TitledBorder titled;
titled = BorderFactory.createTitledBorder("NewUser?");

/* newUserPanel.setSize(new Dimension(100,80));*/
newUserPanel.setLayout(new BoxLayout(newUserPanel, BoxLayout.Y_AXIS));
newUserPanel.setBorder(titled);

JPanel panel = new JPanel();
/*panel.setSize(new Dimension(100,80));*/
panel.add(registerButton);
newUserPanel.add(panel);

/*JPanel existingUserPanel = new JPanel();
existingUserPanel.setName("Existing User?");
TitledBorder existingUserTitle;
existingUserTitle = BorderFactory.createTitledBorder("title");

existingUserPanel.setLayout(new BoxLayout(newUserPanel, BoxLayout.Y_AXIS));
existingUserPanel.setBorder(existingUserTitle);

final JTextField name = new JTextField();
final JTextField password = new JTextField();
JButton login = new JButton("Login");
login.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent action){
onLogin(name.getText(), password.getText());
}
});
existingUserPanel.add(name);
existingUserPanel.add(password);
existingUserPanel.add(login);
*/
outerPanel1.add(Box.createRigidArea(new Dimension(0, 10)));
outerPanel1.add(newUserPanel);

/*JPanel outermostPane = new JPanel();
outermostPane.setLayout(new BoxLayout(outermostPane, BoxLayout.Y_AXIS));
outermostPane.add(outerPanel1);
outermostPane.add(existingUserPanel);*/

JFrame loginFrame = new JFrame("Login");
try {
UIManager.setLookAndFeel(
UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception e) { }

//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
loginFrame.setContentPane(outerPanel1);
loginFrame.setSize(new Dimension(150,200));
loginFrame.setFocusable(true);
JWindow window = new JWindow(loginFrame);
loginFrame.show();

}

private static void registerNewUser(){

}
private void onLogin(String name, String password){

}
private void initFrame(){

}
}
[/code]

The login window which i get on clicking the menu from the menubar is java style window although i have tried setting the defaultLookAndFeel of the login JFrame to true....
Any help??

Mark
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories