JFrame and JOptionPane
843805Jan 23 2007 — edited Jan 29 2007hi 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".
Here is my problem:
1) When customer want to rent the movie it load GUI to enter the customer detail then follow by JOptionPane to ask the customer how many day to rent. But it load both the GUI and JOptionPane together on the screen. How do I load the GUI and enter the customer detail, when the user click "OK" and close then it load the JOptionPane.
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="", name, address, phone;
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");
//JFrame GUI = new GuiTesting();
GUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GUI.setVisible(true);
//GUI.setFocusable(true);
String input = JOptionPane.showInputDialog(null, "Please enter how many day you wish to rent: ");
}
}
}
here is the class file (GuiTesting.java):
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
class GuiTesting extends JFrame
{
private static final int width = 500;
private static final int height = 175;
private JLabel nameLabel, addressLabel, phoneLabel;
private JTextField nameTextField, addressTextField, phoneTextField;
private JButton okButton, clearButton;
private OkButtonHandler obHandler;
//private ClearButtonHandler cbHandler;
public GuiTesting()
{
setTitle("Customer Detail");
setSize(width,height);
Container pane = getContentPane();
GridLayout Layout = new GridLayout(4,3);
pane.setLayout(Layout);
nameLabel = new JLabel("Name: ");
addressLabel = new JLabel("Address: ");
phoneLabel = new JLabel("Phone: ");
nameTextField = new JTextField(30);
addressTextField = new JTextField(50);
phoneTextField = new JTextField(8);
okButton = new JButton("OK");
obHandler = new OkButtonHandler();
okButton.addActionListener(obHandler);
clearButton = new JButton("CLEAR");
//add components to the pane
pane.add(nameLabel);
pane.add(nameTextField);
pane.add(addressLabel);
pane.add(addressTextField);
pane.add(phoneLabel);
pane.add(phoneTextField);
pane.add(okButton);
pane.add(clearButton);
}//end constructor
private class OkButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String name;
DvdAdmin admin = new DvdAdmin();
name = nameTextField.getText();
admin.printCustomerName(name);
//String address;
//address = addressTextField.getText();
//String phone;
//phone = phoneTextField.getText();
}//method
}//class AcceptButtonHander
}//class GuiTesting
Sorry to take your time.......Thank you
Message was edited by:
Kleave