|
|
本帖最后由 mengchai0701 于 7-11-2011 03:05 PM 编辑
[url=http://www.facebook.com/photo.php?fbid=10150530034603662&l=6d5d79bd4a]print screen of my software when click on the "NEW" button for 2 time[/url]
i having problem in java se , i am develop a project using eclipse recently . When i call a method JPanel (); to add in anothe rJFrame , all the JComponent i setBounds all run out , but when i click on the button again , it on bounds again , can sumbody help me to solve it , thx q . below i attached with my source code.
public class NewCustomer implements ActionListener{
private String ageRange[] = {"Please select age range","10-20","21-30","31-40","41-50","51-60","61-70","71-80","81-90"};
private JLabel lblTitle,lblFirstName,lblLastName,lblContact, lblAddress, lblGender, lblAge, lblEmail, lblBirthday,lblRace,lblTransactionID,lblImages;
private JTextField txtFirstname , txtLastName , txtContact , txtAddress , txtGender , txtAge , txtEmail , txtBirthday,txtRace,txtTransactionID,txtImages;
private JRadioButton male = new JRadioButton("Male",false), female = new JRadioButton("Female", false);
private JRadioButton Chinese = new JRadioButton("Chinese",false), Malay = new JRadioButton("Malay", false),Indian = new JRadioButton("Indian", false),Others = new JRadioButton("Others", false);
private ButtonGroup Gender = new ButtonGroup();
private ButtonGroup Race = new ButtonGroup();
private JButton Save = new JButton(), Cancel = new JButton() , Clear = new JButton(), Choose = new JButton() , Show = new JButton();
private JPanel panel = new JPanel();
private JFileChooser fileChooser = new JFileChooser();
private JComboBox comboBox = new JComboBox();
JPanel getNewPanel() {
panel.removeAll();
panel.setBackground(Color.WHITE);
panel.setBounds(10, 80, 680, 450);
Font f = new Font("SansSerif", Font.BOLD, 18);
lblTitle = new JLabel("PLEASE FILL IN CUSTOMER DETAIL :");
lblTitle.setFont(f);
lblTitle.setBounds(10, 10, 1000, 20);
lblFirstName = new JLabel("*First Name ");
lblFirstName.setBounds(10, 40, 80, 20);
txtFirstname = new JTextField(15);
txtFirstname.setBounds(120, 40, 200, 20);
lblLastName = new JLabel(" Last Name ");
lblLastName.setBounds(360, 40, 80, 20);
txtLastName = new JTextField(15);
txtLastName.setBounds(440, 40, 200, 20);
lblAge = new JLabel(" Age ");
lblAge.setBounds(10, 60, 80, 20);
JComboBox cbxAge = new JComboBox(ageRange);
cbxAge.setBackground(Color.WHITE);
cbxAge.setBounds(120, 60, 200, 20);
lblGender = new JLabel(" Gender ");
lblGender.setBounds(10, 80, 80, 20);
Gender.add(male);
male.setBounds(120, 80, 80, 20);
male.setBackground(Color.WHITE);
Gender.add(female);
female.setBounds(200, 80, 80, 20);
female.setBackground(Color.WHITE);
lblBirthday = new JLabel(" Birthday ");
lblBirthday.setBounds(10, 100, 80, 20);
txtBirthday = new JTextField(15);
txtBirthday.setBounds(120, 100, 200, 20);
lblContact = new JLabel("*Contact ");
lblContact.setBounds(10, 120, 80, 20);
txtContact = new JTextField(15);
txtContact.setBounds(120, 120, 200, 20);
lblEmail = new JLabel(" Email ");
lblEmail.setBounds(10, 140, 80, 20);
txtEmail = new JTextField(15);
txtEmail.setBounds(120, 140, 200, 20);
lblRace = new JLabel(" Race ");
lblRace.setBounds(10, 160, 80, 20);
Race.add(Chinese);
Race.add(Malay);
Race.add(Indian);
Race.add(Others);
Chinese.setBounds(120, 160, 100, 20);
Chinese.setBackground(Color.WHITE);
Malay.setBounds(220, 160, 100, 20);
Malay.setBackground(Color.WHITE);
Indian.setBounds(320, 160, 100, 20);
Indian.setBackground(Color.WHITE);
Others.setBounds(420, 160, 100, 20);
Others.setBackground(Color.WHITE);
lblAddress= new JLabel(" Address ");
lblAddress.setBounds(10, 180, 80, 20);
txtAddress = new JTextField(45);
txtAddress.setBounds(120, 180, 500, 20);
lblTransactionID = new JLabel(" Transaction ID ");
lblTransactionID.setBounds(10, 200, 120, 20);
txtTransactionID = new JTextField(15);
txtTransactionID.setBounds(120, 200, 200, 20);
lblImages = new JLabel(" Image");
lblImages.setBounds(10, 220, 120, 20);
txtImages = new JTextField("Please Choose a image for customer");
txtImages.setBounds(120, 220, 350, 20);
Choose = new JButton("Choose");
Choose.setBounds (480,220,80,20);
Choose.addActionListener(this);
Show = new JButton("Show");
Show.setBounds(565,220,80,20);
Show.setToolTipText("Click to show your image");
Show.addActionListener(this);
ImageIcon save = new ImageIcon("images/Save(20x20).png");
Save = new JButton("Save",save);
Save.setBounds(340, 300, 100, 40);
Save.addActionListener(this);
ImageIcon cancel = new ImageIcon("images/Cancel(20x20).png");
Cancel = new JButton("Cancel",cancel);
Cancel.setBounds(442, 300, 100, 40);
Cancel.addActionListener(this);
ImageIcon clear = new ImageIcon("images/Clear(20x20).png");
Clear = new JButton("Clear",clear);
Clear.setBounds(544, 300, 100, 40);
Clear.addActionListener(this);
panel.add(lblTitle);
panel.add(lblFirstName);
panel.add(txtFirstname);
panel.add(lblLastName);
panel.add(txtLastName);
panel.add(lblAge);
panel.add(cbxAge);
panel.add(lblGender);
panel.add(male);
panel.add(female);
panel.add(lblBirthday);
panel.add(txtBirthday);
panel.add(lblContact);
panel.add(txtContact);
panel.add(lblEmail);
panel.add(txtEmail);
panel.add(lblRace);
panel.add(Chinese);
panel.add(Malay);
panel.add(Indian);
panel.add(Others);
panel.add(lblAddress);
panel.add(txtAddress);
panel.add(lblTransactionID);
panel.add(txtTransactionID);
panel.add(lblImages);
panel.add(txtImages);
panel.add(Choose);
panel.add(Show);
panel.add(Save);
panel.add(Cancel);
panel.add(Clear);
return panel;
}
/**********************************************************************************************************************************************************
public class btCM extends JFrame implements ActionListener{
private String ageRange[] = {"Please select age range","10-20","21-30","31-40","41-50","51-60","61-70","71-80","81-90"};
private JLabel lblTitle,lblFirstName,lblLastName,lblContact, lblAddress, lblGender, lblAge, lblEmail, lblBirthday,lblRace,lblTransactionID;
private JTextField txtFirstname , txtLastName , txtContact , txtAddress , txtGender , txtAge , txtEmail , txtBirthday,txtRace,txtTransactionID;
private JRadioButton male = new JRadioButton("Male",false), female = new JRadioButton("Female", false);
private JRadioButton Chinese = new JRadioButton("Chinese",false), Malay = new JRadioButton("Malay", false),Indian = new JRadioButton("Indian", false),Others = new JRadioButton("Others", false);
private ButtonGroup Gender = new ButtonGroup();
private ButtonGroup Race = new ButtonGroup();
private JButton Save = new JButton(), Cancel = new JButton() , Clear = new JButton();
JButton btNew,btSearch,btPrint;
JTextPane text;
JPanel panel = new JPanel();
JFrame frame = new JFrame("Customer Management System");
NewCustomer NC = new NewCustomer();
SearchCustomer SC = new SearchCustomer();
public btCM()
{
initUI();
}
public final void initUI() {
frame.setVisible(true);
frame.setSize(710,570 );
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.getContentPane().setLayout(null);
ImageIcon new_customer = new ImageIcon("images/new(30x30).png");
btNew = new JButton("New",new_customer);
btNew.setBounds(10, 10, 110, 60);
btNew.setMnemonic(KeyEvent.VK_N);
btNew.addActionListener(this);
ImageIcon search = new ImageIcon("images/search(30x30).png");
btSearch = new JButton("Search",search);
btSearch.setBounds(120, 10, 110, 60);
btSearch.setMnemonic(KeyEvent.VK_S);
btSearch.addActionListener(this);
ImageIcon print = new ImageIcon("images/print(30x30).png");
btPrint = new JButton("Print",print);
btPrint.setBounds(230, 10, 110, 60);
btPrint.setMnemonic(KeyEvent.VK_P);
btPrint.addActionListener(this);
frame.getContentPane().add(btNew);
frame.getContentPane().add(btSearch);
frame.getContentPane().add(btPrint);
frame.getContentPane().add(panel);
frame.getContentPane().add(NC.getNewPanel());
frame.getContentPane().add(SC.getNewPanel());
NC.getNewPanel().setVisible(false);
SC.getNewPanel().setVisible(false);
}
public void actionPerformed(ActionEvent e)
{
Object o = e.getSource();
if(o == btNew)
{
//panel.layout();
NC.getNewPanel().setVisible(true);
SC.getNewPanel().setVisible(false);
panel.setVisible(false);
frame.repaint();
} |
|