JFrame

Hi guy,

I got some problem about the JFrame. I create the JFrame and when i run it, it load the Frame and it auto close by itself.

So I put this code :

JFrame GUI = new GuiTesting();

GUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GUI.setVisible(true);

the problem is still the same.

[324 byte] By [Kleavea] at [2007-11-26 15:47:53]
# 1
What do you mean when you say "auto close"?Kaj
kajbja at 2007-7-8 22:07:20 > top of Java-index,Java Essentials,New To Java...
# 2
Can you post your "GuiTesting" class?
ChrisLesliea at 2007-7-8 22:07:20 > top of Java-index,Java Essentials,New To Java...
# 3

This is a driver file:

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");

GUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

GUI.setVisible(true);

//GUI.setFocusable(true);

//String input = JOptionPane.showInputDialog("Hello");

}

System.exit(0);

}

}

This is GuiTesting

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 ClearButtonHandlercbHandler;

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

what this program does is that it when the customer request for the movie and if the customer want to rent the DVD movie it load the GUI to enter the customer detail. So the problem is that when it load the GUI, it appear momentary and then disappear. So do anyone can know how to stop it from be disappear? Thank guy..........

Message was edited by:

Kleave

Message was edited by:

Kleave

Kleavea at 2007-7-8 22:07:20 > top of Java-index,Java Essentials,New To Java...
# 4
Remove the call to System.exitKaj
kajbja at 2007-7-8 22:07:20 > top of Java-index,Java Essentials,New To Java...
# 5
Thank you.....
Kleavea at 2007-7-8 22:07:20 > top of Java-index,Java Essentials,New To Java...
# 6
i got one problem
Kleavea at 2007-7-8 22:07:20 > top of Java-index,Java Essentials,New To Java...
# 7
> i got one problemOk. We can't read you mind, so you have to say what the problem is.Kaj
kajbja at 2007-7-8 22:07:20 > top of Java-index,Java Essentials,New To Java...
# 8
In the future, Swing questions should be posted in the Swing forum.
CaptainMorgan08a at 2007-7-8 22:07:20 > top of Java-index,Java Essentials,New To Java...
# 9

i got one problem.I want the user to enter the customer detail first then do the next step(JOptionPane.showInputDialog("Please enter how many day you wish to rent: ")) but it load both GUI and the JOptionPane.showInputDialog on the screen. How do I load the GUI first and when the user click 'OK' it close the GUI then load the JOptionPane.showInputDialog

This is a update of driver file

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("Please enter how many day you wish to rent: ");

}

}

}

Thank for reading.....hope someone can help me this problem.

Kleavea at 2007-7-8 22:07:20 > top of Java-index,Java Essentials,New To Java...