Problem on canvas

Hi
I an doing a game using swing.I kept a canvas and a panel on a frame.Panel is on the botton of the frame and canvas is on top of the frame.my canvas size is 240*270.when am drawing to canvas (i.e any shape like rectangle or circle) it is drawing perfectly.but when i am drawing an image some times it draw perfectly and some times it ignores it . if i minimize and then maximize the imaze comes
What may be the problem.I am giving my source code below.please some body tell me why it dopesn,t draw some time.
public class PokerGame extends Canvas implements ActionListener
String iconFile = "splash.png";
     Image image;
public PokerGame(CardWindow obj)
          super();
          loadImages();
          System.out.println("comming inside the constructor1 of pokergame");
          this.cardwindow = obj;
          counter = 0;
          width = 240 ;
          height = 270 ;
public void paint(Graphics g){
          drawGame(g);
private void drawGameTable(Graphics g){
     g.drawImage(image,0,0,null);
Thanks
Srikant

Don't use AWT components in a Swing application. Canvas is an AWT component. Use a JComponent or JPanel for custom painting. Also you should be overriding the paintComponent(..) method not paint().

Similar Messages

  • Problem with canvas area

    just installed final cut pro studio. started up fcp. did some settings for sequence. after import clip and moved over to the canvas area, there's an opaque overlay, which is transparent, on the video. do you know if this is because of the settings or a possibly a glitch in the software?

    i didn't apply any filter to the clip. but out of curiosity, i played with a few different filters. rendered the sequence. same problem. so i closed out fcp and started again. what do you know, the video in the canvas came back and is now normal viewing. i am still not sure what had happened, but hopefully, the problem won't come back again.
    thanks for all the help.

  • Problem with Canvas component.

    Hello all,
    I am building a sort of flowcharting software using Swing. The software is standalone. The "flowcharting" component is a sort of canvas, However it does not extend the Canvas class from AWT, but rather extends a JComponent. The paint() method simpy says g.fillRect(color) and this produces the backdrop. Ok, to the point, every once in a while, some components or text will not render at all on this canvas. If if I were to close and load the flowchart, the same component will not render, and usually it is text with user defined fonts that will not render. I would say they render correctly on 80% of the machines on which it has been installed. It may be a font problem, but other text with the same exact font will render. Assuming that the components are instructed to render(I am fairly convinced of this) are there any possible reasons that these components will not render. All components render on my machine, and some will not render on other machines. Has anyone ever dealt with anything like this? Perhaps my canvas should actually subclass Canvas from AWT? Any feedback is much appreciated.
    Thanks.

    Thanks,
    Actually, this canvas overrides the JComponent class and is not an AWT Canvas component. A couple of things I did notice however....
    Maybe overriding JPanel would be more suitable.
    Currently the paint() method is being overridden as opposed to the paintComponent() method. I think overriding paintComponent would be the right thing to do.
    Thanks for help anyways.

  • Problem in canvas window positioning

    Dear buddies,
    I'm using Dev-6i....whenever I minimize the MDI window of my forms and then maximize it, the canvas window is resized and moves upward and so its buttons toolbar which I created myself ( and not using built-in Default & Smart Bar) gets disappeared, so I've to double click on the title bar of that window to resize it and bring it on the actual position. Can anybody tell me that why is it happening & whats its remedy??? thanx

    it sounds, like you have a canvas-problem. maybe there are some elements (buttons, items, ...) which are displayed in the lower section of the form or in the right section.
    If you increase the canvas and window-size a little bit... is the problem then away?

  • Picture problem in canvas

    im doing a project for my school, and i imported some pictures. the first picture i imported looked fine, i adjusted the top and bottom so it would fit my widescreen video. when i go back to import another picture, it looks fine in the viewer, but when i add it to the timeline it shrinks to the middle and doesnt fill the canvas. i dont know if i did something, cause i went back (just to check) and put that first picture back on the timeline, and it did the same thing. so something changed between the first time i did it, and now..yes, i can still resize it in the canvas but im wondering why it wouldnt do it automatically like it did earlier. any help would be appreciated.. thanks..(sorry so detailed, but i wanted to make sure you knew what was going on)
    aaron

    that solves the problem, i was just curious why, but i guess you just have to adjust in the motion tab..good enough for me..thanks

  • Problems with canvas size in Photoshop.

    I just upgraded to CS Cloud. When I open images in Photoshop the canvas appears to be very large. So I tried cropping the image. When I go to the Image Size or Canvas Size the right size appears. However, on screen there is all of this white space that shows up. It's driving me crazy. Has anyone had this problem and know how to correct it?

    Or you have color for the document window area outside the document bounds set to white.
    Right click just outside the picture and see if selecting one the grays like light gray, makes a difference.

  • Problem using Canvas

    Im using Canvas in my application to allow the user to draw onto it using the mouse, to keep the drawn shapes I simply overrided the update() method with:
    public void update(Graphics g)
         paint(g);
    }But when I resize the frame or minimize/maximize the Canvas is cleared, is there a better way to do this? I need to store the content somewhere so I can eventually write it to a file.

    hello
    My application is like this...
    Free form drawing is allowed using mouse on canvas.Inthe mouse dragged event,iam storing all the coordinates(x,y) to reproduce the same drawing in another application.The problem is,when i minimizing or maximizing the window on which iam drawing, all the drawings is disappeared.How can use paint method here??Any help would be appreciated...
    Below is my code...
    public class class1 extends Frame implements MouseMotionListener,MouseListener {
    int p,q=0;
    int x1,y1,x2,y2;
    int oldx, oldy, newx,newy;
    int i1=0;
    Vector vx;
    Vector vy;
    Canvas cv;
    public class1() {
    vx=new Vector();
    vy=new Vector();
    setSize(500,500);
    setVisible(true);
    cv=new Canvas();
    cv.setSize(300,300);
    cv.setBackground(Color.cyan);
    add("North",cv);
    cv.addMouseListener(this);
    cv.addMouseMotionListener(this);
    public void mouseMoved(MouseEvent me1)..
    public void mousePressed(MouseEvent me1)..
    public void mouseClicked(MouseEvent me1)..
    public void mouseDragged(MouseEvent me2)
    x2=me2.getX();
    y2=me2.getY();
    Integer x3=new Integer(x2);
    Integer y3=new Integer(y2);
    vx.addElement(x3);
    vy.addElement(y3);
    newx=x2;
    newy=y2;
    try{
    Graphics g=cv.getGraphics();
    if(oldx==0 && oldy==0){
    oldx=newx;
    oldy=newy;
    g.drawLine(oldx,oldy,newx,newy);
    oldx=newx;
    oldy=newy;
    catch(Exception e)
    e.printStackTrace();
    i1++;
    public void mouseReleased(MouseEvent me2)
    oldx=0;
    oldy=0;
    public static void main(String str[])
    class1 c1=new class1();
    thanx in adavance
    sreeni

  • Problem: Scalable canvas with affine transformation

    I'm trying to create a canvas that can be scrolled and is scalable through affine transformations. This, I'm trying to achieve by adding a control component to an existing Canvas that listens for MouseEvents and masks the area outside the area defined by the canvas when the control component is created. The base for this component was http://gasi.ch/blog/zooming-in-flash-flex/.
    Next I'm explain how the component is supposed to work and then on to the problem.
    This is how the canvas is created. In the constructor MouseListeners and a mask canvas is added to dragCanvas.
              var canvasControl:MatrixCanvasMouseControl = new MatrixCanvasMouseControl(dragCanvas);
    The listeners work pretty much the same way as in the link I mentioned earlier. So on to the scaling which is the problem.
    The scaling is done by first scaling the dragCanvas with method scaleAt(...):
    /** START OF MOUSE WHEEL LISTENER */
              // CUT
              // get the mouseevent position in stage
              var eventStagePoint:Point = new Point();
                        eventStagePoint.x = event.stageX;
                        eventStagePoint.y = event.stageY;         
              // scale dragCanvas at that point with scaleAt
              scaleAt(canvas, zoomIn, zoomIn, canvas.globalToLocal(eventStagePoint).x, canvas.globalToLocal(eventStagePoint).y);       
              // CUT
    /** END OF MOUSE WHEEL LISTENER  */
             * Scales the matrix through affine transformation.
            public static function scaleAt(sprite:Sprite, scaleX:Number, scaleY:Number, originX:Number, originY:Number):void
                var translateMatrix:Matrix = sprite.transform.matrix;
                // move to origo to preserve form
                translateMatrix.translate(-originX, -originY);
                // scale the matrix
                translateMatrix.scale(scaleX, scaleY);
                // move back to originX, originY
                translateMatrix.translate(originX, originY);
                sprite.transform.matrix = translateMatrix;
    This scales the maskCanvas also. Next I'm trying to scale the maskCanvas back to it's original position by:
              MatrixHelper.scaleAt(maskCanvas, (1 / zoomIn), (1 / zoomIn), maskCanvas.globalToLocal(eventStagePoint).x * (1 / zoomIn), maskCanvas.globalToLocal(eventStagePoint).y * (1 / zoomIn));
    The problem is that when the Canvas is scaled, the mask  changes it's position when I try to scale it back to it's original size and position (as it's size and position changed when dragCanvas was scaled because maskCanvas is a child of dragCanvas).
    This might not be the best way to achieve scrolling. I also thought about extending Canvas and creating a parent Canvas that would contain dragCanvas and maskCanvas as it's children. That way scaling one would not affect the other. The problem with this was that I didn't find a way to do that without overriding Canvas functionality. If anyone knows and could explain how this could be done effectively for example by "decorating" it would be great.
    I would really appreciate if anyone could help me with this. I've struggled with it for quite a few hours already.
    I know I haven't explained everything clearly, so, please, ask me to clarify things more, if this was not understandable.
    Message was edited by: Kimmo Jokinen
    Message was edited by: Kimmo Jokinen

    OK, I found a hacky solution to my problem by going through every rawChildren of the canvas and then scaling it if it's id didn't match with the one I created in the mouseControl component.
    This does not seem like a very elegant way but at least it works.
    I'm pretty sure that this should be done whole differently architecturally but I'm not experienced enough to find that way.
    So this is how I did it.
    for (i = 0; i < canvas.rawChildren.numChildren; i++) {
         child = canvas.rawChildren.getChildAt(i) as Object;
         if (!child is DisplayObject) {
              continue;
         transformAllowed = false;
         displayChild = DisplayObject(child);
         if (displayChild.hasOwnProperty("id") && (displayChild["id"] == "maskCanvas" || displayChild["id"] == "mouseControlArea")) {    
              transformAllowed = false;                                   
         } else {
              transformAllowed = true;
         if (transformAllowed) {
              MatrixHelper.scaleAt(displayChild, zoomOut, zoomOut, canvas.globalToLocal(eventStagePoint).x, canvas.globalToLocal(eventStagePoint).y);

  • Problem getting canvas & timeline to display

    The timeline & canvas will not display when I open up FCE. FCE has worked great until now...
    FYI - I tried the following to correct this problem:
    1. Resetting the display mode (windows, arrange, standard & small windows). Note - The canvas & timeline listings in the drop down windows menu were unchecked & displayed in light gray.
    2. Reloaded FCE & checked for software updates.
    Any suggestions would be appreciated!!!
    Thanks in advance!
    Dan E.

    Hi Al -
    *Thank you very much! You solved my viewing problem!!!!*
    FYI - To ensure that I am able to view the sequence "automatically" every time I open up any of my clips, I will save each project when the sequence is opened.
    Not sure what I did differently to cause this to happen recently, but now the problem is solved.
    *Thanks Again!!*
    Regards-
    Dan E.

  • Problem refreshing canvas when multiple windows and canvasses.

    Ok I Have a form that has 2 windows and 2 canvases.
    They both get populated on When new Forms instance trigger with a parameter i pass in from teh previous form.
    On entering the form if the parameter is set (passed in by the form before) it should query the blocks on canvas 1 and display the second canvas/window via a seperate package of "canvas.open" which is a package to open and populate the second canvas which is a tree.
    If this code is fired on a key next item or a button press its fine. but not where it is on when new form instance trigger. The canvas.open simply stops on a synchronize early on. If i remove a sync then the second canvas never appears.
    You can see a commented out pause. If this is included then it all works fine. If i use a synchronize instead of the pause it doesnt even reach the canvas.open (i used messages on status to work this out)
    So my question is how can i get a synchronize to work as i assume this is whats missing?
    Any help much appreciated, Im sorry if i have not explained very well.
    IF :PARAMETER.I IS NOT NULL THEN                    
                   Go_Block('B1');               
                   Execute_Query(no_validate);
                   Go_Block('B2');
                   Execute_Query(no_validate);
    --PAUSE;
                   canvas.Open(:PARAMETER.I);                    
    END IF;          

    What happens if you do a
    IF :PARAMETER.I IS NOT NULL THEN                    
                   Go_Block('B1');               
                   Execute_Query(no_validate);
    SYNCHRONIZE;
                   Go_Block('B2');
                   Execute_Query(no_validate);
    SYNCHRONIZE;
                   canvas.Open(:PARAMETER.I);                    
    END IF;

  • Problem about canvas repaint!

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    class DrawPie extends Canvas{
    Container cont;
    public DrawPie(Container parent){
    cont=parent;
    public void addinContainer(){
    this.setSize(200,200);
    cont.add(this,BorderLayout.SOUTH);
    public void paint(Graphics g){
    g.drawString("This is test",20,20);
    public class WelFrame extends JFrame {
    JPanel contentPane;
    BorderLayout borderLayout1 = new BorderLayout();
    // Construct the frame
    public WelFrame() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
    jbInit();
    catch (Exception e) {
    e.printStackTrace();
    // Component initialization
    private void jbInit() throws Exception {
    Button btn=new Button("Open");
    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(borderLayout1);
    btn.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    btn_actionPerformed(e);
    contentPane.add(btn,BorderLayout.NORTH);
    this.setTitle("Welcome to JBuilder");
    this.setSize(new Dimension(400, 300));
    //Overridden so we can exit when window is closed
    protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
    System.exit(0);
    //File | Exit action performed
    public void jMenuFileExit_actionPerformed(ActionEvent e) {
    System.exit(0);
    void btn_actionPerformed(ActionEvent e) {
    DrawPie dp=new DrawPie(contentPane);
    dp.addinContainer();
    public static void main(String[] args){
    WelFrame wf=new WelFrame();
    wf.show();
    I can't get the text painted when click the button open.But when i resize the Frame,the text appeared.
    how can i get the text painted when i click the button open.Thanks a lot.

    When you add a component to another component, call it the parent component, AFTER YOU HAVE CONSTRUCTED THE PARENT COMPONENT, you need to call the method validate()on the parent component to insure that this component, the parent component, has a valid layout. In your code, you're adding your component which extends Canvas to the parent component which extends JFrame AFTER instanciating it. Hence, you need to call validate() on this parent right after adding the child component. In other words, your method btn_actionPerformed should look like the following:
    void btn_actionPerformed(ActionEvent e) {
    DrawPie dp=new DrawPie(contentPane);
    dp.addinContainer();
    validate(); //or this.validate();
    calling validate() will insure re-arrenging all children correctly according to the parent layout. When you resize your form, validate is called automatically and that's why the child component shows up.
    Without calling validate(), your newly added child component is not resized and located according to the parent layout. it's probably with the size 0,0 and that's why you're not seeing the text.
    I hope I explained it clearly enough

  • NEED HELP: Problem with Canvas Size in Crystal design/report.

    Hello,
         I am having some trouble with one of my reports, the canvas size is so much bigger than my design/report, which is causing it to preview really small.  I have gone into the document properties and tried to change those settings, I have also used the tools to try to make the canvas size smaller, it seems as thought nothing is really working.  When I use those tools it cuts off part of my report and also adds huge scroll bars into my design... Does anyone have any insight on this? It would be a great help.
    Thank you,
    Kerry Jenkins
    Harte-Hanks Analyst

    Hi Kerry,
    Are you using Crystal Reports Designer or BusinessObjects designer ( what ever it was called ) Crysstal Reports 5 was released in the summer of 1997 and definitely did not support a flash file.
    Need more info and details on the versions you are using and info on the Clients portal, Is it Businessobjects Enterprise 5.1?
    Thank you
    Don

  • Problem with Canvas method

    Hi,
    I'm new to Java and Java ME. I' m using jwt 2.5.2 for building and can't get rid of a compiler error. I have two classes: a driver class called TestCanvas which subclasses the MIDlet class and implements a CommandListener and a Canvas subclass called MyCanvas both in the same directory. Here is my code:
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    public class TestCanvas
        extends MIDlet implements CommandListener{
      public void startApp() {
        Displayable d = new MyCanvas();
        d.addCommand(new Command("Exit", Command.EXIT, 0));
        d.setCommandListener(this);
        Display.getDisplay(this).setCurrent(d);
        d.setMyvar(1);
      public void commandAction(Command c, Displayable d) {
           if (c.getCommandType() == Command.EXIT) notifyDestroyed();
      public void pauseApp() { }
      public void destroyApp(boolean unconditional) { }
    // Here code for MyCanvas class
    import javax.microedition.lcdui.*;
    public class MyCanvas
        extends Canvas {
      private int myvar = 0;
      public void setMyvar(int myvar){
      this.myvar = myvar;
      public void paint(Graphics g) {
        int w = getWidth();
        int h = getHeight();
        g.setColor(0,0,0);
        g.fillRect(0, 0, w, h);
        g.setColor(200,150,150);
    // draw stuff
        int z1 = w/2;
        int z2 =h/2;
        g.fillArc(z1-15, z2-15, 30, 30, 0, 360);
        g.fillArc(z1-20,z2-15,10,10,0,360); 
        g.fillArc(z1+10,z2-15,10,10,0,360); 
        g.setColor(0,0,0);
        g.fillArc(z1-8, z2-8,5,5,0,360); 
        g.fillArc(z1+3, z2-8,5,5,0,360);
        g.drawArc(z1-5,z2-5,10,10,0,360); 
        g.fillArc(z1-3,z2-2,3,3,0,360); 
        g.fillArc(z1,z2-2,3,3,0,360);
        g.drawArc(z1-5,z2+2,10,10,-180,180);
    } When I try to build, I get the error:
    Building "TestCanvas"
    /home/ivan/j2mewtk/2.5.2/apps/TestCanvas/src/TestCanvas.java:16: cannot find symbol
    symbol  : method setMyvar(int)
    location: class javax.microedition.lcdui.Displayable
        d.setMyvar(1);
         ^
    1 error
    com.sun.kvem.ktools.ExecutionException
    Build failedCan anybody help me? Can't really figure out why this souldn't work! The compiler doesn't complain about MyCanvas, hence the class is found but method not.
    Thanks in advance!!

    You have calledd.setMyvar (1);d is an instance of Displayable, not TestCanvas and the method is a method of TestCanvas.
    Since the call is in the same class, you can simply writesetMyvar (1);luck, db

  • Problem with canvas

    hiee
    I am in the process of creating a GUI for an Application similar to the PaintBrush. On clicking the 'New' option of the menubar a JInternal frame opens.now ,i want to add on to it a canvas. how do i do that. i have written a code for it but the canvas is not gettin added onto the internalframe.
    how do i add the canvas? please give suggestions.

    public class DrawingPanel extends JPanel
    public void paint(Graphics g)
    // your code or other method calls
    // Code to add JPanel
    JInternalFrame frame = new JInternalFrame("Title");
    frame.getContentPane().add(new DrawingPanel());

  • Problem with Canvas pointerDragged().

    Hi folks,
    I discovered that with my phone, when I drag my finger across the screen, although I get a steady stream of pointerDragged() calls initially, if I stop my finger (while continuing to press) and then start moving it again, there will be no more such events after the stop.
    So to review:
    1. Press finger
    2. Slide finger -> numerous pointerDragged events
    3. Stop finger but keep pressing
    4. Slide finger -> no pointerDragged events
    Is this a bug or by design, and how can I work around it?
    Thanks.

    Did you try to enable touch screen in WTK 2.2?
    If memory serves, this could be done by adding a line *touch_screen=true* *) to the file DefaultColorPhone.properties. This file is in the WTK installation folder, in subdirectory called like wtklib/device/DefaultColorPhone.
    As for behavior of 2.5.2, it does not look buggy to me, quite opposite. As long as file-access code is there, there should be prompts and permissions for it, even if you don't call that code. To get past these prompts, either set correct permissions (I think User Guide explains this in details) or remove the unused code that causes the prompts. As far as I recall, touch screen events worked perfectly fine for me with 2.5.2
    *) +...this could be done by adding a line touch_screen=true+ -- or by changing line touch_screen=false if it is present in properties file

Maybe you are looking for