problems getting 2 classes working together
hello.
this is james mcfadden. i am currently developing a video library system in Java. it involves developing a video library menu. the video library menu is supposed to consist of an administrator's section, a new user's section and an existing user's section. i am using JTabbedPane to navigate between the 3 sections of the menu. the following program compiles but it does not run the way i expect it to. when i run the program, the frame with the tabbed pane stuff is displayed on screen, but when i press any of the 2 Log On buttons the logon dialog box called "Welcome to Home Entertainment" doesn't display on screen. how can i solve this problem?
thanks.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
publicclass VideoLibrarySystemextends JPanelimplements ActionListener{
private JTabbedPane jtp =new JTabbedPane();
private JPanel cP1 =new JPanel();
private JPanel cP2 =new JPanel();
private JPanel cP3 =new JPanel();
private JPanel bP1 =new JPanel();
private JPanel bP2 =new JPanel();
private JPanel bP3 =new JPanel();
private JButton jbAdministratorLogOn =new JButton("Log On");
private JButton jbNewUserRegister =new JButton("Register");
private JButton jbExistingUserLogOn =new JButton("Log On");
public VideoLibrarySystem(){
cP1.setLayout(new BorderLayout());
cP2.setLayout(new BorderLayout());
cP3.setLayout(new BorderLayout());
bP1.setBorder(new TitledBorder("Make a choice"));
bP2.setBorder(new TitledBorder("Make a choice"));
bP3.setBorder(new TitledBorder("Make a choice"));
bP1.add(jbAdministratorLogOn);
bP2.add(jbNewUserRegister);
bP3.add(jbExistingUserLogOn);
cP1.add(bP1, BorderLayout.SOUTH);
cP2.add(bP2, BorderLayout.SOUTH);
cP3.add(bP3, BorderLayout.SOUTH);
jtp.addTab("Administrator", cP1);
jtp.addTab("New User", cP2);
jtp.addTab("Existing User", cP3);
JFrame jf =new JFrame("Video Library System");
jf.addWindowListener(new WindowAdapter(){
publicvoid windowClosing(WindowEvent e){
System.exit(0);
}
});
jf.getContentPane().add(jtp, BorderLayout.CENTER);
jf.setSize(500, 300);
jf.setVisible(true);
jbAdministratorLogOn.addActionListener(this);
jbNewUserRegister.addActionListener(this);
jbExistingUserLogOn.addActionListener(this);
}
publicvoid actionPerformed(ActionEvent e){
if(e.getSource() == jbAdministratorLogOn){
LogOn logon =new LogOn();
}
if(e.getSource() == jbNewUserRegister){
//RegistrationForm registration = new RegistrationForm();
//registration.getInput();
//registration.setVisible(true);
}
if(e.getSource() == jbExistingUserLogOn){
LogOn logon =new LogOn();
}
}
publicstaticvoid main(String[] args){
new VideoLibrarySystem();
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
publicclass LogOn{
publicstaticvoid main(String[] args){
new LogOnInfoDialog().setVisible(true);
}
}
class LogOnInfoDialogextends JDialog{
private JTextField jtfUN =new JTextField(20);
private JPasswordField jtfPW =new JPasswordField(20);
private JButton jbOK =new JButton("OK");
private JButton jbCancel =new JButton("Cancel");
private LogOn logOn =new LogOn();
class LogOn{
String username;
String password;
}
public LogOnInfoDialog(){
this(null,true);
}
public LogOnInfoDialog(java.awt.Frame parent,boolean child){
super(parent, child);
setTitle("Welcome to Home Entertainment");
// Group two labels
JPanel jp1 =new JPanel(new GridLayout(2, 1));
jp1.add(new JLabel("Username"));
jp1.add(new JLabel("Password"));
// Group two text fields
JPanel jp2 =new JPanel(new GridLayout(2, 1));
jp2.add(jtfUN);
jp2.add(jtfPW);
// Group jpLabels and jpTextFields
JPanel jp3 =new JPanel(new BorderLayout(5, 2));
jp3.add(jp1, BorderLayout.WEST);
jp3.add(jp2, BorderLayout.CENTER);
JPanel jp4 =new JPanel();
jp4.add(jbOK);
jp4.add(jbCancel);
getContentPane().add(jp4, BorderLayout.SOUTH);
getContentPane().add(jp3, BorderLayout.CENTER);
jbOK.addActionListener(new ActionListener(){
publicvoid actionPerformed(ActionEvent e){
logOn.username = jtfUN.getText().trim();
logOn.password =new String(jtfPW.getPassword());
setVisible(false);
}
});
jbCancel.addActionListener(new ActionListener(){
publicvoid actionPerformed(ActionEvent e){
logOn =null;
setVisible(false);
}
});
}
}

