Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Need help with programming (setting up GUI for program)

$
0
0
So my first homework was to create a program that creates a collection of items (I used a clothing collection) and each item has 5 attributes. That was fine but now my next assignment is to set up a GUI for the program. My professor did not go into much detail on how to setup GUI he just gave us the basic shell of it. I could really use an explanation of what each part of it does and where the GUI goes. Any help would be greatly appreciated.

Code given for GUI
import java.util.Scanner;
import java.awt.Dimension;
import java.io.*;
import javax.swing.*;
 public class Hw01 {
 
 public static void main(String[] args) throws IOException{
   JFrame frame = new JFrame ("Display File");
       frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
          JPanel panel1 = new JPanel();
       JTextArea ta = new JTextArea (20, 50);
          
     String  info="Hello";         
      //.....  code  to fill in info

    ta.setText (info);
   JScrollPane sp = new JScrollPane(ta);
   sp.setPreferredSize(new Dimension (400,100));
   panel1.add(sp);
   
      frame.getContentPane().add (panel1);
      frame.pack();
      frame.setVisible(true);
 }


My Program:
Driver Class
package HW01;
//HW01.java 	CS-185-01
//1/30/2013
//This program creates, modifies, and examines my clothing collection.

public class HW01 {

	public static void main(String[] args)
	{
		
		ClothingCollection clothes = new ClothingCollection();
		clothes.addClothing ("Blue Striped Polo", "Polo", 2009, 24.95, true);
		clothes.addClothing ("Grey Sweatshirt", "American Eagle", 2012, 31.50, false);
		clothes.addClothing ("Blue Sweatshirt", "Under Armor", 2008, 49.95, true);
		clothes.addClothing ("Jeans", "Abercrombie", 2010, 22.50, true);
		clothes.addClothing ("White T-Shirt", "Footlocker", 2011, 9.95, false);
		
		System.out.println (clothes);
		
		clothes.addClothing ("Striped Thermal", "American Eagle", 2012, 24.99, true);
		clothes.addClothing ("Black T-Shirt", "Polo", 2011, 12.95, false);
		
		System.out.println (clothes);
		
	}

}


Worker class i think?
package HW01;
//ClothingCollection.java 	CS-185-01
//1/30/2013
//Mark DelMonte
//This program Represents a collection of Clothing.
import java.text.NumberFormat;

public class ClothingCollection
{
	private Clothing[] collection;
	private int count;
	private double totalCost;
	//-----------------------------------------------------------------
	// Constructor: Creates an initially empty collection.
	//-----------------------------------------------------------------
	public ClothingCollection ()
	{
	collection = new Clothing[100];
	count = 0;
	totalCost = 0.0;
	}
	//-----------------------------------------------------------------
	// Adds a clothing to the collection, increasing the size of the
	// collection array if necessary.
	//-----------------------------------------------------------------
	public void addClothing (String title, String manufacturer, int year,
	double cost, boolean warm)
	{
	if (count == collection.length)
	increaseSize();
	collection[count] = new Clothing (title, manufacturer, year, cost, warm);
	totalCost += cost;
	count++;
	}
	//-----------------------------------------------------------------
	// Returns a report describing the Clothing collection.
	//-----------------------------------------------------------------
	public String toString()
	{
	NumberFormat fmt = NumberFormat.getCurrencyInstance();
	String report = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
	report += "My Clothing Collection\n\n";
	report += "Number of Clothess: " + count + "\n";
	report += "Total cost: " + fmt.format(totalCost) + "\n";
	report += "Average cost: " + fmt.format(totalCost/count);
	report += "\n\nClothing List:\n\n";
	for (int clothing = 0; clothing < count; clothing++)
	report += collection[clothing].toString() + "\n";
	return report;
	}
	//-----------------------------------------------------------------
	// Increases the capacity of the collection by creating a
	// larger array and copying the existing collection into it.
	//-----------------------------------------------------------------
	private void increaseSize ()
	{
	Clothing[] temp = new Clothing[collection.length * 2];
	for (int clothing = 0; clothing < collection.length; clothing++)
	temp[clothing] = collection[clothing];
	collection = temp;
	
	
	}
	
}


Class for attributes?
package HW01;
//Clothing.java 	CS-185-01
//1/30/2013
//Mark DelMonte
//This program Represents a piece of clothing
import java.text.NumberFormat;

public class Clothing
{
	private String title, manufacturer;
	private int year;
	private double cost;
	private boolean warm;
	//-----------------------------------------------------------------
	// Creates a new clothing with the specified information.
	//-----------------------------------------------------------------
	public Clothing (String title, String manufacturer, int year, double cost,
	boolean warm)
	{
	this.title = title;
	this.manufacturer = manufacturer;
	this.year = year;
	this.cost = cost;
	this.warm = warm;
	}
	//-----------------------------------------------------------------
	// Returns a string description of this clothing.
	//-----------------------------------------------------------------
	public String toString()
	{
	NumberFormat fmt = NumberFormat.getCurrencyInstance();
	String description;
	description = fmt.format(cost) + "\t" + year + "\t";
	description += title + "\t" + manufacturer;
	if (warm)
	description += "\t" + "Warm";
	return description;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getManufacturer() {
		return manufacturer;
	}
	public void setManufacturer(String manufacturer) {
		this.manufacturer = manufacturer;
	}
	public int getYear() {
		return year;
	}
	public void setYear(int year) {
		this.year = year;
	}
	public double getCost() {
		return cost;
	}
	public void setCost(double cost) {
		this.cost = cost;
	}
	public boolean isWarm() {
		return warm;
	}
	public void setWarm(boolean warm) {
		this.warm = warm;
	}
}

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>