Results 1 to 11 of 11
Thread: Unexpected Error
- 07-05-2008, 06:23 AM #1
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
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...
- 07-05-2008, 07:21 AM #2
Member
- Join Date
- Jul 2008
- Posts
- 1
- Rep Power
- 0
code
may i see what your code looks like?
- 07-05-2008, 07:28 AM #3
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
Thxs for responce
here is code
Plz help me...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); } } }
- 07-05-2008, 12:55 PM #4
possible cause
If event is button, this closes the app.Java Code:public boolean action (Event evt, Object arg) { if (evt.target instanceof Button) { hide(); dispose(); return true; } return false; }Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 07-05-2008, 01:46 PM #5
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
- 07-05-2008, 02:21 PM #6
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.
- 07-05-2008, 02:42 PM #7
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
- 07-05-2008, 03:05 PM #8
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.
- 07-07-2008, 06:12 AM #9
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 6
ok here i full line code
JOptionPane.showMessageDialog(null,"HI It is last part to show in this Dialog");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); } } }
plz help me
- 07-07-2008, 06:20 PM #10
handleEvent not switching on type of event
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: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.Java Code:public boolean handleEvent (Event event) { switch (event.id) { case Event.WINDOW_DESTROY: dispose(); return true; default: return super.handleEvent(event); } }
At least that is what it sounds like, based on poster's original description:
Above that, code shows:when i click on About Dialog then exe close autometically.Which also ( with logic that follows ) closes the window.Java Code:if (evt.target instanceof Button)
would process a mouse event to launch URL, but that is not shown in code.Java Code:public void mouseClicked(MouseEvent e){
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
- 07-07-2008, 07:57 PM #11
Similar Threads
-
Error: unexpected type
By silvia in forum New To JavaReplies: 3Last Post: 02-05-2010, 09:54 PM -
An unexpected error has been detected by HotSpot Virtual Machine:
By 82rathi.angara in forum NetworkingReplies: 3Last Post: 12-30-2008, 10:58 AM -
error 530 error authentication required
By rgale in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 05-12-2008, 04:28 PM -
An unexpected jumper bug on my IO code?
By cruxblack in forum New To JavaReplies: 7Last Post: 07-29-2007, 08:24 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks