Hi i have a combobox and when i click on add button another frame pop up with text field(name ,address etc..) ,confirm button and cancel button at bottom of the frame. When i put something on the second window and click confirm i would have the information on the combo box. i don't really know how to doing it.
Sorry i forget to put my code i got two class. this is the first class print("import javax.swing.*; import java.awt.event.*; import java.util.*;
public class AddressList{ JComboBox combo; JTextField txtBox; private String PersonViewing; private String TelephoneNumber; private String Address; private JFrame Addressframe; Address Alist;
/** * Return the name of person that are viewing the property */ public String getName() { return PersonViewing; } /** * Return the address of person that are viewing the property */ public String getAddress() { return PersonViewing; } /** * Return the telephone number of person that are viewing the property */ public String getTelephoneNumberOfPerson() { return TelephoneNumber; } public AddressList(){ JFrame frame = new JFrame("Add-Remove item to list"); String items[] = {"", "", "", "", ""}; combo = new JComboBox(items); JButton button1 = new JButton("Add new item"); txtBox = new JTextField(35); button1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ Address Alist = new Address(); } }); JButton button2 = new JButton("Remove"); button2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ if (combo.getItemCount() > 0) combo.removeItemAt(0); else JOptionPane.showMessageDialog(null,"the viewing list is empty "); } }); JPanel panel = new JPanel(); JPanel panel1 = new JPanel(); panel.add(txtBox); panel.add(combo); panel.add(button1); panel.add(button2); frame.add(panel); // frame.add(panel1); frame.setSize(320, 350); frame.setVisible(true); frame.setResizable(false); boolean resizable = frame.isResizable(); }
}"); abd this is the second class `print("import javax.swing.*; import java.awt.event.*; import java.util.*; import java.awt.*;
public class Address { public Address() { JFrame frame3 = new JFrame("Adding the new propert"); JPanel panel = new JPanel(new GridLayout(4,2,20,30)); panel.add(new JLabel("Name" )); panel.add(new JTextField(5)); panel.add(new JLabel("Telphone")); panel.add(new JTextField(3)); panel.add(new JLabel("Address")); panel.add(new JTextField(3)); panel.add(new JButton("Confirm")); panel.add(new JButton("Cancel"));
frame3.add(panel); frame3.setSize(350,350); frame3.setVisible(true); } }e");`
thanks
Sorry for the previous message
import javax.swing.*; import java.awt.event.*; import java.util.*; public class AddressList{ JComboBox combo; JTextField txtBox; private String PersonViewing; private String TelephoneNumber; private String Address; private JFrame Addressframe; Address Alist; /** * Return the name of person that are viewing the property */ public String getName() { return PersonViewing; } /** * Return the address of person that are viewing the property */ public String getAddress() { return PersonViewing; } /** * Return the telephone number of person that are viewing the property */ public String getTelephoneNumberOfPerson() { return TelephoneNumber; } public AddressList(){ JFrame frame = new JFrame("Add-Remove item to list"); String items[] = {"", "", "", "", ""}; combo = new JComboBox(items); JButton button1 = new JButton("Add new item"); txtBox = new JTextField(35); button1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ Address Alist = new Address(); } }); JButton button2 = new JButton("Remove"); button2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ if (combo.getItemCount() > 0) combo.removeItemAt(0); else JOptionPane.showMessageDialog(null,"the viewing list is empty "); } }); JPanel panel = new JPanel(); JPanel panel1 = new JPanel(); panel.add(txtBox); panel.add(combo); panel.add(button1); panel.add(button2); frame.add(panel); // frame.add(panel1); frame.setSize(320, 350); frame.setVisible(true); frame.setResizable(false); boolean resizable = frame.isResizable(); } } import javax.swing.*; import java.awt.event.*; import java.util.*; import java.awt.*; public class Address { public Address() { JFrame frame3 = new JFrame("Adding the new propert"); JPanel panel = new JPanel(new GridLayout(4,2,20,30)); panel.add(new JLabel("Name" )); panel.add(new JTextField(5)); panel.add(new JLabel("Telphone")); panel.add(new JTextField(3)); panel.add(new JLabel("Address")); panel.add(new JTextField(3)); panel.add(new JButton("Confirm")); panel.add(new JButton("Cancel")); frame3.add(panel); frame3.setSize(350,350); frame3.setVisible(true); } }
import java.awt.*; import javax.swing.*; import java.awt.event.*; public class AddRemoveItemFromCombo{ JComboBox combo; public static void main(String[] args){ AddRemoveItemFromCombo ar = new AddRemoveItemFromCombo(); } public AddRemoveItemFromCombo(){ final JFrame frame = new JFrame("Add-Remove Item of a Combo Box"); combo = new JComboBox(); JButton button1 = new JButton("Add"); button1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ final JFrame frame3 = new JFrame("Adding the new propert"); JPanel panel = new JPanel(new GridLayout(4,2,20,30)); JButton b1=new JButton("Confirm"); JButton b2=new JButton("Cancel"); final JTextField text1=new JTextField(3); final JTextField text2=new JTextField(3); final JTextField text3=new JTextField(3); panel.add(new JLabel("Name")); panel.add(text1); panel.add(new JLabel("Telphone")); panel.add(text2); panel.add(new JLabel("Address")); panel.add(text3); panel.add(b1); panel.add(b2); frame3.add(panel); frame3.setSize(350,350); frame3.setVisible(true); b1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ frame.setFocusable(true); StringBuffer buffer=new StringBuffer(); buffer.append(text1.getText()).append(", ").append(text2.getText()).append(", ").append(text3.getText()); String text=buffer.toString(); System.out.println(text); if (!text.equals("")){ int a = 0; for(int i = 0; i < combo.getItemCount(); i++){ if(combo.getItemAt(i).equals(text)){ a = 1; break; } } if (a == 1) JOptionPane.showMessageDialog(null,"Combo has already this item."); else combo.addItem(text); } else{ JOptionPane.showMessageDialog(null,"Please enter text in Text Box"); } frame3.setVisible(false); } }); } }); JButton button2 = new JButton("Remove"); button2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ if (combo.getItemCount() > 0) combo.removeItemAt(0); else JOptionPane.showMessageDialog(null,"Item not available"); } }); JPanel panel = new JPanel(); JPanel panel1 = new JPanel(); panel.add(combo); panel.add(button1); panel.add(button2); frame.add(panel); frame.setSize(400, 400); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
thanks you i would like ask another question i would like to make a non GUI class of list of address and put on the combox box how i could to do that ?
Ads