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());

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.

  • 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

  • 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 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 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

  • Problem with RGB Values for Canvas Type ‚Horizontal Toolbar' in Webforms 10

    Hello,
    I have a problem with the canvas type ‘Horizontal Toolbar’ in Webforms 10g.
    When I try to set or change the RGB value of a ‘Horizontal Toolbar’ with the forms function
    Set_Canvas_Property(‘my_horizontal_toolbar’, BACKGROUND_COLOR, rgb-value)
    (at runtime) it has no effect in Webforms 10g for the canvas type ‘Horizontal Toolbar’ (the background color of the horizontal toolbar doesn’t change).
    But it works fine for other canvas types like ‘Stacked’ or ‘Content’.
    In Oracle 6i (Client / Server) this function works quiet well (even for the ‘Horizontal Toolbar’ canvas type).
    The reason why we are using rgb values instead of visual attributes in this case is, that the color of the ‘Horizontal Toolbar’ should be customizeable (via a RGB Field) for our customers (at runtime).
    Further more we are using the same technique for Text-Field-Items, Content- and Stacked-Canvases (and all works fine).
    Maybe it has something to do with the pre-configured IAS color-schema (blaf).
    But changing the color schema (e.g.: from 'blaf' to 'red') has no effect also.
    Thanks for your help.

    This is probably bug 777312. Call Support for the latest info on this bug and for help getting it fixed.

  • Problems with getWidth() and getHeight() in class Canvas

    Hi,
    i am developing MIDlets with Sun Studio4 One Update1 (Mobile Edition). Here is a simple example Code for my Problem:
    class MyCanvas extends Canvas
        public void paint(Graphics g)
            //Clear the Display
            g.setColor(0,0,0); //black
            g.fillRect(0,0,getWidth(),getHeight());
    }If i try to execute the Program with the Default Color Phone emulator included with Suns WTK2.0, everything works fine. (Ive tried to print out the results of getWidth() and getHeight() on the console, everything ok, the Displays width and height is displayed.).
    The problem is, that any other emulator from WTK1.0.4_01 (included with Sun Studio4 ME) compiles and preverifies fine, but while running the application, the emulator quits with the following error:
    ALERT: No such method getWidth.()I
    Execution completed successfully
    Anyone has an idea?
    Thanks!!

    Hello,
    I'm having the exact same problem and I'd like to know what changes you made to your code to get it working. My class is not an inner class and is very much like yours and so follows the form:
    class MyCanvas extends Canvas{ 
    int element = getWidth()/10;
    public void paint(Graphics g) {        //Clear the Display  
    g.setColor(0,0,0); //black
    g.fillRect(0,0,getWidth(),getHeight());
    I am also using WTK104. I did not have this problem until I renamed my file. I carried the renaming throughout the rest of the file in a consistent fashion and I don't see any problems with it. Any help appreciated.

  • 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);

  • Advance level drawing problem with Jframe and JPanel need optimize sol?

    Dear Experts,
    I m trying to create a GUI for puzzle game following some kind of "game GUI template", but i have problems in that,so i tried to implement that in various ways after looking on internet and discussions about drawing gui in swing, but i have problem with both of these, may be i m doing some silly mistake, which is still out of my consideration. please have a look at these two and recommend me one of them, which is running without problems (flickring and when you enlarge window the board draw copies (tiled) everywhere,
    Note: i don't want to inherit jpanel or Jframe
    here is my code : import java.awt.BorderLayout;
    public class GameMain extends JFrame {
         private static final long serialVersionUID = 1L;
         public int mX, mY;
         int localpoints = 0;
         protected static JTextField[][] squares;
         protected JLabel statusLabel = new JLabel("jugno");
         Label lbl_score = new Label("score");
         Label lbl_scorelocal = new Label("local score");
         protected static TTTService remoteTTTBoard;
         // Define constants for the game
         static final int CANVAS_WIDTH = 800; // width and height of the game screen
         static final int CANVAS_HEIGHT = 600;
         static final int UPDATE_RATE = 4; // number of game update per second
         static State state; // current state of the game
         private int mState;
         // Handle for the custom drawing panel
         private GameCanvas canvas;
         // Constructor to initialize the UI components and game objects
         public GameMain() {
              // Initialize the game objects
              gameInit();
              // UI components
              canvas = new GameCanvas();
              canvas.setPreferredSize(new Dimension(CANVAS_WIDTH, CANVAS_HEIGHT));
              this.setContentPane(canvas);
              this.setDefaultCloseOperation(EXIT_ON_CLOSE);
              this.pack();
              this.setTitle("MY GAME");
              this.setVisible(true);
         public void gameInit() {     
         // Shutdown the game, clean up code that runs only once.
         public void gameShutdown() {
         // To start and re-start the game.
         public void gameStart() {
         private void gameLoop() {
         public void keyPressed(KeyEvent e) {
         public void keyTyped(KeyEvent e) {
         public void gameKeyReleased(KeyEvent e) {
              PuzzleBoard bd = getBoard();
              for (int row = 0; row < 4; ++row) {
                   for (int col = 0; col < 4; ++col) {
                        if (e.getSource() == squares[row][col]) {
                             if (bd.isOpen(col, row)) {
                                  lbl_score.setText("Highest Score = "
                                            + Integer.toString(bd.getPoints()));
                                  setStatus1(bd);
                                  pickSquare1(col, row, squares[row][col].getText()
                                            .charAt(0));
         protected void pickSquare1(int col, int row, char c) {
              try {
                   remoteTTTBoard.pick(col, row, c);
              } catch (RemoteException e) {
                   System.out.println("Exception: " + e.getMessage());
                   e.printStackTrace();
                   System.exit(1);
         // method "called" by remote object to update the state of the game
         public void updateBoard(PuzzleBoard new_board) throws RemoteException {
              String s1;
              for (int row = 0; row < 4; ++row) {
                   for (int col = 0; col < 4; ++col) {
                        squares[row][col].setText(new_board.ownerStr(col, row));
              lbl_score.setText("Highest Score = "
                        + Integer.toString(new_board.getPoints()));
              setStatus1(new_board);
         protected void setStatus1(PuzzleBoard bd) {
              boolean locals = bd.getHave_winner();
              System.out.println("local win" + locals);
              if (locals == true) {
                   localpoints++;
                   System.out.println("in condition " + locals);
                   lbl_scorelocal.setText("Your Score = " + localpoints);
              lbl_score
                        .setText("Highest Score = " + Integer.toString(bd.getPoints()));
         protected PuzzleBoard getBoard() {
              PuzzleBoard res = null;
              try {
                   res = remoteTTTBoard.getState();
              } catch (RemoteException e) {
                   System.out.println("Exception: " + e.getMessage());
                   e.printStackTrace();
                   System.exit(1);
              return res;
         /** Custom drawing panel (designed as an inner class). */
         class GameCanvas extends JPanel implements KeyListener {
              /** Custom drawing codes */
              @Override
              public void paintComponent(Graphics g) {
                   // setOpaque(false);
                   super.paintComponent(g);
                   // main box; everything placed in this
                   // JPanel box = new JPanel();
                   setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
                   // add(statusLabel, BorderLayout.NORTH);
                   // set up the x's and o's
                   JPanel xs_and_os = new JPanel();
                   xs_and_os.setLayout(new GridLayout(5, 5, 0, 0));
                   squares = new JTextField[5][5];
                   for (int row = 0; row < 5; ++row) {
                        for (int col = 0; col < 5; ++col) {
                             squares[row][col] = new JTextField(1);
                             squares[row][col].addKeyListener(this);
                             if ((row == 0 && col == 1) || (row == 2 && col == 3)
                             || (row == 1 && col == 4) || (row == 4 && col == 4)
                                       || (row == 4 && col == 0))
                                  JPanel p = new JPanel(new BorderLayout());
                                  JLabel label;
                                  if (row == 0 && col == 1) {
                                       label = new JLabel("1");
                                       label.setHorizontalAlignment(JLabel.LEFT);
                                       label.setVerticalAlignment(JLabel.TOP);
                                  else if (row == 4 && col == 0) {// for two numbers or
                                       // two
                                       // blank box in on row
                                       label = new JLabel("2");
                                       label.setHorizontalAlignment(JLabel.LEFT);
                                       label.setVerticalAlignment(JLabel.TOP);
                                  else if (row == 1 && col == 4) {
                                       label = new JLabel("3");
                                       label.setHorizontalAlignment(JLabel.LEFT);
                                       label.setVerticalAlignment(JLabel.TOP);
                                  else if (row == 4) {
                                       label = new JLabel("4");
                                       label.setHorizontalAlignment(JLabel.LEFT);
                                       label.setVerticalAlignment(JLabel.TOP);
                                  else {
                                       label = new JLabel("5");
                                       label.setHorizontalAlignment(JLabel.LEFT);
                                       label.setVerticalAlignment(JLabel.TOP);
                                  label.setOpaque(true);
                                  label.setBackground(squares[row][col].getBackground());
                                  label.setPreferredSize(new Dimension(label
                                            .getPreferredSize().width, squares[row][col]
                                            .getPreferredSize().height));
                                  p.setBorder(squares[row][col].getBorder());
                                  squares[row][col].setBorder(null);
                                  p.add(label, BorderLayout.WEST);
                                  p.add(squares[row][col], BorderLayout.CENTER);
                                  xs_and_os.add(p);
                             } else if ((row == 2 && col == 1) || (row == 1 && col == 2)
                                       || (row == 3 && col == 3) || (row == 0 && col == 3)) {
                                  xs_and_os.add(squares[row][col]);
                                  // board[ row ][ col ].setEditable(false);
                                  // board[ row ][ col ].setText("");
                                  squares[row][col].setBackground(Color.RED);
                                  squares[row][col].addKeyListener(this);
                             } else {
                                  squares[row][col] = new JTextField(1);
                                  // squares[row][col].addActionListener(this);
                                  squares[row][col].addKeyListener(this);
                                  xs_and_os.add(squares[row][col]);
                   this.add(xs_and_os);
                   this.add(statusLabel);
                   this.add(lbl_score);
                   this.add(lbl_scorelocal);
              public void keyPressed(KeyEvent e) {
              public void keyReleased(KeyEvent e) {
                   gameKeyReleased(e);
              public void keyTyped(KeyEvent e) {
         // main
         public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                   @Override
                   public void run() {
                        new GameMain();
      thanks a lot for your time , consideration and efforts.
    jibby
    Edited by: jibbylala on Sep 20, 2010 6:06 PM

    jibbylala wrote:
    thanks for mentioning as i wasn't able to write complete context here.Yep thanks camickr. I think that Darryl's succinct reply applies here as well.

  • Design problem with JScrollPane

    First, I have problems with english. I hope u understand without problems that Im trying to say here. Sorry about that.
    Mi problem is whit a JScrollPane. I want to put an image whit a predefined size for draw inside it. I dont have any information about it, just the size. I want to put it in a JPane. The best choice is use the JPane area. The problem is that I want to use a JScrollPane because the image is bigger that the visualization area.
    Im unable to put a Canvas in the ScrollPane, or a JPane whit a predefined size or an image whit a predefined size. Im sure that is a design problem. Somebody can tell me something I can start whit? What do u think is better choice to put inside a JScrollPane?
    I dont send any source code because I dont have anything else that is show in the example.
    Gracias.

    import java.awt.*;
    import javax.swing.*;
    import java.net.URL;
    public class Test extends JFrame {
      String url = "http://www.sandbox-usa.com/images/product_images/2piece_16.gif";
      public Test() {
    //    System.getProperties().put( "proxySet", "true" );  // uncomment if you have proxy
    //    System.getProperties().put( "proxyHost", "myproxy.mydomain.com" ); // Your proxyname/IP
    //    System.getProperties().put( "proxyPort", "80"); // Sometimes 8080   
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   
        Container content = getContentPane();
        try {
          Image i = Toolkit.getDefaultToolkit().getImage(new URL(url));
          JLabel jl = new JLabel(new ImageIcon(i));
          content.add(new JScrollPane(jl), BorderLayout.CENTER);
          setSize(200, 200);   
          setVisible(true); 
        } catch (Exception e) { e.printStackTrace(); }
      public static void main(String[] args) { new Test(); }
    }

  • Problem with ScrollPane and JFrame Size

    Hi,
    The code is workin but after change the size of frame it works CORRECTLY.Please help me why this frame is small an scrollpane doesn't show at the beginning.
    Here is the code:
    import java.awt.*;
    public class canvasExp extends Canvas
         private static final long serialVersionUID = 1L;
         ImageLoader map=new ImageLoader();
        Image img = map.GetImg();
        int h, w;               // the height and width of this canvas
         public void update(Graphics g)
            paint(g);
        public void paint(Graphics g)
                if(img != null)
                     h = getSize().height;
                     System.out.println("h:"+h);
                      w = getSize().width;
                      System.out.println("w:"+w);
                      g.drawRect(0,0, w-1, h-1);     // Draw border
                  //  System.out.println("Size= "+this.getSize());
                     g.drawImage(img, 0,0,this.getWidth(),this.getHeight(), this);
                    int width = img.getWidth(this);
                    //System.out.println("W: "+width);
                    int height = img.getHeight(this);
                    //System.out.println("H: "+height);
                    if(width != -1 && width != getWidth())
                        setSize(width, getHeight());
                    if(height != -1 && height != getHeight())
                        setSize(getWidth(), height);
    }I create frame here...
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.JFrame;
    public class frame extends JFrame implements MouseMotionListener,MouseListener
         private static final long serialVersionUID = 1L;
        private ScrollPane scrollPane;
        private int dragStartX;
        private int dragStartY;
        private int lastX;
        private int lastY;
        int cordX;
        int cordY;
        canvasExp canvas;
        public frame()
            super("test");
            canvas = new canvasExp();
            canvas.addMouseListener(this);
            canvas.addMouseMotionListener(this);
            scrollPane = new ScrollPane();
            scrollPane.setEnabled(true);
            scrollPane.add(canvas);
            add(scrollPane);
            setSize(300,300);
            pack();
            setVisible(true);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        public void mousePressed(MouseEvent e)
            dragStartX = e.getX();
            dragStartY = e.getY();
            lastX = getX();
            lastY = getY();
        public void mouseReleased(MouseEvent mouseevent)
        public void mouseClicked(MouseEvent e)
            cordX = e.getX();
            cordY = e.getY();
            System.out.println((new StringBuilder()).append(cordX).append(",").append(cordY).toString());
        public void mouseEntered(MouseEvent mouseevent)
        public void mouseExited(MouseEvent mouseevent)
        public void mouseMoved(MouseEvent mouseevent)
        public void mouseDragged(MouseEvent e)
            if(e.getX() != lastX || e.getY() != lastY)
                Point p = scrollPane.getScrollPosition();
                p.translate(dragStartX - e.getX(), dragStartY - e.getY());
                scrollPane.setScrollPosition(p);
    }...and call here
    public class main {
         public main(){}
         public static void main (String args[])
             frame f = new frame();
    }There is something I couldn't see here.By the way ImageLoader is workin I get the image.
    Thank you for your help,please answer me....

    I'm not going to even attempt to resolve the problem posted. There are other problems with your code that should take priority.
    -- class names by convention start with a capital letter.
    -- don't use the name of a common class from the standard API for your custom class, not even with a difference of case. It'll come back to bite you.
    -- don't mix awt and Swing components in the same GUI. Change your class that extends Canvas to extend JPanel instead, and override paintComponent(...) instead of paint(...).
    -- launch your GUI on the EDT by wrapping it in a SwingUtilities.invokeLater or EventQueue.invokeLater.
    -- calling setSize(...) followed by pack() is meaningless. Use one or the other.
    -- That's not the correct way to display a component in a scroll pane.
    Ah, well, and the problem is that when you call pack(), it retrieves the preferredSize of the components in the JFrame, and you haven't set a preferredSize for the scroll pane.
    Please, for your own good, take a break from whatever it is you're working on and go through The Java&#8482; Tutorials: [Creating a GUI with JFC/Swing|http://java.sun.com/docs/books/tutorial/uiswing/TOC.html]
    db

  • Problem with repaint of display after a click event

    Hi,
    I have a problem with repaint of display. In particular in method keyPressed() i inserted a statement that, after i clicked bottom 2 of phone, must draw a string. But this string doesn't drawing.
    Instead if i reduce to icon the window, which emulate my application, and then i enlarge it, i see display repainted with the string.
    I don't know why.
    Any suggestions?
    Please help me.

    modified your code little
    don't draw in keyPressed
    import java.io.IOException;
    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Graphics;
    import javax.microedition.lcdui.Image;
    public class PlayerCanvas extends Canvas implements CommandListener{
         Display display;
         Displayable dsp11;
    private Image play, pause, stop, next, previous = null;
    private int gamcode;
    private Command quitCmd = new Command("Back", Command.ITEM, 1);
    public PlayerCanvas(Display display,Displayable dsp11){
         this.display =display;
         this.dsp11 =dsp11;
         addCommand(quitCmd);
         createController();
         setCommandListener(this);
         display.setCurrent(this);
              protected void paint(Graphics g)
              g.setColor(255,200,150);
              g.fillRect(0, 0, getWidth(), getHeight());
              if (play != null){
              g.drawImage(play, getWidth()/5, getHeight()-50, Graphics.BOTTOM | Graphics.HCENTER);
              if (stop != null){
              g.drawImage(stop, getWidth()/5, getHeight()-10, Graphics.BOTTOM | Graphics.HCENTER);
              if (next != null){
              g.drawImage(next, (getWidth()/5)+10, getHeight()-30, Graphics.BOTTOM | Graphics.LEFT);
              if (previous != null){
              g.drawImage(previous, (getWidth()/5)-30, getHeight()-30, Graphics.BOTTOM | Graphics.LEFT);
                   /////this will draw on key UP
                   g.setColor(0,0,0);
                   System.out.print(gamcode);
                   if(gamcode==Canvas.UP){
                        g.drawString("PROVA",10, 0, 0);
                   }else if(gamcode==Canvas.DOWN){
                        g.drawString("DIFFERENT",10, 30, 0);     
    private void createController()
    try {
    play = Image.createImage("/icon3.png");//replace your original images plz
    pause = Image.createImage("/icon3.png");
    stop = Image.createImage("/icon3.png");
    next = Image.createImage("/icon3.png");
    previous = Image.createImage("/icon3.png");
    } catch (IOException e) {
    play = null;
    pause = null;
    stop = null;
    next = null;
    previous = null;
    if (play == null){
    System.out.println("cannot load play.png");
    if (pause == null){
    System.out.println("cannot load pause.png");
    if (stop == null){
    System.out.println("cannot load stop.png");
    if (next == null){
    System.out.println("cannot load next.png");
    if (previous == null){
    System.out.println("cannot load previous.png");
              protected void keyPressed(int keyCode)
                   repaint();
                   if ( (keyCode == 2) || (UP == getGameAction(keyCode)) ){
                        gamcode = UP;
                        repaint();
                        else if ( (keyCode == 8) || (DOWN == getGameAction(keyCode)) ){
                             gamcode =DOWN;
                             repaint();
              else if ( (keyCode == 4) || (LEFT == getGameAction(keyCode)) ){
              else if ( (keyCode == 6) || (RIGHT == getGameAction(keyCode)) ){
              public void commandAction(Command arg0, Displayable arg1) {
                   // TODO Auto-generated method stub
                   if(arg0==quitCmd){
                        display.setCurrent(dsp11);
    }

  • Problem with busy cursor

    IHey there,
    i have a popping up window in my Flex app. This window needs a little time to get created. In this time I want to set the Cursor to busy. But instead of the busy cursor Flex displays no cursor, also the arrow cursor disappears.
    I tried the hack with callLater but it doesn't help. Had anyone a similar problem and knows how to fix it?
    By the way: What is the best way to set the busy cursor? Static, with the parentApplication.cursoManager property or in the component with this.cursoManager? All of these ways have the same result on my problem: no cursor!
    click on a item (own component, extended Canvas, buttonMode = true)
    call function by MouseListener
    function {
        this.cursorManager.setBusyCursor();
        this.callLater(doPopUpWork);
    callLater function
    doPopUpWork() {
        // DO WORK AND ADD POPUP
        this.cursorManager.removeBusyCursor;
    I checked the right timing with trace statements [ trace("setBusy") ... ] and the also cursor comes Back when work is done and popup was added. All right and in right time. But the cursor disappears in that time instead of showing the busy cursor.
    Can anybody help me???

    I see there are problems with reading the code, try again:
    click on a item (own component, extended Canvas, buttonMode = true)
    call function by MouseListener
    function {
        this.cursorManager.setBusyCursor();
        this.callLater(doPopUpWork);
    callLater function
    doPopUpWork {
        // DO WORK AND ADD POPUP
        this.cursoManager.removeBusyCursor();

Maybe you are looking for