Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-19-2008, 08:33 AM
Member
 
Join Date: Mar 2008
Posts: 3
Jononomous is on a distinguished road
replacing array values
Alright So....I'm trying to replace the array values when I hit my 'add' button, and then when i hit the summary button it displays the initial array values, the ones i preloaded in, and the new, updated ones. Any help here is much appreciated, been workin on it for days



Questions being:

1. How do I achieve the proper effects with my add and summary buttons, right now it will display the initial values but not the ones I add in using my add button.

2. How do I make it so that when it appends null to my textArea to actually make it append "N/A" instead, current method isnt working properly

Code:

Code:
import javax.swing.*; import java.awt.Color; import java.awt.Container; import java.awt.FlowLayout; import java.awt.event.*; public class partsPresentation extends JFrame implements ActionListener { private static final int FRAME_WIDTH = 375; private static final int FRAME_HEIGHT = 600; private static final int FRAME_X_ORIGIN = 150; private static final int FRAME_Y_ORIGIN = 250; private static final int BUTTON_WIDTH = 80; private static final int BUTTON_HEIGHT = 30; JLabel partAddLabel; JButton summaryButton; JTextField pwrapField; JTextField brandAField; JTextField brandBField; JTextField brandXField; JLabel columnsLabel; JButton addButton; private JTextArea textArea; private JScrollPane textBoxScroll; private String WHITESPACE = " "; partsSummary newArray[]; partsSummary partsList[] = new partsSummary[9]; partsSummary partsSum; public static void main(String[] args) { partsPresentation frame = new partsPresentation(); frame.setVisible(true); } public partsPresentation() { Container contentPane; setSize(FRAME_WIDTH, FRAME_HEIGHT); setResizable(false); setTitle("Ch10 Project"); setLocation(FRAME_X_ORIGIN, FRAME_Y_ORIGIN); contentPane = getContentPane(); contentPane.setLayout(new FlowLayout()); columnsLabel = new JLabel(); columnsLabel .setText(" PWrap - Brand A - Brand B - Brand X "); columnsLabel.setSize(150, 25); contentPane.add(columnsLabel); partAddLabel = new JLabel(); partAddLabel.setText("Add Part: "); partAddLabel.setSize(150, 25); contentPane.add(partAddLabel); pwrapField = new JTextField(); pwrapField.setColumns(6); contentPane.add(pwrapField); brandAField = new JTextField(); brandAField.setColumns(4); contentPane.add(brandAField); brandBField = new JTextField(); brandBField.setColumns(4); contentPane.add(brandBField); brandXField = new JTextField(); brandXField.setColumns(4); contentPane.add(brandXField); summaryButton = new JButton("Summary"); summaryButton.setSize(BUTTON_WIDTH, BUTTON_HEIGHT); contentPane.add(summaryButton); addButton = new JButton("Add Part"); addButton.setSize(BUTTON_WIDTH, BUTTON_HEIGHT); contentPane.add(addButton); textArea = new JTextArea(); textArea.setColumns(30); textArea.setRows(20); textArea.setLineWrap(true); textBoxScroll = new JScrollPane(textArea); textBoxScroll .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); textArea.setBorder(BorderFactory.createLineBorder(Color.RED)); // Set to non edit textArea.setEditable(false); contentPane.add(textBoxScroll); pwrapField.addActionListener(this); brandAField.addActionListener(this); brandBField.addActionListener(this); brandXField.addActionListener(this); summaryButton.addActionListener(this); addButton.addActionListener(this); setDefaultCloseOperation(EXIT_ON_CLOSE); } public void assignParts() { for (int i = 0; i < partsList.length; i++) { partsList[i] = new partsSummary(); } partsList[0].setValues("PR001", "A001", "B001", "X001"); partsList[1].setValues("PR002", "A002", "B002", "X002"); partsList[2].setValues("PR003", "A003", "B003", "X003"); } public void actionPerformed(ActionEvent event) { String PWrapStr = pwrapField.getText(); String brandAStr = brandAField.getText(); String brandBStr = brandBField.getText(); String brandXStr = brandXField.getText(); //start on the 3rd index of the array int partsListIndex = 3; if (event.getSource() instanceof JButton) { JButton clickedButton = (JButton) event.getSource(); if (clickedButton == addButton) { partsList[partsListIndex].setValues(PWrapStr, brandAStr, brandBStr, brandXStr); partsListIndex += 1; JOptionPane.showMessageDialog(null, "Part Added!"); } if (clickedButton == summaryButton) { int indexInteger = 0; boolean foundBoolean = true; // This seems to be a key element? assignParts(); //With it, I can click summary and it will output the //preset array values. However, when i remove it and hit the //summary button, runtime error ect. BUT! if I 'add' a part //using the add button, and THEN click summary, it works //like it should, but it doesnt have the preset array values. while (indexInteger < partsList.length && foundBoolean != false) { for (int i = 0; i < partsList.length; i++) { textArea.append(partsList[i].getPW() + WHITESPACE + partsList[i].getBrandA() + WHITESPACE + partsList[i].getBrandB() + WHITESPACE + partsList[i].getBrandX() + "\n"); indexInteger+=1; } if (indexInteger == partsList.length) { foundBoolean = false; } } } } } }
=====================
MY OTHER CLASS!!
=====================

Code:
public class partsSummary { private String plainWrapString; private String brandAString; private String brandBString; private String brandXString; public void setValues(String plainWrap, String brandA, String brandB, String brandX) { if (plainWrap != null) { plainWrapString = plainWrap; } else { plainWrapString = "N/A"; } if (brandA != null) { brandAString = brandA; } else { brandAString = "N/A"; } if (brandB != null) { brandBString = brandB; } else { brandBString = "N/A"; } if (brandX != null) { brandXString = brandX; } else { brandXString = "N/A"; } } public String getPW() { return plainWrapString; } public String getBrandA() { return brandAString; } public String getBrandB() { return brandBString; } public String getBrandX() { return brandXString; } }
Thanks again,

- Jononomous

Last edited by Jononomous : 05-19-2008 at 08:36 AM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-22-2008, 05:27 PM
orchid's Avatar
Member
 
Join Date: Apr 2007
Location: Midwest
Posts: 60
orchid is on a distinguished road
What I discovered is a null pointer exception when I hit the add button. YOu are not assigning values to your array until the summary button is clicked.
Code:
if (clickedButton == summaryButton) { int indexInteger = 0; boolean foundBoolean = true; // This seems to be a key element? assignParts();
You probably want to initialize your array prior to this.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
3d array filled with garbage values jon80 New To Java 4 04-21-2008 05:12 PM
Accessing boolean Values of another values in one class. a_iyer20 Advanced Java 4 04-15-2008 03:04 PM
[SOLVED] How to read a file and compare Array values DonCash Advanced Java 2 04-02-2008 04:22 PM
Replacing at an index bugger New To Java 2 01-29-2008 08:33 AM
splitting string and replacing itsme New To Java 1 12-11-2007 05:08 PM


All times are GMT +3. The time now is 04:56 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org