Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Issue with JOptionPane showMessageDialog

  1. #1
    Member
    Join Date
    Jun 2014
    Posts
    77
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Default Issue with JOptionPane showMessageDialog

    Hi,

    I am wondering why , when I click on the "Add Student" button on the GUI,the message dialog is not popping up. I might be doing something wrong but can't figure it out.

    Thanks

     
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
     
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
     
     
    public class MainWindow extends JFrame implements ActionListener {
     
    	JButton addStudent = new JButton("Add Student");
    	JButton delStudent = new JButton("Delete Student");
    	JButton updateStudent = new JButton("Update Student");
    	JButton searchStudent = new JButton("Search Student");
    	JButton displayStudent = new JButton("Display Students");
     
    	JButton addCourse = new JButton("Add Course");
    	JButton delCourse = new JButton("Delete Course");
    	JButton updateCourse = new JButton("Update Course");
    	JButton searchCourse = new JButton("Search Course");
    	JButton displayCourse = new JButton("Display Courses");
     
     
    	 private class WindowDestroyer extends WindowAdapter 
    	  {
    		     public void windowClosing(WindowEvent e) 
    		     {
    		               System.exit(0); 
    		     } 
    		}
     
     
    	 public MainWindow(){
     
    		 super("Main Window");
    		 setSize(300,300);
    		 setLayout(new GridLayout(5,2));
    		 add(addStudent);
    		 add(addCourse);
    		 add(delStudent);
    		 add(delCourse);
    		 add(updateStudent);
    		 add(updateCourse);
    		 add(searchStudent);
    		 add(searchCourse);
    		 add(displayStudent);
    		 add(displayCourse);
    		 setVisible(true);
     
    	 }
     
     
     
    	@Override
    	public void actionPerformed(ActionEvent e) {
    		String action = e.getActionCommand().trim().toString();
     
    		switch(action){
    		case "Add Student" :   JOptionPane.showMessageDialog(addStudent, "add button pressed!");
    							   break;
     
    		case "Add Course" :     JOptionPane.showMessageDialog(addCourse, "add button pressed");
    						    	break;
    		case "Delete Student": JOptionPane.showMessageDialog(delStudent, "delete button pressed");
    							   break;
     
     
    		};
     
    	}
     
     
    	public static void main(String[] args) {
     
    	      MainWindow f = new MainWindow();
    		}
     
     
    }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Issue with JOptionPane showMessageDialog

    See the steps outlined in the following (specifically step 2):
    How to Write an Action Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)

Similar Threads

  1. Java Issue / Cache issue
    By VisualPK in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 14th, 2012, 08:43 PM
  2. String Formatting on JOptionPane.showMessageDialog
    By Onur in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 23rd, 2011, 08:39 AM
  3. Replies: 1
    Last Post: July 16th, 2011, 08:55 AM
  4. showMessageDialog is not showing!
    By jonathan920 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 27th, 2010, 04:14 AM
  5. "showMessageDialog" method in swing package
    By Delmi in forum Java Theory & Questions
    Replies: 1
    Last Post: May 13th, 2010, 02:52 PM

Tags for this Thread