Results 1 to 5 of 5
Thread: Output to TextArea
- 08-01-2008, 06:08 PM #1
Member
- Join Date
- Jul 2008
- Posts
- 43
- Rep Power
- 0
Output to TextArea
Below is my program. How do I get the contents to display in TextArea?
Java Code:// CheckPoint: Inventory4.java // Week 7 // This program calculates inventory value import java.awt.*; import javax.swing.*; public class Inventory4 { // main method begins program execution public static void main( String args[] ) { // display a welcome message to the InventoryProgramPart4 user System.out.println( "Welcome to Inventory Program Part 4!" ); // office supplies supplies[] supplies = new supplies[100]; // an array of 100 supplies manufacturer[] manufacturer = new manufacturer[100]; manufacturer notepads = new manufacturer ( 4000, "notepads", 60, 2.75, "Ampad" ); manufacturer pencils = new manufacturer ( 5000, "pencils", 75, 1.25, "Bic" ); manufacturer folders = new manufacturer ( 2000, "folders", 30, 4.75, "3M" ); manufacturer envelopes = new manufacturer ( 1000, "envelopes", 15, 5.25, "Universal" ); manufacturer markers = new manufacturer ( 3000, "markers", 45, 3.50, "Sanford" ); manufacturer temp[] = new manufacturer[1]; for( int i = 0; i < args.length - 1; i++ ) { for( int j = 0; j < args.length - 1; j++ ) { if( manufacturer[j].getSuppliesName().compareToIgnoreCase( manufacturer[j+1].getSuppliesName() ) > 0 ) { temp[0] = manufacturer[j]; manufacturer[j] = manufacturer[j+1]; manufacturer[j+1] = temp[0]; } // end if } // end for } // end for // display the inventories one at a time envelopes.showInventory(); folders.showInventory(); markers.showInventory(); notepads.showInventory(); pencils.showInventory(); // sort supplies by name for ( int i = 0; i < args.length; i++ ) System.out.println( args[i] + ", " ); double array[] = { 82.69, 149.63, 165.38, 173.25, 98.44 }; double total = 0; // add each element's value to total for ( int counter = 0; counter < array.length; counter++) total += array[ counter ]; System.out.printf( "\nTotal inventory value is: $%.2f\n", total ); System.out.println( "\nThank you for using Inventory Program Part 4!\n" ); javax.swing.JTextArea ta = new javax.swing.JTextArea( 10, 20 ); for( int i = 0; i < args.length; i++ ) { ta.append( args[i].toString()+"\n" ); } // end for { javax.swing.JFrame frame = new javax.swing.JFrame(); frame.getContentPane().add(new javax.swing.JScrollPane(ta) ); frame.pack(); frame.setLocationRelativeTo( null ); frame.setDefaultCloseOperation( javax.swing.JFrame.EXIT_ON_CLOSE ); frame.setVisible( true ); } // end frame } // end main } // end class Inventory4 // Office Supplies class supplies { public int suppliesNumber; public String suppliesName = new String(); public int suppliesUnits; public double suppliesPrice; // set supplies number public void setSuppliesNumber( int number ) { this.suppliesNumber = number; } // end method set supplies number // return supplies number public int getSuppliesNumber() { return suppliesNumber; } // end method get supplies number // set supplies name public void setSuppliesName( String name ) { this.suppliesName = name; } // end method set supplies name // return supplies name public String getSuppliesName() { return suppliesName; } // end method get supplies name // set supplies in stock public void setSuppliesUnits( int units ) { this.suppliesUnits = units; } // end method set supplies units // return supplies units public int getSuppliesUnits() { return suppliesUnits; } // end method get supplies units // set supplies price public void setSuppliesPrice( double price ) { this.suppliesPrice = price; } // end method set supplies price // return supplies price public double getSuppliesPrice() { return suppliesPrice; } // end method get supplies price // calculate supplies inventory value public double getValue() { return suppliesUnits * suppliesPrice; } // end method supplies inventory value // four-argument constructor supplies( int number, String name, int units, double price ) { suppliesNumber = number; suppliesName = name; suppliesUnits = units; suppliesPrice = price; } // end four-argument constructor // display inventory public void showInventory() { System.out.println(); // outputs blank line System.out.println( "Product Number: "+suppliesNumber ); System.out.println( "Product Name: "+suppliesName ); System.out.println( "Units in Stock: "+suppliesUnits ); System.out.printf( "Unit Price: $%.2f", suppliesPrice ); // value() method and display the value System.out.printf( "\nInventory value of "+suppliesName+ " is = $%.2f\n", getValue() ); } // end display inventory } // end class supplies class manufacturer extends supplies { // holds the supplies manufacturer private String suppliesManufacturer; // five-argument constructor public manufacturer( int number, String name, int units, double price, String manufacturer ) { super( number, name, units, price ); // validate and store supplies manufacturer setSuppliesManufacturer( manufacturer ); } // end five-argument constructor // set supplies manufacturer public void setSuppliesManufacturer( String manufacturer ) { this.suppliesManufacturer = manufacturer; } // end method set supplies manufacturer // return supplies manufacturer public String getSuppliesManufacturer() { return suppliesManufacturer; } // end method get supplies manufacturer // calculate restocking fee public double getRestockingFee() { return super.getValue() * 0.05; } //end method calculate restocking fee //return String representation of suppliesManufacturer public String toString() { String formatString = "Manufacturer: %s"; formatString += "\nRestocking Fee: $%.2f\n"; formatString = String.format( formatString, suppliesManufacturer, super.getValue() * 0.05 ); return( formatString ); } // end toString() // display inventory public void showInventory() { super.showInventory(); System.out.println( toString() ); // Display value plus restocking fee System.out.printf( "\nTotal Inventory value of "+suppliesName+ " is = $%.2f\n", super.getValue() * 0.05 + super.getValue() ); } // end method display inventory } // end class manufacturer
- 08-01-2008, 07:58 PM #2
Look at the API doc for the TextArea and read the set and append methods.the contents to display in TextArea
What are "the contents"?
- 08-02-2008, 03:10 AM #3
Member
- Join Date
- Jul 2008
- Posts
- 43
- Rep Power
- 0
What is the API doc? I am new to Java and not sure of all the terminology.
- 08-02-2008, 03:50 AM #4
Application Program Interface documentation. It documents all the java classes and their fields and methods.
You will need to be very familiar with this to program.
Its a free down load from the Sun site
- 08-03-2008, 09:59 AM #5
Similar Threads
-
TextArea with Unicode
By Java Tip in forum javax.swingReplies: 0Last Post: 04-16-2008, 10:53 PM -
How to get the position of character in TextArea
By loganathan.lakshmanan in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 01-19-2008, 12:06 AM -
TextArea Bug?
By Soda in forum New To JavaReplies: 2Last Post: 12-07-2007, 12:37 PM -
problems when I print in textarea
By gabriel in forum New To JavaReplies: 1Last Post: 07-26-2007, 06:57 PM -
textarea
By ubuntu in forum AWT / SwingReplies: 4Last Post: 05-12-2007, 09:54 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks