Help with displaying text through GUI interface

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2007
Posts: 1
Reputation: meha1331 is an unknown quantity at this point 
Solved Threads: 0
meha1331 meha1331 is offline Offline
Newbie Poster

Help with displaying text through GUI interface

 
0
  #1
Mar 4th, 2007
This is my code, I could get the program to run before i tried to get it to display using a GUI interface; can anyone help please?
//Inventory Program Part5

import java.util.*; //=============================import all java.util classes
import java.text.*;
import javax.swing.*;

class Product //============================================start Product class
{
public String[] className; //=====================================class's name
public int[] classNumber; //=====================class's unique product number
public int[] classQuantity; //=======================class's quantity in stock
public double[] classPrice; //===============================class's price per

public Product(String[] name, int[] number, int[] quantity, double[] price)
//==========================================================product constructor
{
className = name; //==============================set className to name
classNumber = number; //======================set classNumber to number
classQuantity = quantity; //==============set classQuantity to quantity
classPrice = price; //==========================set classPrice to price
} //====================================================end Product constructor

public Product SortedArray(Product Inventory5) //======start method SortedArray
{
String[] name=new String[Inventory5.className.length];
//=================================================new name for sorting array
int [] number = new int[Inventory5.classNumber.length];
//===============================================new number for sorting array
int[] quantity = new int[Inventory5.classQuantity.length];
//=============================================new quantity for sorting array
double [] price = new double [Inventory5.classPrice.length];
//=================================================new price for sorting array
name = (String[])Inventory5.className.clone();
//=================================================place name in sorting array
Arrays.sort(name); //=============================================sort by name
for (int counter = 0; counter < name.length; counter++)
//==========================================loop and counter for sorting array
{
for(int counter2=0;counter2<name.length;counter2++)
//====================loop and counter to match unsorted array and sorted one
{
if(name[counter].equals(Inventory5.className[counter2]))
//=====================================if statement for when a match occurs
{
quantity[counter]=Inventory5.classQuantity[counter2];
//=============================set quantity equal to sorted array quantity
price[counter]=Inventory5.classPrice[counter2];
//===================================set price equal to sorted array price
number[counter]=Inventory5.classNumber[counter2];
//=================================set number equal to sorted array number
break; //============================================break for if statement
} //========================================================end if statement

} //====================================================end for loop counter2

} //======================================================end for loop counter
Product SortedProductArray = new Product (name, number, quantity, price);
//=========================new sorted product array replace old product array
return SortedProductArray; //==================return new product array sorted
} //=====================================================end method SortedArray

public double TotalInvWorth(int[] quantity, double[] price)
//=====start method TotalInvWorth
{
double total=0.00F; //====================================set double total = 0
for (int counter = 0; counter < quantity.length; counter++)
//================loop and counter to multiply each quantity x price in array
{
double perprodworth=quantity[counter]*price[counter];
//============= multiply quantity x price per counter in array = perprodworth
total=total+perprodworth; //=========================add perprodworth to total
}
return total; //==================================return total in TotalInvWorth
} //===================================================end method TotalInvWorth

} //===========================================================end Product class
public class Inventory5 extends JFrame
{
JTextArea _resultArea = new JTextArea(20,40);
//=================================================== start class Inventory5
public static void main(String[] args) //==============start main method
{
//=========================setting static data for variables in each array
String[] name = {"Java Programming IT", "Internet Concepts IT",
"Analysis & Design IT", "Computer Networking IT"};
int[] number = {315, 320, 321, 330};
int[] quantity = {1, 1, 1, 1};
double[] price = {(double) 855.00, (double) 855.00, (double) 855.00,
(double) 855.00};

Product Inventory5 = new Product (name, number, quantity, price);
//=========================================needed to resolve constructor

JOptionPane.showMessageDialog(null, "Course Name: " className,
"\nCourseID: " classNumber, "\n Price of Remaining Class: $"
classPrice, "\nTotal of Remaining Courses: $" TotalInvWorth,
JOptionPane.PLAIN_MESSAGE);


} //========================================================end main method

} //======================================================= end class Inventory5
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,242
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 491
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Help with displaying text through GUI interface

 
0
  #2
Mar 5th, 2007
You can't force showMessageDialog to something it is not build for :cheesy:
You giving it is : Component, object, object, object and on the end title and message type
where java knows only of this method
showMessageDialog(Component parentComponent, Object message, String title, int messageType)
http://java.sun.com/javase/6/docs/ap....String,%20int)
You have two options either you will create your own showMessageDialog or you will output result in some other component (example JFrame)

Secondly you need to make some changes to the way you try to call your variables. It is a bad idea to name Product variable as Inventory5 which is your class name, if you want it with that name you should use lower case for first letter. Than className is an array, if you want to get value from array you have to give it position from which you want to retrive value. You can see my correction bellow

Originally Posted by meha1331 View Post
Product class
public class Inventory5 extends JFrame
{
JTextArea _resultArea = new JTextArea(20,40);
//=================================================== start class Inventory5
public static void main(String[] args) //==============start main method
{
//=========================setting static data for variables in each array
String[] name = {"Java Programming IT", "Internet Concepts IT",
"Analysis & Design IT", "Computer Networking IT"};
int[] number = {315, 320, 321, 330};
int[] quantity = {1, 1, 1, 1};
double[] price = {(double) 855.00, (double) 855.00, (double) 855.00,
(double) 855.00};

Product product = new Product (name, number, quantity, price);
//=========================================needed to resolve constructor

JOptionPane.showMessageDialog(null, "Course Name: " product.className[0],
"My Message",JOptionPane.PLAIN_MESSAGE);


} //========================================================end main method

} //======================================================= end class Inventory5
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC