Results 1 to 3 of 3
  1. #1
    Lidz is offline Member
    Join Date
    Feb 2011
    Posts
    1
    Rep Power
    0

    Default Action Perform functions giving me a ploblem pls help

    GUI Class


    /**
    * Linda Sikakane - 20720328
    *
    * DS4 Assignment 1
    *
    * DVD Class that is used to load DVD Information into an array
    * Adds a new DVD object into the end of the array
    * Displays all the DVD's in the array
    * Save DVD's in an array to a textfile
    * Exit GUI and terminate application
    **/

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Scanner.*;
    import java.io.*;
    import java.util.*;


    public class GUIDVD extends JFrame implements ActionListener
    {
    private int count = -1; //resets the number of dvd's
    GUIDVD [] aDVD = new GUIDVD [8]; //creates a partial array of 8 to store 4 dvd's

    //* Creates labels for the GUI
    JLabel mtL = new JLabel ("Movie Title :");
    JLabel yorL = new JLabel ("Year of Release :");
    JLabel ageL = new JLabel ("Age :");
    JLabel genreL = new JLabel ("Genre :");
    JLabel ptL = new JLabel ("Playing Times :");

    //* Creates Textfields for entering data

    JTextField mtT = new JTextField("", 30);
    JTextField yorT = new JTextField("", 5);
    JTextField ageT = new JTextField ("",3);
    JTextField genreT = new JTextField("",20);
    JTextField ptT = new JTextField("",5);


    JTextArea txtDisplay = new JTextArea(5,50);
    JScrollPane scroll = new JScrollPane(txtDisplay,ScrollPaneConstants.VERTICA L_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_ SCROLLBAR_ALWAYS);


    //* Creates Buttons for the GUI

    JButton load = new JButton("LOAD");
    JButton save = new JButton("SAVE");
    JButton add = new JButton ("ADD");
    JButton display = new JButton ("DISPLAY");
    JButton exit = new JButton ("EXIT");

    //* Creates the layout for the container
    JPanel p1 = new JPanel(new GridLayout (5,2));
    JPanel p2 = new JPanel(new GridLayout (1,5));
    JPanel pane = new JPanel(new BorderLayout());
    JPanel p3 = new JPanel(new BorderLayout ());



    public GUIDVD()
    {
    super("GUIDVD");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


    //* adds labels ,textfields and buttons to container
    p1.add(mtL);
    p1.add(mtT);

    p1.add(yorL);
    p1.add(yorT);

    p1.add(ageL);
    p1.add(ageT);


    p1.add(genreL);
    p1.add(genreT);


    p1.add(ptL);
    p1.add(ptT);

    pane.add(txtDisplay);

    p2.add(load);
    p2.add(save);
    p2.add(add);
    p2.add(display);
    p2.add(exit);

    p3.add("North",p1);
    p3.add("Center",pane);
    p3.add("South",p2);


    //* add listeners to buttons

    load.addActionListener(this);
    save.addActionListener(this);
    add.addActionListener(this);
    display.addActionListener(this);
    exit.addActionListener(this);


    setContentPane(p3);
    }


    public static void main(String[] args)
    {
    GUIDVD aFrame = new GUIDVD();

    //* sets the windows width and height
    aFrame.setSize(500,400);
    aFrame.setVisible(true);

    }

    public void Reload()
    {

    }

    public void actionPerformed(ActionEvent e)
    {

    //identifies which button is clicked
    Object s = e.getSource();

    //button exit clicked
    if (s == exit)
    System.exit (0); //terminates application

    if (s == load)
    {
    DVD.loadDVD(DVD completeDVDInventory[]);
    txtdisplay.setText("");
    //messageText1.setText("Default Vehicle Information has been successfully loaded");
    load.setEnabled(false);
    display.setEnabled(true);
    add.setEnabled(true);
    //sortButton.setEnabled(true);
    }

    if (s == display)
    {

    }

    if (s == add)
    {

    txtdisplay.setText("");
    //messageText1.setText("Clear text boxes and enter Vehicle Information");
    String mtitle =mtT.getText(); //local variable Manufacturer
    int year = yorT.getText();
    String age =ageT.getText(); //local variable Model
    String genre = genreT.getText();
    int ptime = ptimeT.getText(); //local variable Price
    DVD.addDVD(completeDVDInventory,mtitle,year,age,ge nre,ptime,arraycount);
    closeAddDVD();
    arraycount++;
    }

    if (s == save)
    {
    //PrintWriter outputS = null;
    try
    {
    //saves dvd array in textfile
    //outputS = new PrintWriter (New FileoutputStream("DVD.txt",true);
    BufferedWriter dwrite = new BufferedWriter(new FileWriter ("DVD.txt"));
    for (int i = 0; i < arraycount+1;i++)
    dWrite.write(completeDVDInventory[i].getString()) ;
    dWrite.close();


    }
    catch(EndOfFileExcption e)
    {
    JOptionPane.showMessageDialog("End of file inDVD.txt");
    }

    }
    }
    }




    DVD Class

    /**
    *The DVD CLASS
    * Keagen Reddy - 19951542
    *
    * DS4 Assignment 1
    *
    * Vehicles Class that is used to load Vehicle Information into an array by default
    * Also allowed to add Vehicles to the array
    * Display the unsorted array of Vehicles
    * Display a sorted array of Vehicles
    *
    **/
    import java.io.*;
    import java.util.Arrays;

    public class DVD implements Comparable
    {
    private String mtitle; //DVD movie title
    private int year; //DVD year of release
    private String age; //DVD Age classification
    private String genre; //DVD genre
    private int ptime; //DVD Playing Time in minutes



    public DVD() //default constructor
    {
    mtitle = " ";
    year = 0;
    age = " ";
    genre = " ";
    ptime = 0;
    }

    //contructor initialises DVD information
    public DVD(String mtitle, int year, String age, String genre, int ptime)
    {
    this.mtitle = mtitle;
    this.year = year;
    this.age = age ;
    this.genre = genre;
    this.ptime = ptime;
    }

    public void setDVDinfo(String mtitle, int year, String age, String genre, int ptime)
    {
    setMtitle(mtitle);
    setYearOfRelease(year);
    setAge(age);
    setGenre(genre);
    setPlayingTime(ptime);
    }

    public void setMtitle(String mtitle)
    {
    mtitle = mtitle;
    }

    public void setYearOfRelease(int year)
    {
    year = year ;
    }

    public void setAge(String age)
    {
    age = age ;
    }

    public void setGenre(String genre)
    {
    genre = genre ;
    }

    public void setPlayingTime(int ptime)
    {
    ptime = ptime ;
    }

    public String getmtitle()
    {
    return mtitle;
    }

    public int getyear()
    {
    return year;
    }

    //method to display DVD information
    public String displayDVD()
    {
    return ("Movie Title :" + mtitle +"\n Year Of Release :" + year + "\nAge :" + age + "\nGenre :" + genre+ "\nPlaying Times :" +ptime);

    }

    // method to display all DVD's in inventory in an unsorted order
    public static String displayTotalDVD( DVD completeDVDInventory[],int arraycount)
    {
    String textAreaText = "\nInventory of DVD (unsorted):\n";

    for ( int count = 0; count < arraycount; count++ )
    {
    textAreaText += "Item# "+ (count + 1)+"\n";
    textAreaText += completeDVDInventory[count].displayDVD()+"\n\n";
    } // end for

    return textAreaText;
    } // end displayTotalDVD

    public int compareTo(Object value)
    {
    DVD d = (DVD)value;
    int results = this.mtitle.compareTo(d.getmtitle());

    if (this.year == d.getyear())
    {
    results = 0;

    if (this.year > d.getyear())
    {
    results = +1;

    if (this.year < d.getyear())
    {
    results = -1;
    }
    }
    }

    return results;
    }

    // method to display all DVD's in inventory in a sorted order
    public static String sortedDVDInventory( DVD completeDVDInventory[],int arraycount )
    {
    DVD completeDVDInventory1[] = new DVD[arraycount];

    for ( int count = 0; count < arraycount; count++ )
    {
    completeDVDInventory1[count] = completeDVDInventory[count];
    }

    String textAreaText = "\nInventory of Vehicles (sorted):\n";
    Arrays.sort( completeDVDInventory1 ); // sort array

    for ( int count = 0; count < arraycount; count++ )
    {
    textAreaText += "Item# "+ (count + 1)+"\n";
    textAreaText += completeDVDInventory1[count].displayDVD()+"\n\n";
    } // end for
    return textAreaText;
    } // end sortedVehiclesInventory

    //Load default values into an array

    public static void loadDVD(DVD completeDVDInventory[])
    {
    completeDVDInventory[0] = new DVD("Valentines",2010,"PG 13","Romantic Comedy",108);
    completeDVDInventory[1] = new DVD("Disco night",2000,"NVL","Drama",110);
    completeDVDInventory[2] = new DVD("Takers",2011,"VLS","Thriller",120);
    completeDVDInventory[3] = new DVD("Dotters",1999,"Family","Adventure",99);

    }

    // add new DVD information to array
    public static void addDVD(DVD completeDVDInventory[],String mtitle,int year,String age,String genre,int ptime,int arraycount)
    {
    completeDVDInventory[arraycount] = new DVD(mtitle.toUpperCase(),year,age.toUpperCase(),ge nre,ptime);
    } // end addDVDs
    }






    I have to create a dvd class that has 5 attributes. The class is to implement the interface comparable. Comparable is to be implemented so that dvds are maintained in year order, and where the year is the same according to title.

    The gui program must have the following functionality:
    - Load dvds - create 4 dvd objects and place them in an array (hard coded)
    -display all dvds in an array
    -add new dvd object to the end of the array
    -save all the dvds in the array to textfiles
    -close the gui and terminate the application

  2. #2
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Wink

    Hey Linda,

    Please use Code Tags while posting your code. Or else, no one would be interested to stress their eyes, just to read such big code.

    And what is your problem by the way?

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Lidz View Post
    Java Code:
    /**
    *The DVD CLASS
    * Keagen Reddy - 19951542
    *
    * DS4 Assignment 1
    *
    * Vehicles Class that is used to load Vehicle Information into an array by default
    * Also allowed to add Vehicles to the array
    * Display the unsorted array of Vehicles
    * Display a sorted array of Vehicles
    *
    **/
    
    public class DVD implements Comparable
    [ ... ]
    The class API documentation for your DVD class doesn't make sense; fix that.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. How do I perform basic math with BigDecimals
    By s0meb0dy in forum New To Java
    Replies: 4
    Last Post: 09-26-2010, 12:32 PM
  2. Replies: 3
    Last Post: 08-19-2010, 08:27 AM
  3. My buttons all perform their action like 100 times
    By 711groove in forum New To Java
    Replies: 0
    Last Post: 12-13-2009, 10:49 AM
  4. Cannot perform a PING
    By mnementh64 in forum Networking
    Replies: 1
    Last Post: 09-17-2009, 04:39 PM
  5. Perform one action at a time
    By Melki in forum AWT / Swing
    Replies: 6
    Last Post: 12-08-2008, 07:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •