codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  [GRAPHICS] - SymbolDesignerTool - URGENT HELP PLS  metan at 06:26 on Wednesday, March 15, 2006
 

Hi to all!
im a newbie in this forum so pls forgive my mistakes if any.
Coming to the question:

Im designing an symbol drawing tool. I ve buttons such as. circle. line. recttangle and so..
I created a JFrame, and build all my buttons, panels, and so into it by using JGoodies. (just a layout manager *www.JGoodies.com*) Anywayz. The important parts of the source are below:





public class MainWindowEngineeringTool extends JFrame implements ActionListener,ChangeListener,
WindowListener, MouseListener
{
// lot of button and panel definitions here
private JPanel mDrawingPnl = new JPanel(); // panel that the drawings will be in it.

pubic static void main(String[] args)
{
JFrame frame = new JFrame();
frame.setTitle("PLS HELP :)");
//setBounds...
//AlwaysOnTop
//resizable = false
frame.setDefaultCloseOperation(WindowConstraints.EXIT_ON_CLOSE);
JComponent panel = new MainWindowEngineeringTool().BuildPanel();
frame.getContentPane().add(panel);
frame.setVisible(true);
}

public MainWindowEngineeringTool() //CONST
{
super();
//some JGoodies related layout definitions
//all Listener implementations to the buttons.
//label and button initializations.

mDrawingPnl.addMouseListener(this);
mDrawingPnl.addMouseMotionListener(this);
mDrawingPnl.setDoubleBuffered(true);
}

public void stateChanged(ChangeEvent e) // Used for color selection
{
if(e.getSource() == mSelectedColor)
{
ColorSelectionModel model = (ColorSelectionModel)e.getSource();
mCurrentColor = model.getSelectedColor();
}
}

public void actionPerformed(ActionEvent e)
{
int returned = this.switchButton(e); // Just used for switch case below, to define what button is clicked.

switch(returned) // just some of the button actions
{
case 8: setShape(CIRCLE); //int parametered shape definer.
break;
case 10: setShape(ARROW);
break;
case 17: mColorDialog.setContentPane(mColorChooser);
mColorDialog.setTitle("Colors");
//setBounds
//setResizable false
//always on top
//visible true
break;
default: break;
}
}

public void setShape(shape_) {shape = shape_;}

public void paint(Graphics g)
{
//g.setColor(mCurrentColor); //throws exception here so İ commented it.
switch(shape)
{
case NONE: g.fillOval(prevX, prevY, 2,2); //simple brushing right?
break;
case CIRCLE: g.drawOval(prevX, prevY, lastX-prevX, lastY-prevY);
break;
//and the other shapes...
default: break;
}
}

public void mousePressed(MouseEvent e)
{
prevX=e.getX();
prevY=e.getY();
}

public void mouseDragged(MouseEvent e)
{
//some code for printing the mouse X and Y positions in the label.
lastX = e.getX();
lastY = e.getY();
prevX = lastX;
prevY = lastY;
}
}

I ve tried everything but I dont know why its not painting. There is a panel in the middle of the Frame where the painting should go. the listeners set to that panel. I've even tried calling paint in the mouseEvent methods. but none of them worked.

The big question is: how can I paint with mouse in the panel which is located in the frame?


Thanx for any replies.
Urgent Help needed.
Any helps are appriciated.
Best Regards
Metan.

  Re: [GRAPHICS] - SymbolDesignerTool - URGENT HELP PLS  metan at 06:29 on Thursday, March 16, 2006
 

Thanx on your helps.
It helped great, and I modified the source you give to me depending on my requiraments.

Now I have another question that:
I ve started painting very nice but, I dont know what I did but something happened and now i cant even run the program. it says unable to find main, and before that is gives an error like.
"NoClasDefFound: Exception in thread main"

why does it happen?
Neccessary code is belowç

public class MainEngineeringToolFrame extends JFrame implements ActionListener.
{
//Some Code...
public MainEngineeringToolFrame
{
super("HELP PLS");
System.out.println("**super passed");
setBounds(120,300,1024,428);
setResizable(false);
System.out.println("**next code: Set Visible true");
setVisible(true);
}

//Some Code...

public static void main(String[] args)
{
System.out.println("***Main function loaded.");
MainEngineeringToolFrame frame = new MainEngineeringToolFrame();
System.out.println("***Object created.");
// frame.setTitle
// frame.setResizable
// getContentPane
// add(....
setVisible(true);
}

}


This is my fiirst class.
I created another class for the panel. where painting will occur in it.
necessary code is below:

public class DrawingPanel extends JPanel implements MouseListener, MouseMotionListener
{
MainEngineeringToolFrame obj = new MainEngineeringToolFrame();

public DrawingPanel()
{
super();
addMouseListener(this);
addMouseMotionListener(this);
setLayout(null);
}

//paint func.
//implemented methods.
}


At the System Line it only prints

***Main function loaded.


What means it cant create an object from itself in the main class.
than program tries to build itself some time.
And gives an error message like:


Exception in thread "SyntheticImageGenerator" java.lang.OutOfMemmoryError: Java heap space.


I thought increasing the heap space in ecliopse from VM arguments in run properties window in arguments tag. where under Java Application (Im thinking u r familliar with eclipse.)

Why does it happpen? I thought this kind of exception may occur in an infiniteloop where infinite objects are created. Well I dont even have a loop or Im not creating infinite number of objects..

If you can help I will be very useful
Thanx for your helps.
appriciated.
best regards
metan

  Re: [GRAPHICS] - SymbolDesignerTool - URGENT HELP PLS  crwood at 16:49 on Thursday, March 16, 2006
 

Look at the constructor declaration in MainEngineeringToolFrame; it is incomplete.

public class MainEngineeringToolFrame extends JFrame implements ActionListener.
{
//constructor is a special method and requires "()" operator
public MainEngineeringToolFrame()
{

You are calling "setVisible" twice: in the constructor and in the "main" method.

Dont' do this:

public class DrawingPanel extends JPanel implements MouseListener, MouseMotionListener
{
MainEngineeringToolFrame obj = new MainEngineeringToolFrame();

The "obj" instance is not the same instance as the instance you created in the "main" method of MainEngineeringToolFrame and so will not have access to the information in the latter for use in DrawingPanel.
To get a reference of/for/to MainEngineeringToolFrame in DrawingPanel you can do something like this:

public class MainEngineeringToolFrame extends JFrame implements ActionListener.
{
DrawingPanel drawingPanel;

public MainEngineeringToolFrame()
{
drawingPanel = new DrawingPanel(this);
...

public class DrawingPanel extends JPanel implements MouseListener, MouseMotionListener
{
MainEngineeringToolFrame metf;

public DrawingPanel(MainEngineeringToolFrame metf)
{
this.metf = metf;
}

Now DrawingPanel has a reference to MainEngineeringToolFrame and can call methods and access instance variables in MainEngineeringToolFrame. MainEngineeringToolFrame can do the same with its reference to the DrawingPanel class with its instance variable "drawingPanel".
Besides an infinite loop, OutOfMemory error can be caused by things like poor construction code or calling "repaint" inside a "paint/paintComponent" method. Start commenting out code or removing class instantiations until you can isolate the trouble.

  Re: [GRAPHICS] - SymbolDesignerTool - URGENT HELP PLS  metan at 08:39 on Friday, March 17, 2006
 

Thank you very much!
You helped me a lot
it is now perfectly working.
Greatly appriciated.
Best regards
metan.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Digital.Canal.Software.V2013
•  Altair_HyperWorks_12.0.1_Win64
•  Global.mapper.V15.0
•  ESI.PAM-RTM.V2010.0
•  KISSsoft.03.2013E.SP5
•  Technical.Toolboxes.Pipeline.Toolbox.2013.Enterprise.v15.0.0
•  Simprotek.Simprosys.V3.0
•  Ricardo.SABR.V6.0p1
•  PSIM.V9.2


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2013