6 Replies - 246 Views - Last Post: 30 May 2012 - 03:52 PM Rate Topic: -----

#1 justin_k  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 28-May 12

J.OptionPane Warning

Posted 30 May 2012 - 12:19 PM

Hey guys, first post here. Anyway, I'm doing some GUI homework and wondering where/how to implement a JOptionPane.WARNING_MESSAGE for an exit button on my GUI. my book isn't very helpful, and I'm a noob so I don't get what half the posts I search are even saying. Do I put it in the ActionPerformed area of my code? If you answer explain what and why. I'm not on here just to answer this, but why is the answer what you say it is. Here's the code and thank you if you answer.

		
		jbtExit.addActionListener(this);
	}//end the Public Bottom Panel
	
		public void actionPerformed (ActionEvent jbtExit) {
			System.exit(0);
			
	
		}//end actionPerformed for the exit button
	
	
}//end class

And like a noob, I left out my closing tag. Let's try this again.
	[code]	
		jbtExit.addActionListener(this);
	}//end the Public Bottom Panel
	
		public void actionPerformed (ActionEvent jbtExit) {
			System.exit(0);
			
	
		}//end actionPerformed for the exit button
	
	
}//end class


Is This A Good Question/Topic? 0
  • +

Replies To: J.OptionPane Warning

#2 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2774
  • View blog
  • Posts: 11,732
  • Joined: 20-September 08

Re: J.OptionPane Warning

Posted 30 May 2012 - 12:32 PM

Quote

wondering where/how to implement a JOptionPane.WARNING_MESSAGE for an exit button on my GUI.


What's the purpose of this?
Was This Post Helpful? 0
  • +
  • -

#3 bul2nmedown  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 25-May 12

Re: J.OptionPane Warning

Posted 30 May 2012 - 12:40 PM

There really isn't enough information here to work with. Are you trying to have it pop up with a warning window when the program is exited or what? Can you post full code
Was This Post Helpful? 0
  • +
  • -

#4 justin_k  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 28-May 12

Re: J.OptionPane Warning

Posted 30 May 2012 - 01:01 PM

View Postbul2nmedown, on 30 May 2012 - 12:40 PM, said:

There really isn't enough information here to work with. Are you trying to have it pop up with a warning window when the program is exited or what? Can you post full code


Yes, When the user hits the exit button I want the Window to display "Are you sure you want to exit?", along with yes and no buttons that are functionally correct of course. Here's the full code for the panel..
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.event.*;



public class BottomPanel extends JPanel{	
	
	public BottomPanel() {
	
		this.setLayout(new FlowLayout());
	
        //create the buttons for the bottom panel	
		JButton jbtExit = new JButton("Exit");
		JButton jbtFind = new JButton("Find");
		JButton jbtInsert = new JButton("Insert");
		JButton jbtUpdate = new JButton("Update");
		JButton jbtDelete = new JButton("Delete");
		
		//add colors to the buttons
		jbtExit.setBackground(Color.YELLOW);
		jbtFind.setBackground(Color.BLUE);
		jbtInsert.setBackground(Color.GREEN);
		jbtUpdate.setBackground(Color.WHITE);
		jbtDelete.setBackground(Color.RED);
		
		//give the buttons rollover text
		jbtExit.setToolTipText("Click here to exit the application");
		jbtFind.setToolTipText("Click here to search for your record");
		jbtInsert.setToolTipText("Click here to insert your data into the database");
		jbtUpdate.setToolTipText("Click here to update your record");
		jbtDelete.setToolTipText("Click here to erase your record");
		
	
		//implement the buttons	 
		this.add(jbtExit);
		this.add(jbtFind);
		this.add(jbtInsert);
		this.add(jbtUpdate);
		this.add(jbtDelete);	
		
		this.setBorder(new TitledBorder("Functional Buttons"));
		
		jbtExit.addActionListener(new ActionListener() {
		
			public void actionPerformed (ActionEvent e) {
			JOptionPane.showConfirmDialog(null, "Are you sure you want to Exit?" + e); 
			System.exit(0);
		}
		});
	
	}

}//end class

Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: J.OptionPane Warning

Posted 30 May 2012 - 01:14 PM

That should do it
public void actionPerformed (ActionEvent e) {  

            int ans = JOptionPane.showConfirmDialog(null, "Are you sure you want to Exit?" + e);   
             if(ans == JOptionPane.YES_OPTION)
                System.exit(0);  
         }  
         });  


Was This Post Helpful? 1
  • +
  • -

#6 justin_k  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 28-May 12

Re: J.OptionPane Warning

Posted 30 May 2012 - 01:17 PM

I actually got the Box to work, but your code helps me see how the button should function correctly. Thank You.
Was This Post Helpful? 0
  • +
  • -

#7 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2774
  • View blog
  • Posts: 11,732
  • Joined: 20-September 08

Re: J.OptionPane Warning

Posted 30 May 2012 - 03:52 PM

What are you going to do if the user clicks the normal window exit button?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1