Results 1 to 11 of 11
  1. #1
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default Unexpected Error

    Hi all

    I am in big problem.When i run the code every thing is work fine.But when i run exe of this code then i am facing problem.What happen when i click on About Dialog then exe close autometically.All other menu is working..

    If any one need my code of About Dialog then i will give..

    Plz help me it's a urgent...

  2. #2
    khai is offline Member
    Join Date
    Jul 2008
    Posts
    1
    Rep Power
    0

    Default code

    may i see what your code looks like?

  3. #3
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by khai View Post
    may i see what your code looks like?
    Thxs for responce

    here is code

    Java Code:
    
    package main;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.Color;
    import java.awt.Cursor;
    import java.awt.Graphics;
    import javax.swing.JLabel;
    
    /*
     *
     * AboutDlg
     *
     */
    public class AboutDlg extends JDialog implements MouseListener 
    {
    	  private String URL = "http://www.yahoo.com";
    	  
    	  private String Email = "abc@yahoo.com";
    	  
    	  
    	  
    	public String getURL() {
            return URL;
         
    
        }
    	
    	  public void setURL(String URL) {
    	        this.URL = URL;
    	      
    	    }
    	  
    	  public void setEmail(String URL) {
    	        this.Email = Email;
    	        
    	    }
    	  
    	  
    	 
    	  
    
    	public AboutDlg(Frame parent)
    	{
    		super();
    		 
      
    	    JLabel Dru =  new JLabel( "                                      Email : abc@yahoo.com" , JLabel.LEFT);
    
    	     JLabel Drw =  new JLabel( "                                          http://www.yahoo.com" , JLabel.LEFT);
    	     
    	   
    	     AboutDlg.setDefaultLookAndFeelDecorated(true);
    	     
    	     this.setURL(URL);
    	     Drw.addMouseListener(this);
    	     Drw.setCursor(new Cursor(Cursor.HAND_CURSOR));
    	     Drw.setForeground(Color.BLUE);
    	     
    	     this.setEmail(Email);
    	     Dru.addMouseListener(this);
    	     Dru.setCursor(new Cursor(Cursor.HAND_CURSOR));
    	     Dru.setForeground(Color.BLUE);
    	     
    	    
    	
    	  	     
    	      Font f3= new Font("Terminal", Font.PLAIN, 12);
    	      
    	      
    	      
    	
    	      Dru.setFont(f3);
    	      Drw.setFont(f3);
    	      
    	     
    		setTitle( "About" ) ;
    	
    		setContentPane( new MyPanel() ) ;
    
    	    getContentPane().setLayout(new FlowLayout());   
    	   
    		
    	    
    	
    	
    		getContentPane().add(Drw );
    		getContentPane().add(Dru );
    		getContentPane().add( new Button("   OK   "));
    		
    
    
    		
    		setSize( 300 ,225 ) ;
    
    	
    		Point fatherLocation = parent.location();
    		move(fatherLocation.x + 150,fatherLocation.y + 200);
    		show();
    
    	}
    	
    	
    	 public void mouseClicked(MouseEvent e){
    	        try{
    	            String command = "start " + this.URL;
    	            Process process = Runtime.getRuntime().exec("cmd /c \"" + command + "\"");
    	          //Following line works as it should.
    	            
    	            Runtime.getRuntime().exec("cmd.exe /c start mailto:abc@yahoo.com");
    	    	
    
    	            
    	            
    	            
    	        } catch (Exception exception){
    	            System.out.println("Exception caught : " + exception.getMessage());
    	        }
    	    }
    	 
    	
    	 
    	 public void mouseEntered(MouseEvent e) {
    	    }
    
    	    public void mouseExited(MouseEvent e) {
    
    	    	
    	    }
    
    	    public void mousePressed(MouseEvent e) {
    	    	
    	    }
    
    	    public void mouseReleased(MouseEvent e) {
    	    }
    	    
    	    public void paint(Graphics graphis){
    	        super.paint(graphis);
    	        graphis.setColor(this.getForeground());
    	        graphis.drawLine(0, this.getHeight() - 1, this.getWidth(), this.getHeight() - 1);
    	    }
    
    	
    	public class MyPanel extends JPanel {
    		private Image img ;
    		public MyPanel() {
    			setLayout( new BorderLayout() ) ;
    			img = new ImageIcon("logod.jpg").getImage() ;
    		
    			if( img == null ) {
    				System.out.println( "Image is null" );
    				System.exit( 1 ) ;
    			}
    			if( img.getHeight(this) <= 0 || img.getWidth( this ) <= 0 ) {
    				System.out.println( "Image width or height must be +ve" );
    				System.exit( 2 ) ;
    			}
    		}
    		public void drawBackground( Graphics g ) {
    			int w = getWidth() ;
    			int h = getHeight() ;
    			int iw = img.getWidth( this ) ;
    			int ih = img.getHeight( this ) ;
    			for( int i = 0 ; i < w ; i+=iw ) {
    				for( int j = 0 ; j < h ; j+= ih ) {
    					g.drawImage( img ,0,9 , this ) ;
    				}
    						}
    		
    		}
    		protected void paintComponent(Graphics g) {
    			super.paintComponent(g);
    			Color underline = getForeground();
    
    			g.setColor(underline);
    
    			drawBackground( g ) ;
    		}
    	}
    	
    	
    
    	public boolean action (Event evt, Object arg)
    	{
    		if (evt.target instanceof Button)
    		{
    			hide();
    			dispose();
    			return true;
    		}
    		return false;
    	}
    	
    
    	private boolean updateDB()
    	{
    		
    		hide();
    		dispose();
    		return true;
    	}
    	public boolean handleEvent (Event event) 
    	{
    		switch (event.id) {
    		case Event.WINDOW_DESTROY:
    			dispose();
    			return true;
    		default:
    			return super.handleEvent(event);
    		}
    	}
    
    
    
    
    }
    Plz help me...

  4. #4
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default possible cause

    Java Code:
    public boolean action (Event evt, Object arg)
    {
        if (evt.target instanceof Button)
        {
            hide();
            dispose();
            return true;
        }
        return false;
    }
    If event is button, this closes the app.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  5. #5
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by Nicholas Jordan View Post
    Java Code:
    public boolean action (Event evt, Object arg)
    {
        if (evt.target instanceof Button)
        {
            hide();
            dispose();
            return true;
        }
        return false;
    }
    If event is button, this closes the app.
    Sir now i use this code

    Java Code:
    public boolean action (Event evt, Object arg)
    	{
    		if (evt.target instanceof Button)
    		{
    			if (evt.target == OK) {
    				return updateDB();
    			}
    			return false;
    
    		}
    		return false;
    
    	
    	}

    But problem is same.Plz help me to solve it..

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,458
    Rep Power
    25

    Default

    A suggestion to help YOU find your problem:
    Add println() statements before any statement that will dispose or exit and see if any of them are being executed.

  7. #7
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by Norm View Post
    A suggestion to help YOU find your problem:
    Add println() statements before any statement that will dispose or exit and see if any of them are being executed.
    Yes Norm I fiend it

    here is last line code is actually executed..

    Java Code:
     Dru.setFont(f3);
          Drw.setFont(f3);
    	      
     
     
     
    	 JOptionPane.showMessageDialog(null,"HI It is last part to show in this Dialog");
    plz help me

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,458
    Rep Power
    25

    Default

    Not sure what your problem is now if you've found it? What is it that you have found?

    What lines of code follows what you have posted as being
    "last line is actually executed"? Those lines sound like they could be important, but you left them off your post.

  9. #9
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by Norm View Post
    Not sure what your problem is now if you've found it? What is it that you have found?

    What lines of code follows what you have posted as being
    "last line is actually executed"? Those lines sound like they could be important, but you left them off your post.
    ok here i full line code

    Java Code:
    public AboutDlg(Frame parent)
    	{
    		super();
    		 
      
    	    JLabel Dru =  new JLabel( "                                      Email : abc@yahoo.com" , JLabel.LEFT);
    
    	     JLabel Drw =  new JLabel( "                                          http://www.yahoo.com" , JLabel.LEFT);
    	     
    	   
    	     AboutDlg.setDefaultLookAndFeelDecorated(true);
    	     
    	     this.setURL(URL);
    	     Drw.addMouseListener(this);
    	     Drw.setCursor(new Cursor(Cursor.HAND_CURSOR));
    	     Drw.setForeground(Color.BLUE);
    	     
    	     this.setEmail(Email);
    	     Dru.addMouseListener(this);
    	     Dru.setCursor(new Cursor(Cursor.HAND_CURSOR));
    	     Dru.setForeground(Color.BLUE);
    	     
    	    
    	
    	  	     
    	      Font f3= new Font("Terminal", Font.PLAIN, 12);
    	      
    	      
    	      
    	
    	      Dru.setFont(f3);
    	      Drw.setFont(f3);
    	 //     JOptionPane.showMessageDialog(null,"HI It is last part to show in this Dialog"); here the last line for execute the code..
    	     
    		setTitle( "About" ) ;
    	
    		setContentPane( new MyPanel() ) ;
    
    	    getContentPane().setLayout(new FlowLayout());   
    	   
    		
    	    
    	
    	
    		getContentPane().add(Drw );
    		getContentPane().add(Dru );
    		getContentPane().add( new Button("   OK   "));
    		
    
    
    		
    		setSize( 300 ,225 ) ;
    
    	
    		Point fatherLocation = parent.location();
    		move(fatherLocation.x + 150,fatherLocation.y + 200);
    		show();
    
    	}
    	
    	
    	 public void mouseClicked(MouseEvent e){
    	        try{
    	            String command = "start " + this.URL;
    	            Process process = Runtime.getRuntime().exec("cmd /c \"" + command + "\"");
    	          //Following line works as it should.
    	            
    	            Runtime.getRuntime().exec("cmd.exe /c start mailto:abc@yahoo.com");
    	    	
    
    	            
    	            
    	            
    	        } catch (Exception exception){
    	            System.out.println("Exception caught : " + exception.getMessage());
    	        }
    	    }
    	 
    	
    	 
    	 public void mouseEntered(MouseEvent e) {
    	    }
    
    	    public void mouseExited(MouseEvent e) {
    
    	    	
    	    }
    
    	    public void mousePressed(MouseEvent e) {
    	    	
    	    }
    
    	    public void mouseReleased(MouseEvent e) {
    	    }
    	    
    	    public void paint(Graphics graphis){
    	        super.paint(graphis);
    	        graphis.setColor(this.getForeground());
    	        graphis.drawLine(0, this.getHeight() - 1, this.getWidth(), this.getHeight() - 1);
    	    }
    
    	
    	public class MyPanel extends JPanel {
    		private Image img ;
    		public MyPanel() {
    			setLayout( new BorderLayout() ) ;
    			img = new ImageIcon("logod.jpg").getImage() ;
    		
    			if( img == null ) {
    				System.out.println( "Image is null" );
    				System.exit( 1 ) ;
    			}
    			if( img.getHeight(this) <= 0 || img.getWidth( this ) <= 0 ) {
    				System.out.println( "Image width or height must be +ve" );
    				System.exit( 2 ) ;
    			}
    		}
    		public void drawBackground( Graphics g ) {
    			int w = getWidth() ;
    			int h = getHeight() ;
    			int iw = img.getWidth( this ) ;
    			int ih = img.getHeight( this ) ;
    			for( int i = 0 ; i < w ; i+=iw ) {
    				for( int j = 0 ; j < h ; j+= ih ) {
    					g.drawImage( img ,0,9 , this ) ;
    				}
    						}
    		
    		}
    		protected void paintComponent(Graphics g) {
    			super.paintComponent(g);
    			Color underline = getForeground();
    
    			g.setColor(underline);
    
    			drawBackground( g ) ;
    		}
    	}
    	
    	
    
    	public boolean action (Event evt, Object arg)
    	{
    		if (evt.target instanceof Button)
    		{
    			hide();
    			dispose();
    			return true;
    		}
    		return false;
    	}
    	
    
    	private boolean updateDB()
    	{
    		
    		hide();
    		dispose();
    		return true;
    	}
    	public boolean handleEvent (Event event) 
    	{
    		switch (event.id) {
    		case Event.WINDOW_DESTROY:
    			dispose();
    			return true;
    		default:
    			return super.handleEvent(event);
    		}
    	}
    
    
    
    
    }
    JOptionPane.showMessageDialog(null,"HI It is last part to show in this Dialog");
    plz help me

  10. #10
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default handleEvent not switching on type of event

    Quote Originally Posted by Mir View Post
    (...snip...)What happen when i click on About Dialog then exe close autometically.All other menu is working..
    Norm, what is happening here is that window events and other events are processed in code by a mix of sub-typing ( class a instance of class b )? true/false and a java construct called a switch. A switch is an effective code construct for having the compiler create a jump table.

    Poster has:
    Java Code:
        public boolean handleEvent (Event event) 
        {
            switch (event.id) {
            case Event.WINDOW_DESTROY:
                dispose();
                return true;
            default:
                return super.handleEvent(event);
            }
        }
    Okay, sounds good but due to using event id, we should look at the value of Event.WINDOW_DESTROY as it should not be but may be numeric equivalent of some other class that is shipping an event to the code here.

    At least that is what it sounds like, based on poster's original description:
    when i click on About Dialog then exe close autometically.
    Above that, code shows:
    Java Code:
    if (evt.target instanceof Button)
    Which also ( with logic that follows ) closes the window.

    Java Code:
    public void mouseClicked(MouseEvent e){
    would process a mouse event to launch URL, but that is not shown in code.

    This project needs additional work disentangling event processing logic.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,458
    Rep Power
    25

    Default

    In the code you've posted I don't see any println() statements where there are possiblities of your program changing what is displayed. Ie before all dispose() statements.
    If you'd put these in your code, you might see what is happening.
    You need to do some work yourself to find your problem!!!

Similar Threads

  1. Error: unexpected type
    By silvia in forum New To Java
    Replies: 3
    Last Post: 02-05-2010, 09:54 PM
  2. Replies: 3
    Last Post: 12-30-2008, 10:58 AM
  3. error 530 error authentication required
    By rgale in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 05-12-2008, 04:28 PM
  4. An unexpected jumper bug on my IO code?
    By cruxblack in forum New To Java
    Replies: 7
    Last Post: 07-29-2007, 08:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •