|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

07-05-2008, 07:23 AM
|
|
Senior Member
|
|
Join Date: Mar 2008
Posts: 447
|
|
|
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, 08:21 AM
|
|
Member
|
|
Join Date: Jul 2008
Posts: 1
|
|
|
code
may i see what your code looks like?
|
|

07-05-2008, 08:28 AM
|
|
Senior Member
|
|
Join Date: Mar 2008
Posts: 447
|
|
Originally Posted by khai
may i see what your code looks like?
Thxs for responce
here is 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...
|
|

07-05-2008, 01:55 PM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: Southwest
Posts: 421
|
|
|
possible cause
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.
__________________
Please provide your feedback on our To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. .
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
|
|

07-05-2008, 02:46 PM
|
|
Senior Member
|
|
Join Date: Mar 2008
Posts: 447
|
|
Originally Posted by Nicholas Jordan
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
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..
|
|

07-05-2008, 03:21 PM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: SW MO, USA
Posts: 940
|
|
|
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, 03:42 PM
|
|
Senior Member
|
|
Join Date: Mar 2008
Posts: 447
|
|
Originally Posted by Norm
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..
Dru.setFont(f3);
Drw.setFont(f3);
JOptionPane.showMessageDialog(null,"HI It is last part to show in this Dialog");
plz help me
|
|

07-05-2008, 04:05 PM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: SW MO, USA
Posts: 940
|
|
|
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, 07:12 AM
|
|
Senior Member
|
|
Join Date: Mar 2008
Posts: 447
|
|
Originally Posted by Norm
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
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
|
|

07-07-2008, 07:20 PM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: Southwest
Posts: 421
|
|
|
handleEvent not switching on type of event
Originally Posted by Mir
(...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:
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:
if (evt.target instanceof Button)
Which also ( with logic that follows ) closes the window.
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.
__________________
Please provide your feedback on our To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. .
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
|
|

07-07-2008, 08:57 PM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: SW MO, USA
Posts: 940
|
|
|
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!!!
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|