Results 1 to 3 of 3
Thread: Arraylist
- 04-23-2010, 11:17 PM #1
Arraylist
Where would it be safe to create and arraylist?
Java Code:package accountlog; /** * * @author RaFiKi */ import java.awt.*; // for Container import java.awt.event.*; import javax.swing.*; class Accountlog extends JFrame { private JTextField firstNameField = new JTextField(10); private JTextField surnameField = new JTextField(10); private JTextField accountNumberField = new JTextField (10); private JPanel dataPanel = new JPanel(); private UserInputPanel userInputPanel = new UserInputPanel(); private OptionButtonPanel optionButtonPanel = new OptionButtonPanel(); private JPanel dobPanel = new JPanel(); private JPanel outputPanel = new JPanel(); private JLabel outputLabel = new JLabel(""); private JComboBox monthChoices; private String[] months = { "", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; private JComboBox dateChoices; private String[] dates = { "", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }; private JComboBox yearChoices; private String[] years = { "", "1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007" }; private JComboBox bankChoices; private String [] banks = {"", "HSBC", "Loyds TSB", "Barclays", "RSB", "Natwest" }; private JTextArea dataArea; private JScrollPane scrollPane; private int year = 0; private int month = 0; private int date = 0; private String bank = ""; // window properties private static final int FRAMEWIDTH = 500; private static final int FRAMEHEIGHT = 450; private static final int FRAMEX = 350; // screen co-ordinates private static final int FRAMEY = 300; // PersonV4 object PersonV4 person = new PersonV4(); public Accountlog() { Container guiContainer = getContentPane(); guiContainer.setLayout(new BorderLayout()); dataPanel.setLayout(new BorderLayout()); dataPanel.add(userInputPanel, BorderLayout.NORTH); dobPanel.add(new JLabel("Date ")); // instantiate combo box with dates array dateChoices = new JComboBox(dates); dateChoices.setSelectedIndex(0); // set default item // assign listener DateComboBoxListener dcbListener = new DateComboBoxListener(); dateChoices.addItemListener(dcbListener); dobPanel.add(dateChoices); // process next two combo boxes and their listeners dobPanel.add(new JLabel("Month ")); monthChoices = new JComboBox(months); monthChoices.setSelectedIndex(0); MonthComboBoxListener mcbListener = new MonthComboBoxListener(); monthChoices.addItemListener(mcbListener); dobPanel.add(monthChoices); dobPanel.add(new JLabel("Year ")); yearChoices = new JComboBox(years); yearChoices.setSelectedIndex(0); YearComboBoxListener ycbListener = new YearComboBoxListener(); yearChoices.addItemListener(ycbListener); dobPanel.add(yearChoices); dataPanel.add(dobPanel, BorderLayout.SOUTH); dobPanel.add(new JLabel("Bank ")); bankChoices = new JComboBox(banks); bankChoices.setSelectedIndex(0); BankComboBoxListener bcbListener = new BankComboBoxListener(); bankChoices.addItemListener((ItemListener) bcbListener); dobPanel.add(bankChoices); // add remaining components guiContainer.add(dataPanel, BorderLayout.NORTH); guiContainer.add(optionButtonPanel, BorderLayout.CENTER); // initialise and assign text area dataArea = new JTextArea(10, 20); scrollPane = new JScrollPane(dataArea); outputPanel.add(scrollPane); guiContainer.add(outputPanel, BorderLayout.SOUTH); }
- 04-24-2010, 12:19 AM #2
Senior Member
- Join Date
- Mar 2010
- Posts
- 266
- Rep Power
- 4
anywhere. creating ArrayLists is very safe.
please be more specific - what are you trying to do?
- 04-24-2010, 01:30 AM #3
Trying to implement this code
Safely into hereJava Code:private void saveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveActionPerformed // TODO add your handling code here: if(evt.getActionCommand().equals("Save")) { updatePerson(); //retrieve contents of window and store in person personList.add(person); //always appending }
I need to create the personlist array i was wondering where i would put it.Java Code:private class OptionButtonPanel extends JPanel { public OptionButtonPanel() { setLayout(new FlowLayout()); OptionButtonListener optionButtonListener = new OptionButtonListener(); JButton displayButton = new JButton("Show Current"); add(displayButton); displayButton.addActionListener(optionButtonListener); JButton saveButton = new JButton ("Save"); add (saveButton); saveButton.addActionListener(optionButtonListener); JButton showButton = new JButton ("Show All"); add(showButton); showButton.addActionListener(optionButtonListener); JButton clearButton = new JButton ("Clear"); add (clearButton); clearButton.addActionListener(optionButtonListener); JButton quitButton = new JButton("Exit"); add(quitButton); quitButton.addActionListener(optionButtonListener); } } private class OptionButtonListener implements ActionListener { public void actionPerformed(ActionEvent event) { String command = event.getActionCommand(); if(command.equals("Show Current")) { // assign data extracted from window to person object person.setForename(firstNameField.getText()); person.setSurname(surnameField.getText()); person.setAccountnumber (accountNumberField.getText()); person.setDOB(date, month, year); // extract data from person object and write to text area dataArea.append("Forename: "); dataArea.append(person.getForename()); dataArea.append(" Surname: "); dataArea.append(person.getSurname()); dataArea.append ("\n Account Number: "); dataArea.append(person.getAccountnumber()); dataArea.append("\nAcc. Start Date: "); dataArea.append(Integer.toString(person.getDateOfBirth()) + '/' + Integer.toString(person.getMonthOfBirth()) + '/' + Integer.toString(person.getYearOfBirth())); dataArea.append("\nAge of Account: " + Integer.toString(person.getAge())); dataArea.append ("\nBank: "); dataArea.append(bank); dataArea.append("\n"); // new line } if(command.equals("Exit")) { int option = JOptionPane.showConfirmDialog(null, "Do you really want to exit?", "Confirm", JOptionPane.YES_NO_OPTION); if(option == JOptionPane.YES_OPTION) { System.exit(0); } } }
Similar Threads
-
Regarding arrayList
By kishan in forum Advanced JavaReplies: 7Last Post: 08-07-2009, 12:48 PM -
Java Project Trouble: Searching one ArrayList with another ArrayList
By BC2210 in forum New To JavaReplies: 2Last Post: 04-21-2008, 11:43 AM -
ArrayList
By kizilbas1 in forum New To JavaReplies: 1Last Post: 01-12-2008, 08:48 PM -
ArrayList
By kizilbas1 in forum New To JavaReplies: 11Last Post: 12-05-2007, 07:30 PM -
New to arraylist
By kleave in forum New To JavaReplies: 2Last Post: 11-19-2007, 06:45 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks