The Artima Developer Community
Sponsored Link

Java Answers Forum
events in java

8 replies on 1 page. Most recent reply: Apr 22, 2002 12:12 PM by Aarti

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 8 replies on 1 page
Aarti

Posts: 6
Nickname: aarti
Registered: Apr, 2002

events in java Posted: Apr 5, 2002 3:26 PM
Reply to this message Reply
Advertisement
i have a big application with beginning with a GUI which in turn generates other GUI's .....so in one window the events fail to get enabled and the entire exectuin stops.. i have heard that calling a lot of events fills up the EVent dispatching queue and so no further events can be processed....how do i resolve this.....
plz help!


Thomas SMETS

Posts: 307
Nickname: tsmets
Registered: Apr, 2002

Re: events in java Posted: Apr 8, 2002 4:11 PM
Reply to this message Reply
Aarti,

Yes you are partly right ... It's possible to flood an EventQueue ! I however strongly believe you have a simple logic problem.

Could you proove me that the Events are not dispatched correctly ?

You should consider posting part of the code for us to have a look at it or give us more infos !

Thomas,

steve strongheart

Posts: 12
Nickname: stronghear
Registered: Apr, 2002

Re: events in java Posted: Apr 9, 2002 2:06 AM
Reply to this message Reply
Try writting a flow charts for the event sequences. This can get your logic down pat.

from the flow chart the program almost writes itself.

Aarti

Posts: 6
Nickname: aarti
Registered: Apr, 2002

Re: events in java Posted: Apr 18, 2002 11:47 AM
Reply to this message Reply
thank u for ur replies....
this is the code....i get the GUI to display but the events are not called..keep in mind that it is part of a big application........
package webprinter.collect.dbcollect;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;

import webprinter.collect.DocumentBoundaryCollector;


class GenerateTree extends Component implements MouseListener,ActionListener
{
private int pageCount;
private Vector co_Ordinates = new Vector();
private ArrayList pageList = new ArrayList();
private ArrayList pages = new ArrayList();
private Hashtable coodTable = new Hashtable();
private String label = "1";
private DBCollectorImpl collector;
private Graphics g;


GenerateTree(int count,DBCollectorImpl collector)
{
//adds listeners to the ovals
this.addMouseListener(this);
this.collector = collector;




//assigns count to page count to be used later for the number of ovals
pageCount = count;
Frame frame = new Frame("Tree Diagram of webpages") ;
frame.add(this);
//to close the window
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing (WindowEvent we)
{
System.exit(1);
}
} );

Button okButton = new Button("OK");
okButton.setActionCommand("OK");
okButton.addActionListener(this);
Button cancelButton = new Button("Cancel");
cancelButton.setActionCommand("Cancel");
cancelButton.addActionListener(this);

Panel buttonPanel = new Panel();
FlowLayout flow = new FlowLayout(FlowLayout.CENTER);
buttonPanel.setLayout(flow);
flow.setHgap(25);
buttonPanel.add(okButton);
buttonPanel.add(cancelButton);

frame.add(buttonPanel,"South");
frame.setSize( 400, 600 );

System.out.println("end of contrcutor");

//update(getGraphics());
frame.setVisible(true) ;
paint();

}


public void paint()
{
g = getGraphics();
int centerX = 200, centerY = 80, i;
int height = 80, width = 100, x = 190, x1 = 150;
System.out.println("in paint loop");

for( i = 1;i<=pageCount;i++)
{
g.setColor(Color.black);
g.drawOval(centerX, centerY, 40, 40);
g.setColor(Color.gray);
g.fillOval(centerX, centerY, 40, 40);
//add the co-ordinates with in a vector for comparison later
co_Ordinates.add(new OvalCord(centerX, centerY));

g.setColor(getForeground());
label = label.valueOf(i);
coodTable.put(new Integer(centerY),new Integer(label));
g.drawString(label.valueOf(i) , centerX+17, centerY+22 );
if(i<pageCount)
{
g.drawLine (centerX + 20,centerY+40,centerX+20,centerY+80);
g.drawLine (centerX + 20,centerY+80,centerX+30,centerY+70);
g.drawLine (centerX + 20,centerY+80,centerX+10,centerY+70);
//for drawings arcs on both sides
if( i % 2 ==0 )
{
g.drawArc(x, 100, width , height, -90, 180 );
}
else
{
g.drawArc(x1, 100, width , height, 90, 180 );
}
}

height = height + 80;
width = width + 60;
centerY = centerY + 80; x = x - 30;
x1 = x1 - 30;
}

System.out.println("end of paint loop"); }
public Dimension getPreferredSize()
{
Font f = getFont();
if( f != null )
{
FontMetrics fm = getFontMetrics( f );
int max = Math.max( fm.stringWidth(label)+10,
fm.getHeight()+10 );
return new Dimension( max, max );
}
else
{
return new Dimension( 100, 100 );
}
}

//mouse events
public void mouseClicked(MouseEvent me)
{

int x = me.getX();
int y = me.getY();
boolean doBreak = false;
for(int i=0; i<co_Ordinates.size(); i++)
{
OvalCord OC = (OvalCord) co_Ordinates.get(i); if ( x<OC.x+40 && x>OC.x)
{
if (y<OC.y+40 && y>OC.y)
{
Graphics g = getGraphics();
g.setColor( Color.black);
g.fillOval(OC.x,OC.y,40,40);
//get the number of the webpage that is clicked
Integer webpagesLabel = getLabels(new Integer(OC.y));
//add it to a vector
pages.add(webpagesLabel);
}
}
}
}
public void mouseEntered(MouseEvent me)
{
//System.out.println("SUCESS2");
}

public void mouseExited(MouseEvent me)
{
//System.out.println("SUCESS3");
}

public void mousePressed(MouseEvent me)
{

//System.out.println("SUCESS4");
}

public void mouseReleased(MouseEvent me)
{
//System.out.println("SUCESS5");
}

//action events for the 2 buttons
public void actionPerformed(ActionEvent ae)
{
String actionCommand = ae.getActionCommand();
if(actionCommand.compareTo( "Cancel" ) == 0 )
{
repaint();
}
if(actionCommand.compareTo( "OK" ) == 0 )
{
pageList = pages;
synchronized(collector){
collector.notify();}
}
}





//returns the label associated with the co-ordinates.
public Integer getLabels( Integer coods )
{
Integer number = (Integer)coodTable.get(coods);
return number;

}

public synchronized ArrayList getPagesList()
{
try
{
wait();
}
catch(InterruptedException ie)
{
ie.printStackTrace();
}
return pageList;

}
}

class OvalCord
{
public int x, y;

public OvalCord(int x, int y)
{
this.x = x;
this.y = y;
}

public String toString()
{
return "centerX = "+x+" centerY = "+y+ " | ";
}
};

Aarti

Posts: 6
Nickname: aarti
Registered: Apr, 2002

Re: events in java Posted: Apr 19, 2002 12:37 PM
Reply to this message Reply
actually what i do is call this class from the actionPeformed() of another button and this other class has to wait for a value from this class....which i think is the problem....i used wait and notify for the waiting thing....the code works well as itself but when i integrate it with the whole appilcation the execution halts....

Mohit Gupta

Posts: 15
Nickname: mohit
Registered: Mar, 2002

Re: events in java Posted: Apr 20, 2002 4:45 AM
Reply to this message Reply
actually things are not cleared to me about ur question, so just m giving suggestion after visualising that

r u trying somethings like.. u call this class methods, or this class from any other class's actionPerformed and expecting this class feedback to complete that actionPerformed, and in the meantime source class others event fire... if this is the problem. then it is obvious..

as when we call any long thread from any event, which take time to complete .. like show any dialog box etc, then this event pause temporarily and wait for that code to complete its work and in the mean time other events ,which are on queue, are fired.. which sometime we don't expect.

i myself not know its app soln. but u can just try thread.. invokeLater etc.. perhaps that can solve ur problem.

Aarti

Posts: 6
Nickname: aarti
Registered: Apr, 2002

Re: events in java Posted: Apr 20, 2002 1:45 PM
Reply to this message Reply
yes, i am calling the getPages() method of this class from another class....and the source class has to wait before it gets the value from this class....so i ahve used wait() - notify() for that....without using wait the events are enabled but the execution proceeds before i get the value of the pages and gives me a null pointer execution....is there any other method of making a method wait on some value from this class so that the events are not frozen

Thomas SMETS

Posts: 307
Nickname: tsmets
Registered: Apr, 2002

Re: events in java Posted: Apr 21, 2002 4:18 PM
Reply to this message Reply
Aarti could you make you post following the How to post ? (http://www.artima.com/forums/howtopost.html). I mean not only do we have to read +/-100 lines of codes un formatted while there is all the needed tool to make our life easy !!! :)
(Nothing personnal, he !)

Secondly I (should I say "we") don't have one of the imports :
import webprinter.collect.DocumentBoundaryCollector;


Tx for at least providing an implementation of the interface .... (so we can directly compile the thing )

Thomas,

Aarti

Posts: 6
Nickname: aarti
Registered: Apr, 2002

Re: events in java Posted: Apr 22, 2002 12:12 PM
Reply to this message Reply
sorry for all the trouble....i think i have figured out how to do it though....just copy-pasted a test version of the code while posting....was really frustrated last week....

Flat View: This topic has 8 replies on 1 page
Topic: Scrollbar - need help Previous Topic   Next Topic Topic: Some JVM Problem

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use