|
-
December 26th, 2007, 08:15 PM
#1
can anyone tell me what is wrong with this code!!
the compiler does not find any errors but the window doesnt appears when i execute the code.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class BankTEST extends JFrame {
public BankTEST() {
super("a");
Container logincontainer=getContentPane();
logincontainer.setLayout( new FlowLayout() );
JLabel Username=new JLabel("username");
JLabel Password=new JLabel("password");
JTextField UsernameText=new JTextField(10);
JTextField PasswordText=new JPasswordField(10);
JButton Login=new JButton("LOGIN");
logincontainer.add(Username);
logincontainer.add(Password);
logincontainer.add(UsernameText);
logincontainer.add(PasswordText);
logincontainer.setSize( 500, 170 );
logincontainer.setVisible(true);
}
public static void main(String args[]){
BankTEST b=new BankTEST();
b.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE );
}
}
-
December 26th, 2007, 08:24 PM
#2
Re: can anyone tell me what is wrong with this code!!
It looks like you are setting the content panel to visible, not the frame itself.
Changing the main method like below fixed the problem for me:
Code:
public static void main(String args[]) {
BankTEST b = new BankTEST();
b.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b.pack(); // resize to fit preferred size of subcomponents
b.setVisible(true); // show the frame
}
Last edited by remkop; December 27th, 2007 at 01:09 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|