Java Inventory Part 4

Can't figure out how to call Inventory Info to print out in the GU

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 1561 Views - Last Post: 23 July 2009 - 06:12 AM Rate Topic: -----

#1 Beachgirl029  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 07-July 09

Java Inventory Part 4

Posted 21 July 2009 - 11:52 AM

The problem that I am having is I don't know how to set up the GUI to call the Inventory code I have already written. The instructions are below in quotation marks and I have Never worked with GUI before. I can write the code but GUI is new to me. Please I need help getting started. I am working in the Netbeans software.


"This class will modify the Inventory Program to use a GUI. The GUI will display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory of that product. In addition, the GUI will display the value of the entire inventory, the additional attribute, and the restocking fee."




package inventoryprogram;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.event.AncestorListener;
public class InventoryProgram extends javax.swing.JFrame implements ActionListener {
public InventoryProgram() {
initComponents();
		}
@SuppressWarnings("unchecked")
 // <editor-fold defaultstate="collapsed" desc="Generated Code">	 private void initComponents() {
jTextField1 = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jTextField2 = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jTextField3 = new javax.swing.JTextField();
label1 = new java.awt.Label();
label2 = new java.awt.Label();
label3 = new java.awt.Label();
label4 = new java.awt.Label();
jSeparator1 = new javax.swing.JSeparator();
jSeparator2 = new javax.swing.JSeparator();
		  setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);		  jTextField1.setText("jTextField1");
jTextField1.addActionListener(this);
jLabel1.setText("Value of Inventory");
jLabel2.setText("DVD Year");
jTextField2.setText("jTextField2");
jLabel3.setText("Restocking Fee");
jTextField3.setText("jTextField3");
label1.setText("label1");
label2.setText("label2");
label3.setText("label3");
label4.setText("label4");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());		 getContentPane().setLayout(layout); 
layout.setHorizontalGroup(			 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)			 .addGroup(layout.createSequentialGroup()				 .addContainerGap()				 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)					 .addGroup(layout.createSequentialGroup()						 .addComponent(jLabel1)						 .addGap(10, 10, 10)						 .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))					 .addGroup(layout.createSequentialGroup()						 .addComponent(jLabel2)						 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)						 .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))					 .addGroup(layout.createSequentialGroup()						 .addComponent(jLabel3)						 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)						 .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))					 .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)					 .addGroup(layout.createSequentialGroup()						 .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)						 .addGap(71, 71, 71)						 .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))					 .addGroup(layout.createSequentialGroup()						 .addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)						 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)						 .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))					 .addComponent(label4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))				 .addContainerGap(231, Short.MAX_VALUE))		 );
layout.setVerticalGroup(			 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)			 .addGroup(layout.createSequentialGroup()				 .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)				 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)				 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)					 .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)					 .addGroup(layout.createSequentialGroup()						 .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)						 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)						 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)							 .addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)							 .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))						 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)						 .addComponent(label4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)						 .addGap(61, 61, 61)						 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)							 .addComponent(jLabel1)							 .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))						 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)						 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)							 .addComponent(jLabel2)							 .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))						 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)						 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)							 .addComponent(jLabel3)							 .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))				 .addContainerGap(57, Short.MAX_VALUE))		 );		  pack();
	 }
 // Code for dispatching events from components to event handlers. 
public void actionPerformed(java.awt.event.ActionEvent evt) {		 if (evt.getSource() == jTextField1) {			 InventoryProgram.this.jTextField1ActionPerformed(evt);
		 }
	 }
// </editor-fold>
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {		 // TODO add your handling code here: 
	}
public static void main(String args[]) {		 java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new InventoryProgram().setVisible(true);
JFrame frame = new JFrame ("InventoryProgramSwing");
//Creates a JFrame		   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 //set to terminate the program when the window is closed. 
			}
		 });
	 }
	  // Variables declaration - do not modify
	 javax.swing.JLabel jLabel1;
	 javax.swing.JLabel jLabel2;
	 javax.swing.JLabel jLabel3;
	 javax.swing.JSeparator jSeparator1;
	 javax.swing.JSeparator jSeparator2;
	 javax.swing.JTextField jTextField1;
	 javax.swing.JTextField jTextField2;
	 javax.swing.JTextField jTextField3;
	 java.awt.Label label1;
	 java.awt.Label label2;
	 java.awt.Label label3;
	java.awt.Label label4;
	 // End of variables declaration


This post has been edited by Beachgirl029: 21 July 2009 - 11:53 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Java Inventory Part 4

#2 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 561
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: Java Inventory Part 4

Posted 21 July 2009 - 12:04 PM

You need to clean up your code a little first. Make sure your initComponents method is not opended up on a commented line. You shouldnt really be using a drop and drag editor, just makes the code so messy. To do what you want to do, just instantiate your other class
OtherClass myClass = new OtherClass();


And then use your getter methods in this other class to get your details
myClass.getName();


Bit hard to advise without the other class
Was This Post Helpful? 0
  • +
  • -

#3 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2495
  • View blog
  • Posts: 15,453
  • Joined: 24-September 08

Re: Java Inventory Part 4

Posted 21 July 2009 - 12:09 PM

Ewwwwwwwwwwwwwww drag and drop GUI? *pukes*

We should have some decent tutorials on GUI. Sun does too. You should look them up.
Was This Post Helpful? 0
  • +
  • -

#4 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 561
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: Java Inventory Part 4

Posted 21 July 2009 - 12:26 PM

View PostNeoTifa, on 21 Jul, 2009 - 11:09 AM, said:

Ewwwwwwwwwwwwwww drag and drop GUI? *pukes*

We should have some decent tutorials on GUI. Sun does too. You should look them up.


Your full of pukes today. Was looking at your last tutorial you came up with, thought it was very well written and perfect for newbies. Maybe when you get a bit of spare time you could do one for a basic intro into GUI. I would, but yesterday I told somone that they need to illiterate through their Array :rolleyes:
Was This Post Helpful? 0
  • +
  • -

#5 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2495
  • View blog
  • Posts: 15,453
  • Joined: 24-September 08

Re: Java Inventory Part 4

Posted 21 July 2009 - 01:02 PM

View Postnick2price, on 21 Jul, 2009 - 11:26 AM, said:

View PostNeoTifa, on 21 Jul, 2009 - 11:09 AM, said:

Ewwwwwwwwwwwwwww drag and drop GUI? *pukes*

We should have some decent tutorials on GUI. Sun does too. You should look them up.


Your full of pukes today. Was looking at your last tutorial you came up with, thought it was very well written and perfect for newbies. Maybe when you get a bit of spare time you could do one for a basic intro into GUI. I would, but yesterday I told somone that they need to illiterate through their Array :rolleyes:


Yea, I saw that. lol. Am planning on it. Right now I'm going through the Swing API and tutorials with a [pretty much] fine-toothed comb. Yep, GUI, Image, and Raster are my big 3 right now for my personal project I'm working on that I haven't told anyone about yet. I might just write tutorials along the way, who knows ^__^

This post has been edited by NeoTifa: 21 July 2009 - 01:03 PM

Was This Post Helpful? 0
  • +
  • -

#6 ladyinblack  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 9
  • View blog
  • Posts: 419
  • Joined: 08-April 09

Re: Java Inventory Part 4

Posted 21 July 2009 - 01:19 PM

Hi Beachgirl029,

I've been working with Netbeans GUI and I could probably help you here, since I'm helping my niece with her school project. I see you created three swing labels and four awt labels, but these awt labels are not allocated to anything. You've managed to label your swing labels, but do you have an inventory list already? What is this list file called? I need more information to help you out here. Cos all I see is you've designed your GUI already, but you are having a problem with coding the GUI.
Was This Post Helpful? 1
  • +
  • -

#7 Beachgirl029  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 07-July 09

Re: Java Inventory Part 4

Posted 21 July 2009 - 05:34 PM

I would love any help you will offer. What additional information do you need me to send you. Would you like the other classes I created for my Inventory Program in Java?


View Postladyinblack, on 21 Jul, 2009 - 12:19 PM, said:

Hi Beachgirl029,

I've been working with Netbeans GUI and I could probably help you here, since I'm helping my niece with her school project. I see you created three swing labels and four awt labels, but these awt labels are not allocated to anything. You've managed to label your swing labels, but do you have an inventory list already? What is this list file called? I need more information to help you out here. Cos all I see is you've designed your GUI already, but you are having a problem with coding the GUI.

Was This Post Helpful? 0
  • +
  • -

#8 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 725
  • View blog
  • Posts: 4,471
  • Joined: 24-October 08

Re: Java Inventory Part 4

Posted 21 July 2009 - 07:20 PM

no offense but the code is very difficult to read.. if you could clean it up and indent it properly i am willing to help you... for starters you may wanna check these out

http://java.sun.com/...ents/index.html
Was This Post Helpful? 0
  • +
  • -

#9 ladyinblack  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 9
  • View blog
  • Posts: 419
  • Joined: 08-April 09

Re: Java Inventory Part 4

Posted 22 July 2009 - 12:06 AM

View PostBeachgirl029, on 21 Jul, 2009 - 04:34 PM, said:

I would love any help you will offer. What additional information do you need me to send you. Would you like the other classes I created for my Inventory Program in Java?


View Postladyinblack, on 21 Jul, 2009 - 12:19 PM, said:

Hi Beachgirl029,

I've been working with Netbeans GUI and I could probably help you here, since I'm helping my niece with her school project. I see you created three swing labels and four awt labels, but these awt labels are not allocated to anything. You've managed to label your swing labels, but do you have an inventory list already? What is this list file called? I need more information to help you out here. Cos all I see is you've designed your GUI already, but you are having a problem with coding the GUI.


Hi, Ok send me the other classes you have.

Plus have a look at GUI Basics. Might help you understand a bit better, for the moment.

@mostyfriedman
Netbeans generates those wierd codes while dragging and dropping components, and there is no way to change or edit them to make it look neat, I've certainly tried. ( :angry: Imagine my frustration at the time)
Was This Post Helpful? 0
  • +
  • -

#10 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2495
  • View blog
  • Posts: 15,453
  • Joined: 24-September 08

Re: Java Inventory Part 4

Posted 22 July 2009 - 05:29 AM

First off, you're not supposed to solve programming problems via pm. What if other people needed the same help? Second, that's why you're supposed to hard code GUI yourself. New people should be banned from using DnD GUI. Until you learn how to do your own actionListeners and how everything works with eachother, you really have no business using that horrible cheating tool. NetBeans is evil in that regard, but that's still my IDE of choice ^__^
Was This Post Helpful? 0
  • +
  • -

#11 ladyinblack  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 9
  • View blog
  • Posts: 419
  • Joined: 08-April 09

Re: Java Inventory Part 4

Posted 22 July 2009 - 06:34 AM

Neotifa, you are one fun character.

For your assurance, I did not tell Beachgirl to pm me, and she did not yet.

Now, I totally agree with you on the use of Netbeans for first timer programmers. But would you believe, that in SA, high school students are being taught java using netbeans, damn sucks. The poor kids do not know the real code behind all this jargon of netbeans. And the SA govenrment calls this promoting IT, yeah right.
Was This Post Helpful? 0
  • +
  • -

#12 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2495
  • View blog
  • Posts: 15,453
  • Joined: 24-September 08

Re: Java Inventory Part 4

Posted 22 July 2009 - 07:17 AM

Our school teaches us using NetBeans.... We just don't use the cheating stuff. Actually, I just now realized it was there! :P I was wondering what everybody was talking about using some tool called GUI builder and such. I had never seen any such thing!

This post has been edited by NeoTifa: 22 July 2009 - 07:19 AM

Was This Post Helpful? 0
  • +
  • -

#13 Beachgirl029  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 07-July 09

Re: Java Inventory Part 4

Posted 22 July 2009 - 07:59 AM

I get an error when I try to PM you. I also get an error when I try to add you to my contacts so I will send you all my code this way.

Class Main.java

package InventoryProgram;

public class Main {
	
	public static void main(String[] args) {

		Product dvd = new Product ("Bye Bye Love", 1, 19.99, 3);
		System.out.println(dvd);

		dvd = new Product ("Fireside Rflections", 2, 12.99, 5);
		System.out.println(dvd);

		dvd = new Product ("Green Mile", 3, 24.99, 2);
		System.out.println(dvd);

		dvd = new Product ("Titanic", 4, 30.00, 10);
		System.out.println(dvd);

		System.out.println("Product Title is: " + dvd.getDvdTitle());
		System.out.println(" The item number is: " + dvd.getDvdItemNumber());
		System.out.println("The price of each DVD is $ " + dvd.getDvdPrice());
		System.out.println(" The number of units in stock is: "
				+ dvd.getDvdStockNumber());
	}//end main class
}//end Inventory Program Part 1

Class Product.java

package InventoryProgram;

public class Product {
//Product class holds product information
	
	private String dvdTitle;
	private int dvdItemNumber;
	private double dvdPrice;
	private int dvdStockNumber;
	
	public Product (String title, int itemNumber, double price, int stockNumber){
		//set four-argument constructor
		
		dvdTitle = title;
		dvdItemNumber = itemNumber;
		dvdPrice = price;
		dvdStockNumber = stockNumber;
	}//end Product constructor

	//set Product title
	public void setDVDTitle(String title){
		dvdTitle = title;
	}//end method set Product title

	//return Product title
	public String getDvdTitle(){
		return dvdTitle;
	}//end method getDVDtitle

	//set Dvd Item number
	public void setDvdItemNumber(int itemNumber){
		dvdItemNumber = itemNumber;
	}//end method set dvd item number

	//return dvd item number
	public int getDvdItemNumber(){
		return dvdItemNumber;
	}//end method get dvd item number

	//set Product Price
	public void setDvdPrice(double price){
		dvdPrice = price;
	}//end method set Product price

	//return Dvd Price
	public double getDvdPrice(){
		return dvdPrice;
	}//end method get dvd price

	//set Dvd Stock Number
	public void setDvdStockNumber(int stockNumber){
		dvdStockNumber = stockNumber;
	}//end method set dvd stock number

	//return dvd stock number
	public int getDvdStockNumber(){
		return dvdStockNumber;
	}//end method get Dvd stock number

	//Calculate inventory value
	public double Value(){
		return dvdPrice * dvdStockNumber;
	}//end set value method

	//String representation of Product
	@Override
	public String toString(){
		return dvdTitle + "-" + dvdPrice;
	}//end class Product Inventory Program Part 1
}

Class DVD.java

package inventoryprogram;

import InventoryProgram.Product;

public class DVD extends Product {
 //Inherites class DVD from the base class Product, the extra feature is having 
//a year the movie was made.
	private int movieyear;
	//Holds the year the movie was made

	public DVD(String title, int itemNumber, double price, int stockNumber, int year){
		//Constructor to call the Product constructor.
		super (title, itemNumber, price, stockNumber);
		movieyear = year;
	}
	public void setYear(int year){
		//Sets year
		movieyear = year;
	}
	public int getYear(){//get the year of the DVD product
		return movieyear;
	}
	public double getValue(){
		return super.Value()* 1.05;
	}//Overrides Value() in Product class by calling the base class and adding a
	//5% restocking fee on top

	public double getRestockingFee() {
		return super.Value() * .05;
	}//gets the base class value and figures out the restocking fee only
}

Class Inventory.java

package InventoryProgram;

import java.text.DecimalFormat;
//Import the format class to format values into currency format
public class Inventory {

	int inventorySize = 30;
	//This sets the Array to hold "30" items
	private Product items [] = new Product [inventorySize];

	DecimalFormat formatter = new DecimalFormat ("$##,###.00");
	//Sets the formatter to format values into currency form

	public void addDVD (Product item){
		for (int i =0; i< inventorySize; i++){
			if (items [i] == null){
				items [i] = item;
				return;
			}
		}
	}

	 // Loops through the array of products and adds up the total value.
	// Adds the value to a running total accumulator variable.

	public double getTotalInvValue(){
		double Value = 0.0;

	//Uses a comndensed for loop that iterates the array of items.
		for (Product item : items){
			if (item != null){
				Value += item.getDvdPrice();
			}
		}
		return Value;
	}
	//Prints the inventory list including name, quantity, price and total stock
	//value for each item.

	public void printInventory(){
		System.out.println("Printing items in inventory...\n");

		boolean DVDItems = false;

		for (Product item : items){
			if (item != null){
				DVDItems = true;
				System.out.println(item.getDvdTitle() + "Quantity: " 
						+ item.Value() + "Value of Stock: "
						+ formatter.format(item.Value()));
			}
		}
	}
}

Class InventoryProgram.java (my GUI)

package inventoryprogram;


import java.awt.event.ActionListener;
import java.awt.event.InputMethodListener;
import javax.swing.JFrame;

public class InventoryProgram extends javax.swing.JFrame implements ActionListener, InputMethodListener {

	public InventoryProgram() {
		initComponents();   
	}
OtherClass myClass = new OtherClass();


   
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jTextField1 = new javax.swing.JTextField();
		jLabel1 = new javax.swing.JLabel();
		jLabel2 = new javax.swing.JLabel();
		jTextField2 = new javax.swing.JTextField();
		jLabel3 = new javax.swing.JLabel();
		jTextField3 = new javax.swing.JTextField();
		label1 = new java.awt.Label();
		label2 = new java.awt.Label();
		label3 = new java.awt.Label();
		label4 = new java.awt.Label();
		jSeparator1 = new javax.swing.JSeparator();
		jSeparator2 = new javax.swing.JSeparator();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		addInputMethodListener(this);

		jTextField1.setText("jTextField1");
		jTextField1.addActionListener(this);

		jLabel1.setText("Value of Inventory");

		jLabel2.setText("DVD Year");

		jTextField2.setText("jTextField2");
		jTextField2.addActionListener(this);

		jLabel3.setText("Restocking Fee");

		jTextField3.setText("jTextField3");

		label1.setText("label1");

		label2.setText("label2");

		label3.setText("label3");

		label4.setText("label4");

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(
			layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addContainerGap()
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
					.addGroup(layout.createSequentialGroup()
						.addComponent(jLabel1)
						.addGap(10, 10, 10)
						.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
					.addGroup(layout.createSequentialGroup()
						.addComponent(jLabel2)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
						.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
					.addGroup(layout.createSequentialGroup()
						.addComponent(jLabel3)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
						.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
					.addGroup(layout.createSequentialGroup()
						.addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addGap(71, 71, 71)
						.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
					.addGroup(layout.createSequentialGroup()
						.addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
					.addComponent(label4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
					.addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
				.addContainerGap(231, Short.MAX_VALUE))
		);
		layout.setVerticalGroup(
			layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addContainerGap()
				.addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
				.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
					.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
					.addGroup(layout.createSequentialGroup()
						.addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
							.addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
							.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addComponent(label4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addGap(61, 61, 61)
						.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
							.addComponent(jLabel1)
							.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
							.addComponent(jLabel2)
							.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
							.addComponent(jLabel3)
							.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
				.addContainerGap(47, Short.MAX_VALUE))
		);

		pack();
	}

	// Code for dispatching events from components to event handlers.

	public void actionPerformed(java.awt.event.ActionEvent evt) {
		if (evt.getSource() == jTextField1) {
			InventoryProgram.this.jTextField1ActionPerformed(evt);
		}
		else if (evt.getSource() == jTextField2) {
			InventoryProgram.this.jTextField2ActionPerformed(evt);
		}
	}

	public void caretPositionchanged(java.awt.event.InputMethodEvent evt) {
	}

	public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
		if (evt.getSource() == InventoryProgram.this) {
			InventoryProgram.this.formInputMethodTextChanged(evt);
		}
	}// </editor-fold>

	private void formInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
		// TODO add your handling code here:
	}

	private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
myClass.getClass(Inventory){;
myClass.getName(Inventory){;


}
	}

private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {
	// TODO add your handling code here:
}

	
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new InventoryProgram().setVisible(true); 
				JFrame frame = new JFrame ("InventoryProgramSwing");
		//Creates a JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		  //set to terminate the program when the window is closed.
			}
		});
	}

	// Variables declaration - do not modify
	javax.swing.JLabel jLabel1;
	javax.swing.JLabel jLabel2;
	javax.swing.JLabel jLabel3;
	javax.swing.JSeparator jSeparator1;
	javax.swing.JSeparator jSeparator2;
	javax.swing.JTextField jTextField1;
	javax.swing.JTextField jTextField2;
	javax.swing.JTextField jTextField3;
	java.awt.Label label1;
	java.awt.Label label2;
	java.awt.Label label3;
	java.awt.Label label4;
	// End of variables declaration

}

Other Class.java (my GUI)

package inventoryprogram;

class OtherClass {
OtherClass myClass = new OtherClass();
	void getName() {
		myClass.getClass();
		myClass.getName();
	}
}






View Postladyinblack, on 21 Jul, 2009 - 11:06 PM, said:

View PostBeachgirl029, on 21 Jul, 2009 - 04:34 PM, said:

I would love any help you will offer. What additional information do you need me to send you. Would you like the other classes I created for my Inventory Program in Java?


View Postladyinblack, on 21 Jul, 2009 - 12:19 PM, said:

Hi Beachgirl029,

I've been working with Netbeans GUI and I could probably help you here, since I'm helping my niece with her school project. I see you created three swing labels and four awt labels, but these awt labels are not allocated to anything. You've managed to label your swing labels, but do you have an inventory list already? What is this list file called? I need more information to help you out here. Cos all I see is you've designed your GUI already, but you are having a problem with coding the GUI.


Hi, Ok send me the other classes you have.

Plus have a look at GUI Basics. Might help you understand a bit better, for the moment.

@mostyfriedman
Netbeans generates those wierd codes while dragging and dropping components, and there is no way to change or edit them to make it look neat, I've certainly tried. ( :angry: Imagine my frustration at the time)

Was This Post Helpful? 0
  • +
  • -

#14 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2495
  • View blog
  • Posts: 15,453
  • Joined: 24-September 08

Re: Java Inventory Part 4

Posted 22 July 2009 - 11:33 AM

First off, you can't send pm's because you don't have 10 posts yet. Second, you should make your variables more descriptive. Third, are you still using DnD GUI? For shame if you are. Fourth, why do you have your GUI in a class that is extending action performed or whatever? Fifth, why are you putting the whole package name in the code? :P you only need to say class x extends JFrame. As long as you have imported it, you only need the class you are extending.
Was This Post Helpful? 0
  • +
  • -

#15 ladyinblack  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 9
  • View blog
  • Posts: 419
  • Joined: 08-April 09

Re: Java Inventory Part 4

Posted 22 July 2009 - 11:53 AM

Ok now, Beachgirl, will get back to you. I have severe headache, well its slowly developing, gotta sleep it off, otherwise will get even worse in the morning. You know coding pretty well I see, so you just baffled by the GUI coding, not so difficult once you realise what you want to code. In the meantime, should you have time available, check out this tutorial,
http://www.dreaminco...wtopic17705.htm, available courtesy of SPlutard.
If you don't like reading, just go down to the the part where it says something about Components. Three main components which are mentioned and is a big part of all GUI programming and your program, is listed there.

@NeoTifa, like I said, Beachgirl has not done any coding for the GUI part of it yet, Netbeans did it automatically. How about this, do a short GUI, for your benefit, since you've just realised Netbeans GUI exists. Then you'll know the confusion.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2