package testt;
import java.awt.*;
import java.lang.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;

public class Login extends JFrame implements ActionListener  {
//JFrame logframe = new JFrame();
JLabel am=new JLabel("Air-Malaysia....");
JLabel usrnm=new JLabel("Username : ");
JLabel nwm=new JLabel("Not yet a member? ");
JButton clk=new JButton("Click Here");
JLabel pswrd=new JLabel("Password : ");
JTextField txtname = new JTextField();
JPasswordField txtpswrd = new JPasswordField();
JButton btnOk=new JButton("Okay");
JButton btnCancel=new JButton("Exit");
Font f1 = new Font("TimesRoman",Font.BOLD,20);
Font f2 = new Font("TimesRoman",Font.BOLD,11);

    public Login() {
    setSize(400,400);
    setTitle("Air-Malaysia");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    java.awt.Container contents = getContentPane();
    contents.setLayout(null);
    contents.setLayout(null );
    contents.setBackground(Color.black);
    contents.setForeground(Color.orange);
     am.setFont(f1);
     usrnm.setFont(f2);
     clk.setFont(f2);
     clk.setBackground(Color.black);
     clk.setForeground(Color.orange);
     btnOk.setBackground(Color.black);
     btnOk.setForeground(Color.orange);
     btnCancel.setBackground(Color.black);
     btnCancel.setForeground(Color.orange);
     usrnm.setForeground(Color.orange);
     pswrd.setForeground(Color.orange);
     nwm.setForeground(Color.orange);
     am.setForeground(Color.orange);

    am.setLocation(100,0);
    am.setSize(150,150);
    contents.add(am);

        usrnm.setLocation(20,100);
    	usrnm.setSize(120,25);
    	add(usrnm);
        
        txtname.setLocation(100,100);
    	txtname.setSize(120,25);
    	add(txtname);

        pswrd.setLocation(20,150);
    	pswrd.setSize(120,25);
    	add(pswrd);

        txtpswrd.setLocation(100,150);
    	txtpswrd.setSize(120,25);
    	add(txtpswrd);

        nwm.setLocation(20,200);
    	nwm.setSize(120,25);
    	add(nwm);

        clk.setLocation(200,200);
    	clk.setSize(120,25);
    	add(clk);

        btnOk.setLocation(20,250);
    	btnOk.setSize(120,25);
    	add(btnOk);

        btnCancel.setLocation(200,250);
    	btnCancel.setSize(120,25);
    	add(btnCancel);
        btnOk.addActionListener(this);
        btnCancel.addActionListener(this);

    }

    public void actionPerformed(ActionEvent e){
        if(e.getSource()==btnOk)
        {
        JOptionPane.showMessageDialog(null, "Welcome Mr/Ms " + txtname.getText());
        this.dispose();
       // OptionWindow op = new OptionWindow();
        Flight fly = new Flight();
        fly.setVisible(true);
        }        
     if(e.getSource()==btnCancel)
         JOptionPane.showMessageDialog(null, "Thank You for using Air-Malaysia Online");
          System.exit(0);
}
 public static void main(String[] args) {
 //new Login();
 }
}
package testt;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.awt.*;
import java.lang.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;

public class OptionWindow extends JFrame implements ActionListener {
JFrame frame = new JFrame();
JButton btnexit = new JButton("Logout");
JButton b1 = new JButton("Customer Profile");
JButton b2 = new JButton("Flight Information");
JButton b3 = new JButton("Reservation");

    public OptionWindow() {
    frame.setVisible(true);
    frame.setSize(400,400);
    frame.setTitle("Air-Malaysia");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    java.awt.Container contents = getContentPane();
    contents.setLayout(null);  
    frame.add(contents);
    contents.setLayout(null );
    contents.setBackground(Color.black);
    contents.setForeground(Color.orange);
     b1.setBackground(Color.black);
     b1.setForeground(Color.orange);
     b2.setBackground(Color.black);
     b2.setForeground(Color.orange);
     b3.setBackground(Color.black);
     b3.setForeground(Color.orange);
     btnexit.setBackground(Color.red);
     btnexit.setForeground(Color.white);

        btnexit.setLocation(280,0);
        btnexit.setSize(80,25);
        add(btnexit);
         
        b1.setLocation(110,170);
    	b1.setSize(170,25);
    	add(b1);

        b2.setLocation(110,220);
    	b2.setSize(170,25);
    	add(b2);

        b3.setLocation(110,270);
    	b3.setSize(170,25);
    	add(b3);

        b1.addActionListener(this);
        b2.addActionListener(this);
        b3.addActionListener(this);
        System.out.println("baba");
        JOptionPane.showMessageDialog(null, "Thank You for using Air-Malaysia Online");
    }

    public void actionPerformed(ActionEvent e){
}
     public static void main(String[] args) {
         new OptionWindow();
 }// TODO overwrite start(), stop() and destroy() methods
}

Once i call the class OptionWindow from Login.java using the button. It calls the constructor of OptionWindow and then it dissappears...i tried using exit_on_close but its still not working...any ideas?...thanks...

NormR1 commented: Please don't start 2nd thread on same topic +0

Recommended Answers

All 3 Replies

Member Avatar for coil

Don't use EXIT_ON_CLOSE. Use setVisible(false) or dispose() . EXIT_ON_CLOSE, requires the user to actually close the frame.

Don't use EXIT_ON_CLOSE. Use setVisible(false) or dispose() . EXIT_ON_CLOSE, requires the user to actually close the frame.

hmm, yea i tried but its still the same outcome. i included a msgbox juz to slow its dissappearance...is there any other way to make the frame stay there....thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.