Problem using a JButton object(s)

hello.

Im having difficulty trying to display 2 buttons inside a TitledBorder within a tab. when i run the following program, the Exit the system button is only displayed in the Existing User tab. the Exit the system button is supposed to appear in 3 tabs and not one. the variable names for the jbExistingUserLogOn and jbExitTheSystem objects are almost identical. should i change the variable name of the jbExitTheSystem object from jbExitTheSystem to jbQuit? or do I have to create a separate tab that would allow the user to exit the system?

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.border.*;

publicclass HomeEntertainmentextends 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");

private JButton jbExitTheSystem =new JButton("Exit the system");

public HomeEntertainment(){

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);

bP1.add(jbExitTheSystem);

bP2.add(jbExitTheSystem);

bP3.add(jbExitTheSystem);

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("Home Entertainment");

jf.getContentPane().add(jtp, BorderLayout.CENTER);

jf.setSize(500, 500);

jf.setVisible(true);

jbAdministratorLogOn.addActionListener(this);

jbNewUserRegister.addActionListener(this);

jbExistingUserLogOn.addActionListener(this);

jbExitTheSystem.addActionListener(this);

}//end constructor

publicvoid actionPerformed(ActionEvent e){

if(e.getSource() == jbAdministratorLogOn){

/*

LogOn logOn = new LogOn();

logOn.setVisible(true);

*/

}

if(e.getSource() == jbNewUserRegister){

/*

RegistrationForm r = new RegistrationForm();

r.setVisible(true);

*/

}

if(e.getSource() == jbExistingUserLogOn){

/*

LogOn logOn = new LogOn();

logOn.setVisible(true);

*/

}

if(e.getSource() == jbExitTheSystem){

System.exit(0);

}

}

publicstaticvoid main(String[] args){

new HomeEntertainment();

}//end main()

}//end class

[5794 byte] By [james-mcfaddena] at [2007-11-27 10:48:57]
# 1

Swing related questions should be posted in the Swing forum.

A component can only be added to a single parent. You can't add the same button to 3 panels. You need to create 3 separate buttons.

camickra at 2007-7-29 11:16:05 > top of Java-index,Java Essentials,Java Programming...