JButton

hi guy,

Thank you for taking your time to solve my problem. I doing a project, what my project does is that when a customer come to the shop to rent the movie. If the movie found and the customer want to rent the movie so it have to key in the customer detail using GUI(using JFrame) and it ask customer how many day do they want to rent (using JOptionPane)and then it display the movie, cost and customer after the display the movie status change from "available" to "rented out".

after enter the customer detail and it print the receipt( Example of movie title is crank ). Then after the printing the receipt the movie status change to 'rented out' . When serving the next customer, when enter the customer detail in GUI and click 'ok' it reset my crank movie status to 'available', by right should be 'rented out'. How to I stop the status from be reset to 'available'. Can someone help me out. Thank.......

here is the driver file(DvdUI.java):

import javax.swing.JOptionPane;

import javax.swing.JFrame;

class DvdUI

{

public static void main(String args[])

{

String movieTitle, output="", cusName, cusAddress, cusPhone;

final String title = "Odyssey Film Rental Pte Ltd";

Movie movie;

Customer customer;

int pressed;

DvdAdmin admin = new DvdAdmin();

JFrame GUI = new GuiTesting();

do

{

do

{

movieTitle = JOptionPane.showInputDialog(null,"Enter the movie title: ", title

, JOptionPane.PLAIN_MESSAGE);

movie = admin.findMovieTitle(movieTitle);

}while(movie==null);

output = "" + admin.showMovieDetails(movieTitle);

pressed = JOptionPane.showConfirmDialog(null, output +"\n\nDo you want to rental this movie? ",

title,JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);

}while(pressed == JOptionPane.NO_OPTION);

if (pressed == JOptionPane.YES_OPTION)

{

movie.setStatus("Rented out");

//GUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

GUI.setVisible(true);

try {

synchronized(GUI) {

System.out.println("Wait GUI");

GUI.wait();

System.out.println("GUI closed");

}

} catch (java.lang.InterruptedException ie) {

ie.printStackTrace();

} catch (Exception exp) {

exp.printStackTrace();

}

GUI.setFocusable(true);

// cusName = JOptionPane.showInputDialog(null, "Please enter the customer name: ",

title + " Customer detail", JOptionPane.QUESTION_MESSAGE);

// cusAddress = JOptionPane.showInputDialog(null, "Please enter the customer address: ",

title + " Customer detail", JOptionPane.QUESTION_MESSAGE);

// cusPhone = JOptionPane.showInputDialog(null, "Please enter the customer phone number: ",

title + " Customer detail", JOptionPane.QUESTION_MESSAGE);

//admin.NewCustomer(cusName, cusAddress, cusPhone);

//day = JOptionPane.showInputDialog(null, "Please enter the number of day to rent: ",

title, JOptionPane.QUESTION_MESSAGE);

}

System.exit(0);

}

}

Here is my Movie class:

public class Movie

{

private String movieTitle, catalogue, category, status;

private double cost;

public Movie(String cata, String bMovieTitle, double bCost, String bCategory, String bStatus)

{

movieTitle = bMovieTitle;

catalogue = cata;

cost = bCost;

category = bCategory;

status = bStatus;

System.out.println(movieTitle + "\t" + status);

}

public String getMovieTitle()

{

return movieTitle;

}

public String getCategory()

{

return category;

}

public String getCatalogue()

{

return catalogue;

}

public double getCost()

{

return cost;

}

public String getStatus()

{

return status;

}

public void setStatus(String newStatus)

{

status = newStatus;

System.out.println(movieTitle + "\t" + status);

}

public String toString()

{

String msg;

msg = "DVD title: " + movieTitle +

"\nCatalogue No: " + catalogue +

"\nCategory: " + category +

"\nCost: $" + cost +

"\nStatus: " + status;

return msg;

}

}

Here is my DVDAdmin class:

import javax.swing.JOptionPane;

public class DvdAdmin

{

private Movie[] movie;

private Customer customer;

public DvdAdmin()

{

movie = new Movie[15];

movie[0] = new Movie("C0001", "The OH in Ohio", 10, "Comedy", "Available");

movie[1] = new Movie("C0002", "Bring It On", 10, "Comedy", "Available");

movie[2] = new Movie("A0001", "Shrek", 5, "Aimation", "Available");

movie[3] = new Movie("A0002", "Joseph: King of Dreams", 5, "Aimation", "Available");

movie[4] = new Movie("A0003", "Barney's Great Adventure", 5, "Aimation", "Available");

movie[5] = new Movie("A0004", "Ice Age 2", 5, "Aimation", "Available");

movie[6] = new Movie("A0005", "A Bug's Life", 8, "Aimation", "Available");

movie[7] = new Movie("A0006", "We're back", 5, "Aimation", "Available");

movie[8] = new Movie("A0007", "Flushed Away", 10, "Aimation", "Available");

movie[9] = new Movie("A0008", "Over the Hedge", 5, "Aimation", "Available");

movie[10] = new Movie("T0001", "Operation Undercover", 10, "Thriller", "Available");

movie[11] = new Movie("T0002", "Inside Man", 8, "Thriller", "Available");

movie[12] = new Movie("T0003", "Hannibal", 5, "Thriller", "Available");

movie[13] = new Movie("T0004", "Crank", 10, "Thriller", "Available");

movie[14] = new Movie("T0005", "The Guardian", 10, "Thriller", "Available");

}

public Movie findMovieTitle(String bMovie)

{

int sizeOfMovie = movie.length;

String msg;

for( int i = 0; i < sizeOfMovie; i++)

{

if (movie.getMovieTitle().equalsIgnoreCase(bMovie))

{

return movie;

}//if

}//for

JOptionPane.showMessageDialog(null, "Movie title: " + bMovie + " not found",

"Odyssey Film Rental Pte Ltd", JOptionPane.INFORMATION_MESSAGE );

return null;

}//Movie

public String showMovieDetails(String bMovie)

{

Movie movie;

movie = findMovieTitle(bMovie);

return movie.toString();

}

public void NewCustomer(String cName, String cAddress, String cPhone)

{

Customer cus = new Customer(cName, cAddress, cPhone);

//cus(cName, cAddress, cPhone);

}

public String showCustomerDetail()

{

return customer.toString();

}

}

here is my customer class:

class Customer

{

private String name, address, phone;

public Customer(String aName, String aAddress, String aPhone)

{

name = aName;

address = aAddress;

phone = aPhone;

System.out.println(name + "\t" + address + "\t" + phone);

}

public String getName()

{

return name;

}

public String getAddress()

{

return address;

}

public String getPhone()

{

return phone;

}

public String toString()

{

String output;

output = "Customer name: " + name + "\n" +

"Customer address: " + address + "\n" +

"Customer Number: " + phone;

return output;

}

}

[7483 byte] By [Kleavea] at [2007-11-26 16:23:39]
# 1
[url http://forum.java.sun.com/help.jspa?sec=formatting]How to Post Code[/url]
camickra at 2007-7-8 22:47:28 > top of Java-index,Desktop,Core GUI APIs...
# 2
You also need to take a look [url= http://java.sun.com/docs/codeconv/]here[/url] and [url= http://homepage1.nifty.com/algafield/sscce.html]here[/url]
macrules2a at 2007-7-8 22:47:28 > top of Java-index,Desktop,Core GUI APIs...