Updating paint methods

Hi all,
I was wondering if you can help,
I am programming a java game applet and have got a large picture placed directly onto the applet, which is updated with an animation thread.
This doesn't look right and I want to put the picture in a JPanel so that I can arrange my GUI better.
The usual way seems to be to extend a JPanel in a inner class and use its paintComponent method, but I'm not sure how to convert the code I have at the moment to do this. Especially using the drawImage method I use currently (see below).
public void paint(Graphics g){
     offScreen.drawImage(bgimage, 0, 0, this);
        offScreen.drawImage(fgimage, 0, 0, this);       
        colony.paint(offScreen);                                    
        g.drawImage(image, 0, 0, imageViewWidth, imageViewHeight,imageViewX_tc, imageViewY_tc, imageViewX_bc, imageViewY_bc, this);
} Any help would be appreciated,
John

I don't suggest you use a JPanel for animation, because it is swing, and swing is not thread-safe. Which means you have to use the much slower javax.swing.Timer rather than java.lang.Thread. However, I'll still convert your code in case you still want to do it:
public void paintComponent(Graphics g) {
     super.paintComponent(g);
     offScreen.drawImage(bgimage,0,0,this);
     offScreen.drawImage(fgimage,0,0,this);
     colony.paint(offScreen);
     g.drawImage(image, 0, 0, imageViewWidth, imageViewHeight,imageViewX_tc, imageViewY_tc, imageViewX_bc, imageViewY_bc, this);
}You should really decide to use an AWT component for your animation, like Panel (or event better- Canvas), because you can use the much faster Thread. So try using Canvas, you can still add it to your GUI because it's a child class of Component.

Similar Messages

  • Problem in paint() method

    i have defined a new class which extends JPanel. In that I have defined a paintComponent() method. i dont know how to use the repaint() method.
    can anyone help?

    i have defined a new class which extends JPanel. In
    that I have defined a paintComponent() method. i dont
    know how to use the repaint() method.I do not fully understand your problem, sorry. Could you please clarify a bit?
    The repaint()-method is there to draw an image to the screen once again, to make changes visible. As far as I know, it calls the update()- and paint()-methods whenever you call it.

  • HT204152 I am unable to update my App  store Updations. the reason being billing problem asking to update payment method.many times i updated my credit card details but refusing from the system .how can i update my app store updations like  Face book etc.

    I am unable to update my App  store Updations. the reason being billing problem asking to update payment method.Many a  times i updated my credit card details but refusing from the system .how can i update my app store updations like  Face book etc....Using ! phone 6plus  .IOS8.3

    What do you mean by 'refusing from the system', if you are getting an error message then what does it say ?
    For a credit card to have a chance of being accepted it needs to be registered to the same name and address (including format and spacing etc) that you have on your iTunes account, and have been issued by a bank in the country where you and your iTunes account are. If it is and if you are getting a 'declined' message then you could check with the card issuer to see if it's them that are declining it, and if not then try contacting iTunes Support (these are user-to-user forums) and see if they know why it's being declined : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption
    If when trying to download you are getting a message about a 'problem with a previous purchase' then that implies that iTunes wasn't able to collect the money for your last purchase. If that is the case then you won't be able to download anything else (including app updates) until you've paid off what you owe : Pay an unpaid balance in the iTunes Store - Apple Support
    If you aren't getting the 'problem with a previous purchase' message then try logging into your account (not when trying to download something) and see if you get the 'none' option so that you can remove the card's details and be able to download updates to your apps : Change or remove your payment information from your iTunes Store account (Apple ID) - Apple Support

  • Adding a JButton when there's a paint method

    I'm creating a game application, sort of like a maze, and I want to add buttons to the levelOne panel to be able to move around the maze. When I add the buttons to the panel they don't appear, I assume the paint method is the reason for this. here's my code, I have 3 files, ill post the user_interface, and the levels class, where the level is created and where i tried to add the button. I tried putting the buttons in a JOptionPane, but then my JMenu wouldn't work at the same time the OptionPane was opened. If anyone knows a way around this instead, please let me know. I also tried using a separate class with a paintComponent method in it, and then adding the button (saw on a forum, not sure if it was this one), but that didn't work either. Also, if there is a way just to simply have the user press the directional keys on the keyboard and have the program perform a certain function when certain keys are pressed, I'd like to know, as that would solve my whole problem. Thanks.
    //Libraries
    import java.awt.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.text.*;
    public class User_Interface extends JFrame
    static Levels l = new Levels ();
    static Delay d = new Delay ();
    private Container contentPane = getContentPane ();
    private JPanel main, levelOne;
    private String level;
    private CardLayout cc = new CardLayout ();
    private GridBagConstraints gbc = new GridBagConstraints ();
    private JPanel c = new JPanel ();
    private String label = "MainMenu";
    public User_Interface ()
    //Generates the User-Interface
    super ("Trapped");
    main = new JPanel ();
    GridBagLayout gbl = new GridBagLayout ();
    main.setLayout (gbl);
    c.setLayout (cc);
    // set_gbc (gbc, 2, 2, 5, 5, GridBagConstraints.NONE);
    c.add (main, "Main Page");
    contentPane.add (c, BorderLayout.CENTER);
    cc.show (c, "Main Page");
    levelOne = new JPanel ();
    levelOne.setLayout (new GridBagLayout ());
    levelOne.setBackground (Color.black);
    c.add (levelOne, "LevelOne");
    JMenuBar menu = new JMenuBar ();
    JMenu file = new JMenu ("File");
    JMenu help = new JMenu ("Help");
    JMenuItem about = new JMenuItem ("About");
    JMenuItem mainmenu = new JMenuItem ("Main Menu");
    mainmenu.addActionListener (
    new ActionListener ()
    public void actionPerformed (ActionEvent event)
    cc.show (c, "Main Page");
    label = "MainMenu";
    JMenuItem newGame = new JMenuItem ("New Game");
    newGame.addActionListener (
    new ActionListener ()
    public void actionPerformed (ActionEvent event)
    l.xCord = 2;
    l.yCord = 2;
    l.xLoc = 140;
    l.yLoc = 140;
    JPanel entrance = new JPanel ();
    entrance.setLayout (new FlowLayout ());
    c.add (entrance, "Entrance");
    label = "Entrance";
    level = "ONE";
    cc.show (c, "Entrance");
    JMenuItem loadgame = new JMenuItem ("Load Game");
    JMenuItem savegame = new JMenuItem ("Save Game");
    JMenuItem exit = new JMenuItem ("Exit");
    exit.addActionListener (
    new ActionListener ()
    public void actionPerformed (ActionEvent event)
    JFrame frame = new JFrame ();
    frame.setLocation (10, 10);
    JOptionPane.showMessageDialog (frame, "Come Back Soon!", "TRAPPED", JOptionPane.INFORMATION_MESSAGE);
    System.exit (0);
    file.add (about);
    file.add (mainmenu);
    file.add (newGame);
    file.add (loadgame);
    file.add (savegame);
    file.add (exit);
    menu.add (file);
    menu.add (help);
    setJMenuBar (menu);
    //Sets the size of the container (columns by rows)
    setSize (750, 550);
    //Sets the location of the container
    setLocation (10, 10);
    //Sets the background colour to a dark blue colour
    main.setBackground (Color.black);
    //Makes the container visible
    setVisible (true);
    public void paint (Graphics g)
    super.paint (g);
    g.setColor (Color.white);
    if (label == "MainMenu")
    for (int x = 0 ; x <= 50 ; ++x)
    g.setColor (Color.white);
    g.setFont (new Font ("Arial", Font.BOLD, x));
    g.drawString ("T R A P P E D", 100, 125);
    d.delay (10);
    if (x != 50)
    g.setColor (Color.black);
    g.drawString ("T R A P P E D", 100, 125);
    if (label == "Entrance")
    l.Entrance ("ONE", g);
    label = "LevelOne";
    if (label == "LevelOne")
    l.LevelOne (g, levelOne, gbc);
    label = "";
    public static void main (String[] args)
    // calls the program
    User_Interface application = new User_Interface ();
    application.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    } //End of Main Method
    //Libraries
    import java.awt.*;
    import java.io.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class Levels extends Objects
    private JFrame frame = new JFrame ();
    //Sets location, size, and visiblity to the frame where the JOptionPane
    //will be placed
    frame.setLocation (600, 600);
    frame.setSize (1, 1);
    frame.setVisible (false);
    public int xCord = 2;
    public int yCord = 2;
    public void LevelOne (Graphics g, JPanel one, GridBagConstraints gbc)
    ***Trying to add the button, doesn't appear. Tried adding to the container, and any JPanel i had created***
    JButton button1 = new JButton ("TEST");
    one.add (button1);
    g.setColor (Color.white);
    g.fillRect (500, 100, 200, 300);
    g.setColor (Color.black);
    g.drawRect (500, 100, 200, 300);
    g.setFont (new Font ("Verdana", Font.BOLD, 25));
    g.setColor (Color.black);
    g.drawString ("LEVEL ONE", 525, 80);
    //ROW ONE
    counter = -80;
    counter2 = 200;
    for (int a = 1 ; a <= 7 ; ++a)
    if (xCord < a && yCord == 0)
    g.setColor (darkGray);
    g.fillRect (xLoc + counter, yLoc - 80, 40, 40);
    g.setColor (Color.black);
    g.drawRect (xLoc + counter, yLoc - 80, 40, 40);
    if (xCord > a - 1 && yCord == 0)
    g.setColor (darkGray);
    g.fillRect (xLoc + counter2, yLoc - 80, 40, 40);
    g.setColor (Color.black);
    g.drawRect (xLoc + counter2, yLoc - 80, 40, 40);
    counter += 40;
    counter2 += 40;
    *****Theres 9 more rows, just edited out to save space****
    int y = 100;
    int x = 100;
    for (int a = 0 ; a < 20 ; ++a)
    g.setColor (Color.white);
    g.fillRoundRect (x, y, 40, 40, 5, 5);
    g.setColor (Color.black);
    g.drawRoundRect (x, y, 40, 40, 5, 5);
    y += 40;
    if (a == 9)
    x += 320;
    y = 100;
    x = 140;
    y = 100;
    for (int a = 0 ; a < 14 ; ++a)
    g.setColor (Color.white);
    g.fillRoundRect (x, y, 40, 40, 5, 5);
    g.setColor (Color.black);
    g.drawRoundRect (x, y, 40, 40, 5, 5);
    x += 40;
    if (a == 6)
    x = 140;
    y += 360;
    g.setColor (Color.black);
    g.drawRect (100, 100, 360, 400);
    ImageIcon[] images = new ImageIcon [4];
    images [0] = new ImageIcon ("arrow_left.gif");
    images [1] = new ImageIcon ("arrow_up.gif");
    images [2] = new ImageIcon ("arrow_down.gif");
    images [3] = new ImageIcon ("arrow_right.gif");
    int direction = -1;
    *****This is where I tried to have the OptionPane show the directional buttons******
    //frame.setVisible (true);
    // direction = JOptionPane.showOptionDialog (frame, "Choose Your Path:", "Trapped", JOptionPane.YES_NO_CANCEL_OPTION,
    // JOptionPane.QUESTION_MESSAGE,
    // null,
    // images,
    // images [3]);
    // if (direction == 0)
    // if (xCord - 1 > 0)
    // xCord -= 1;
    // xLoc += 40;
    // if (direction == 1)
    // if (yCord - 1 > 0)
    // yCord -= 1;
    // yLoc += 40;
    // if (direction == 2)
    // if (yCord + 1 < 9)
    // yCord += 1;
    // yLoc -= 40;
    // if (direction == 3)
    // if (xCord + 1 < 13)
    // xCord += 1;
    // xLoc -= 40;
    //LevelOne (g, one, gbc);
    }

    i tried adding a keylistener, that didn't work too well, i had tried to add it to a button and a textarea which i added to the 'one' frame, it didn't show up, and it didn't work. How would i go about changing the paint method so that it doesn't contain any logic? That's the only way I could think of getting the program to move forward in the game. Thanks.
    //Libraries
    import java.awt.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.text.*;
    public class User_Interface extends JFrame
        static Levels l = new Levels ();
        static Delay d = new Delay ();
        private Container contentPane = getContentPane ();
        private JPanel main, levelOne;
        private String level;
        private CardLayout cc = new CardLayout ();
        private GridBagConstraints gbc = new GridBagConstraints ();
        private JPanel c = new JPanel ();
        private String label = "MainMenu";
        public User_Interface ()
            //Generates the User-Interface
            super ("Trapped");
            main = new JPanel ();
            GridBagLayout gbl = new GridBagLayout ();
            main.setLayout (gbl);
            c.setLayout (cc);
            // set_gbc (gbc, 2, 2, 5, 5, GridBagConstraints.NONE);
            c.add (main, "Main Page");
            contentPane.add (c, BorderLayout.CENTER);
            cc.show (c, "Main Page");
            levelOne = new JPanel ();
            levelOne.setLayout (new GridBagLayout ());
            levelOne.setBackground (Color.black);
            c.add (levelOne, "LevelOne");
            JMenuBar menu = new JMenuBar ();
            JMenu file = new JMenu ("File");
            JMenu help = new JMenu ("Help");
            JMenuItem about = new JMenuItem ("About");
            JMenuItem mainmenu = new JMenuItem ("Main Menu");
            mainmenu.addActionListener (
                    new ActionListener ()
                public void actionPerformed (ActionEvent event)
                    cc.show (c, "Main Page");
                    label = "MainMenu";
            JMenuItem newGame = new JMenuItem ("New Game");
            newGame.addActionListener (
                    new ActionListener ()
                public void actionPerformed (ActionEvent event)
                    l.xCord = 2;
                    l.yCord = 2;
                    l.xLoc = 140;
                    l.yLoc = 140;
                    JPanel entrance = new JPanel ();
                    entrance.setLayout (new FlowLayout ());
                    c.add (entrance, "Entrance");
                    label = "Entrance";
                    level = "ONE";
                    cc.show (c, "Entrance");
            JMenuItem loadgame = new JMenuItem ("Load Game");
            JMenuItem savegame = new JMenuItem ("Save Game");
            JMenuItem exit = new JMenuItem ("Exit");
            exit.addActionListener (
                    new ActionListener ()
                public void actionPerformed (ActionEvent event)
                    JFrame frame = new JFrame ();
                    frame.setLocation (10, 10);
                    JOptionPane.showMessageDialog (frame, "Come Back Soon!", "TRAPPED", JOptionPane.INFORMATION_MESSAGE);
                    System.exit (0);
            file.add (about);
            file.add (mainmenu);
            file.add (newGame);
            file.add (loadgame);
            file.add (savegame);
            file.add (exit);
            menu.add (file);
            menu.add (help);
            setJMenuBar (menu);
            //Sets the size of the container (columns by rows)
            setSize (750, 550);
            //Sets the location of the container
            setLocation (10, 10);
            //Sets the background colour to a dark blue colour
            main.setBackground (Color.black);
            //Makes the container visible
            setVisible (true);
        public void paint (Graphics g)
            super.paint (g);
            g.setColor (Color.white);
            if (label == "MainMenu")
                for (int x = 0 ; x <= 50 ; ++x)
                    g.setColor (Color.white);
                    g.setFont (new Font ("Arial", Font.BOLD, x));
                    g.drawString ("T    R    A    P    P    E    D", 100, 125);
                    d.delay (10);
                    if (x != 50)
                        g.setColor (Color.black);
                        g.drawString ("T    R    A    P    P    E    D", 100, 125);
            if (label == "Entrance")
                l.Entrance ("ONE", g);
                label = "LevelOne";
            if (label == "LevelOne")
                l.LevelOne (g, levelOne, gbc);
                label = "";
            //g.setColor (new Color
        public static void main (String[] args)
            // calls the program
            User_Interface application = new User_Interface ();
            application.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        } //End of Main Method
    //Libraries
    import java.awt.*;
    import java.io.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.ActionMap;
    import javax.swing.plaf.*;
    public class Levels extends Objects
        implements KeyListener
        //static final String newline = System.getProperty ("line.separator");
        JButton button;
        private JFrame frame = new JFrame ();
            //Sets location, size, and visiblity to the frame where the JOptionPane
            //will be placed
            frame.setLocation (600, 600);
            frame.setSize (1, 1);
            frame.setVisible (false);
        JButton button1;
        public int xCord = 2;
        public int yCord = 2;
        public void LevelOne (Graphics g, JPanel one, GridBagConstraints gbc)
        //    button = new JButton ("TEST");
        //    ButtonHandler handler = new ButtonHandler ();
         //   button.addActionListener (handler);
          //  one.add (button);
            g.setColor (Color.white);
            g.fillRect (500, 100, 200, 300);
            g.setColor (Color.black);
            g.drawRect (500, 100, 200, 300);
            g.setFont (new Font ("Verdana", Font.BOLD, 25));
            g.setColor (Color.black);
            g.drawString ("LEVEL ONE", 525, 80);
            //ROW ONE
            counter = -80;
            counter2 = 200;
            for (int a = 1 ; a <= 7 ; ++a)
                if (xCord < a && yCord == 0)
                    g.setColor (darkGray);
                    g.fillRect (xLoc + counter, yLoc - 80, 40, 40);
                    g.setColor (Color.black);
                    g.drawRect (xLoc + counter, yLoc - 80, 40, 40);
                if (xCord > a - 1 && yCord == 0)
                    g.setColor (darkGray);
                    g.fillRect (xLoc + counter2, yLoc - 80, 40, 40);
                    g.setColor (Color.black);
                    g.drawRect (xLoc + counter2, yLoc - 80, 40, 40);
                counter += 40;
                counter2 += 40;
            int y = 100;
            int x = 100;
            for (int a = 0 ; a < 20 ; ++a)
                g.setColor (Color.white);
                g.fillRoundRect (x, y, 40, 40, 5, 5);
                g.setColor (Color.black);
                g.drawRoundRect (x, y, 40, 40, 5, 5);
                y += 40;
                if (a == 9)
                    x += 320;
                    y = 100;
            x = 140;
            y = 100;
            for (int a = 0 ; a < 14 ; ++a)
                g.setColor (Color.white);
                g.fillRoundRect (x, y, 40, 40, 5, 5);
                g.setColor (Color.black);
                g.drawRoundRect (x, y, 40, 40, 5, 5);
                x += 40;
                if (a == 6)
                    x = 140;
                    y += 360;
            g.setColor (Color.black);
            g.drawRect (100, 100, 360, 400);
            ImageIcon[] images = new ImageIcon [4];
            images [0] = new ImageIcon ("arrow_left.gif");
            images [1] = new ImageIcon ("arrow_up.gif");
            images [2] = new ImageIcon ("arrow_down.gif");
            images [3] = new ImageIcon ("arrow_right.gif");
            int direction = -1;
            //frame.setVisible (true);
            // direction = JOptionPane.showOptionDialog (frame, "Choose Your //\Path:", "Trapped", JOptionPane.YES_NO_CANCEL_OPTION,
            //         JOptionPane.QUESTION_MESSAGE,
            //         null,
            //         images,
            //         images [3]);
            // if (direction == 0)
            //     if (xCord - 1 > 0)
            //         xCord -= 1;
            //         xLoc += 40;
            // if (direction == 1)
            //     if (yCord - 1 > 0)
            //         yCord -= 1;
            //         yLoc += 40;
            // if (direction == 2)
            //     if (yCord + 1 < 9)
            //         yCord += 1;
            //         yLoc -= 40;
            // if (direction == 3)
            //     if (xCord + 1 < 13)
            //         xCord += 1;
            //         xLoc -= 40;
            one.addKeyListener (this);
            // one.add (button1);
            if (xCord == 1)
                LevelOne (g, one, gbc);
        /** Handle the key typed event from the text field. */
        public void keyTyped (KeyEvent e)
        /** Handle the key pressed event from the text field. */
        public void keyPressed (KeyEvent e)
            if (e.getSource () == "Up")
                JOptionPane.showMessageDialog (null, "Hi", "Hi", 0, null);
        /** Handle the key released event from the text field. */
        public void keyReleased (KeyEvent e)
            // displayInfo (e, "KEY RELEASED: ");
    }

  • Paint() method in an entity class

    Hi,
    I am trying to draw 2 shapes in a Canvas, one rectangle and a circle.
    However, I have an entity class for both the rectangle and the circle, something like:
    public class MyRectangle
    private int width, height;
    public MyRectangle() { ... }
    pulbic getWidth() { return width; }
    pulbic getHeight() { return Height; }
    I do not want to draw these 2 shape in the paint() method of the Canvas, I want my Rectangle class and my Circle to have their own paint method to draw themselves into the canvas, is it possible?
    If it is possible, can you tell me roughly how to do it?
    Do I have to extend the Component class?
    Thanks in advance.
    SK

    Hi,
    I tried to do what you mentioned as the following, but I cant get the circle display on the screen, do you know why? Thanks
    public class Ball extends Component
    private static final int diameter = 15;
    private int xPosition = 10, yPosition = 10;
    public Ball()
    public int getX() { return xPosition; }
    public int getY() { return yPosition; }
    public int getDiameter() { return diameter; }
    public void paint(Graphics g)
         super.paint(g);
    Graphics2D graphics2D = (Graphics2D)g;
    graphics2D.fillOval(xPosition, yPosition, diameter, diameter);
    public class MyFrame extends JFrame
    public MyFrame()
    // Set up the main frame
    super("Test");
    setPreferredSize(new Dimension(400, 300));
    Container contentPane = getContentPane();
         Ball aBall = new Ball();
         JPanel myPanel = new JPanel();
         myPanel.setBackground(Color.white);
         myPanel.setBorder(BorderFactory.createLineBorder(Color.black));
         myPanel.setOpaque(true);
    myPanel.add(aBall);
         contentPane.add(myPanel, BorderLayout.CENTER);     
    pack();
    /** The main method */
    public static void main(String[] args)
         MyFrame myFrame = new MyFrame();
    myFrame.setVisible(true);
    }

  • Paint() method is in infinite loop when focus is set to JTextPane

    Hi All,
    I am creating one JScrollPane, JPanel and JTextPane. JPanel is added to JScrollPane and JTextPane is added to JPanel. If I override paint() method in JPanel, its in infinite loop. I don't know why it is behaving like this. Can anyone solve my problem. Since, I am doing so much drawings in paint() method, its getting to slow.
    Here is the code what I wrote.
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.*;
    import java.awt.event.*;
    public class TestTextPane1 extends JFrame {
         JPanel panel;
         JScrollPane pane;
         public TestTextPane1() {
              panel = new JPanel(new BorderLayout()) {
                   public void paint(Graphics g) {
                        super.paint(g);
                        System.out.println("inside paint");
              JTextPane textPane = new JTextPane();
              panel.add(textPane);
              pane = new JScrollPane(panel);
              getContentPane().add(pane);
              setSize(300, 200);
              setVisible(true);
         public static void main(String [] args) {
              new TestTextPane1();
    Any help will be useful for me.
    Regards
    Kishore.

    What are you trying to do? You are adding the textPane to the panel and then overriding the paint() method. The textPane will never be painted if you do this.
    In Swing, you should override the paintComponent() method, not the paint() method. See the Swing tutorial on Painting:
    http://java.sun.com/docs/books/tutorial/uiswing/overview/draw.html
    Don't forget to read the "Working With Graphics" link at the bottom.

  • How to update payment method,once generated payment doc through F-58.

    Hi Experts,
    I want to update payment method,once generated payment doc through F-58.
    1)Maintained payment method in XK01
    2)Maintained the same in Invoice Number
    But, i am not able to generate payment method in payment doc through f-58.
    It can possble through F110,but why not in F-58.
    Please let me know,whether is it possible or not.
    Thanks
    Kishore.J

    Hi Ravi,
    Thanks for your reply.
    I gave my payment method,bank and check lot details in F-58 and generated payment document f-58.But,i am not able to find payment method in payment document.
    Thanks
    Kishore.J

  • How to use an object's paint method

    I have created a class imagePanel which extends a jPanel to display an image. When I create a new imagePanel object I pass it an image argument which is used to paint my image on the jPanel, so far so good. I don't wish to have to continuously create new ImamePanels to display new images so I thought I could make a set_Image method that would set a new image in an exising imagePanel object. This is where I run into problems how to use the existing object paint method to replace the image. I tried this without success:
    public Image setMyImage (Image myImage)
    imageX = myImage; // imageX is the image that is painted by the imagePanel object's paint method
    paint(g);
    Something must be wrong on how I access the paint method. Thanks for any help.
    Jack

    Yahoooo, got it. This was the code I needed and thanks for your help:
    public void setImage (Image myImage)
    imageX = myImage;
    repaint(300);
    }

  • Problem about calling paint method

    I have created a class to ask user input 3 floating-point numbers, using JApplet. the code list below
    import java.awt.Graphics;
    import javax.swing.*;
    public class Numbers
    double average,sum,product;
    String result;
    public void init()
    String firstNumber,secondNumber,thirdNumber;
    double num1,num2,num3;
    firstNumber=JOptionPane.showInputDialog("enter first number");
    secondNumber=JOptionPane.showInputDialog("Enter second number");
    thirdNumber=JOptionPane.showInputDialog("Enter thrid number");
    num1=Double.parseDouble(firstNumber);
    num2=Double.parseDouble(secondNumber);
    num3=Double.parseDouble(thirdNumber);
    sum=num1+num2+num3;
    product=num1*num2*num3;
    average=(num1+num2+num3)/3;
    result="";
    if(num1<num2 && num2<num3)
    result=result+num3+" is the largest number";
    if(num2>num1 && num2>num3)
    result=result+num2 +" is the largest number";
    if(num1>num2 && num2>num3)
    result=result+ num1+" is the largest number";
    public void paint(Graphics g)
    super.paint(g);
    g.drawString("sum is"+sum,25,25);
    g.drawString("product is"+ product,25,40);
    g.drawString("average is"+ average,25,60);
    g.drawString(" the largest number is"+result,25,80);
    however, after I compiled, it gave me the error message as:
    java:40: cannot resolve symbol
    symbol : method paint (java.awt.Graphics)
    location: class java.lang.Object
    super.paint(g);
    ^(pointer should point to the dot)
    don't know why,
    Message was edited by:
    ritchie_lin

    your class doesn't extend japplet or any other object for that matter. It does extend Object as all classes do, and Object has no paint method.
    Consider changing:
      public class Numbersto
      public class Numbers extends JAppletAlso, please use code tags next time you're posting code.
    Addendum: If this is not the JApplet portion of your code, it still has to subclass a Swing component that can accept painting such as JPanel. Also, with Swing you use paintComponent rather than paint.
    Message was edited by:
    petes1234

  • BAPI to update Payment Method (BSEG-ZLSCH)

    Hi ABAP Gurus,
    Good day.
    I have looked for a FM / BAPI that can update the Payment Method (BSEG-ZLSCH) of documents and tried some such as
    CHANGE_DOCUMENT and FAGL_CHANGE_DOCUMENT_ADD.  Unfortunately, Payment Method is not being updated.  I have initially debugged the standard transaction but I can't find a specific FM or set of FMs that update the Payment Method.
    With these, i have question:
    Can you kindly suggest a BAPI or FM that can update Payment Method (BSEG-ZLSCH)? 
    Thank you very much in advance for all your help.
    Best regards.
    Rainnier

    Hi Rob,
    Thanks for your checking my question. 
    Yes, I can update my sample document via FB02.  But when I trying some standard FMs, I can;'t update the Payment Method.
    I noticed though that other documents can't be updated via FB02 (payment method is uneditable; perhaps needs to be configured).   
    Thanks in advance for your time and reply.

  • How to call paint() method during creating object

    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    class SomeShape extends JPanel {
         protected static float width;
         protected BasicStroke line = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.CAP_ROUND);
    class Oval extends SomeShape {
         Oval(float width) {
              this.width = width;
              line = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.CAP_ROUND);
              repaint();
         public void paint(Graphics g) {
              Graphics2D pen = (Graphics2D)g;
              int i = 10;
              super.paint(g);
                   g.setColor(Color.blue);
                   g.drawOval(90, 0+i, 90, 90);
                   System.out.println("paint()");
    public class FinalVersionFactory {
        JFrame f = new JFrame();
        Container cp = f.getContentPane();
        float width = 0;
        SomeShape getShape() {
             return new Oval(width++); //I want to paint this oval when I call getShape() method
         public FinalVersionFactory() {
              f.setSize(400, 400);
    //          cp.add(new Oval()); without adding
              cp.addMouseListener(new MouseAdapter() {
                   public void mouseReleased(MouseEvent e) {
                        getShape();
              f.setVisible(true);
         public static void main(String[] args) { new FinalVersionFactory(); }
    }I need help. When I cliked on the JFrame nothing happened. I want to call paint() method and paint Oval when I create new Oval() object in getShape(). Can you correct my mistakes? I tried everything...Thank you.

    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    class SomeShape extends JPanel {
         protected static float width;
         protected static BasicStroke line = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.CAP_ROUND);
    class Oval extends SomeShape {
         static int x, y;
         Oval(float width, int x, int y) {
              this.width = width;
              this.x = x;
              this.y = y;
              line = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.CAP_ROUND);
         public void paint(Graphics g) {
              Graphics2D pen = (Graphics2D)g;
                   g.setColor(Color.blue);
                   pen.setStroke(line);
                   g.drawOval(x, y, 90, 90);
                   System.out.println("Oval.paint()"+"x="+x+"y="+y);
    class Rect extends SomeShape {
         static int x, y;
         Rect(float width, int x, int y) {
              this.width = width;
              this.x = x;
              this.y = y;
              line = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.CAP_ROUND);
         public void paint(Graphics g) {
              Graphics2D pen = (Graphics2D)g;
                   g.setColor(new Color(250, 20, 200, 255));      
                   pen.setStroke(line);
                   g.drawRect(x, y, 80, 80);
                   System.out.println("Rect.paint()"+"x="+x+"y="+y);
    public class FinalVersionFactory extends JFrame {
        Container cp = getContentPane();
        float width = 0;
        int x = 0;
        int y = 0;
            boolean rect = false;
        SomeShape getShape() {
             SomeShape s;
              if(rect) {
                   s = new Rect(width, x, y);
                   System.out.println("boolean="+rect);
              } else {
                   s = new Oval(width++, x, y);
                   System.out.println("boolean="+rect);
              System.out.println("!!!"+s); //print Oval or Rect OK
              return s; //return Oval or Rect OK
         public FinalVersionFactory() {
              setSize(400, 400);
              SomeShape shape = getShape();
              cp.add(shape); //First object which is add to Container(Oval or Rect), returned by getShape() method
              //will be paint all the time. Why? Whats wrong?
              cp.addMouseListener(new MouseAdapter() {
                   public void mouseReleased(MouseEvent e) {
                        x = e.getX();
                        y = e.getY();
                        rect = !rect;
                        getShape();
                        cp.repaint(); //getShape() return Oval or Rect object
                                      //but repaint() woks only for object which was added(line 67) as first
              setVisible(true);
         public static void main(String[] args) { new FinalVersionFactory(); }
    }I almost finish my program but I have last problem. I explained it in comment. Please look at it and correct my mistakes. I will be very greatful!!!
    PS: Do you thing that this program is good example of adoption Factory Pattern?

  • Determining if printing is going on in paint method

    By looking at the source of the existing visual components, I have found out that JComponent.paintChildren uses getFlag(IS_PRINTING) to determine wether or not the current call to paint will paint to screen or to a printer.
    The problem is that both getFlag and the constants it uses are declared as private in JComponent. This is why I am wondering why Sun chose to keep this information private to the JComponent class, while this information could be very useful in some situations.
    Also, would there be any alternatives to determine wether or not printing is occuring from a paint method besides managing flags the same way JComponent does?
    Thanks in advance.

    I gave a try to your approach but it doesn't seem that the graphics object passed to the paint method during the printing process implements PrintGraphics. I'll keep trying stuff with that idea until some new input is given, but thanks for the idea, it sure could have worked out ;)

  • Invoking paint method in Java3D

    I have some example programs in using Java3D but none of them paints 'directly' on the canvas3D.
    if i have a class that extends a Canvas3D how would i call the paint method, can i use this method to draw a 2D polygon on my canvas? (because i wanted to have 3D and 2D objects mixed).
    how would i do this? are the points in terms of x, y, z?
    can anyone help me with this?
    thanks in advance

    I've been trying to do this myself, snd it's a right pain in the arse.
    To actually paint on the Canvas3D, when you override postRender(), you do all your stuff but it doesn't work until you call flush(). However, when I tied it (just drawing a simple rectange), my app slowed from 20fps to 2, which is a bit too much of a performance hit for my liking.
    The J3D Repository overlay is fairly easy to set up, but for some reason the polygon it draws on is about 1 unit away from where you add it, so for a 1st person thing like I'm doing, it dissapears when you get too near a wall. In the end, i have just created my own by putting a texture on a cube just in front of the viewport.

  • How paint method in TiledLayer work ?

    It's my 1st time in forum. Does anyone has source code of Sprite, TiledLayer class or know how exactly the paint method work? I had used it in some game but not satisfied with it. I want to code my own class but i wonder it has some native or low-level code.
    Sorry for my poor E !!!

    perhaps you want to use a more hardware oriented approach. I can highly recommend you the Slick API. It is built on top of the LWJGL API set, which is a Java binding for OpenGL, OpenAL and provides device support such as joysticks/joypads. Slick turns the 3D part into an easy to use 2D rendering framework.
    [http://slick.cokeandcode.com/|http://slick.cokeandcode.com/]
    Basic example program:
    [http://slick.cokeandcode.com/wiki/doku.php?id=01_-_a_basic_slick_game|http://slick.cokeandcode.com/wiki/doku.php?id=01_-_a_basic_slick_game]

  • More than one paint method?

    Hi
    Im wondering if it is possible to have more than one paint method. It should look something like this.
    public class MyApplet extends JApplet {
    public void paint(Graphics g) { // the normal paint method
    public void SecondPaint(Graphics gr) { // should i name the Graphics
    // to the same as in the normal paint method ( Graphics g) ?
    }And if its possible how would i repaint the other method?
    This is for the normal
    repaint(); and how would i do for the second paint method?
    please write an example program with two paint methods and just write below how to repaint.
    Thanks you som much if you reply

    (sorry to hijack this thread...) Yes, it'swindows,
    but right now my problem isn't even that. It'sjust
    catching and correcting basic c-coding errors.
    Witness my embarrassment in the JNI forum:
    http://forum.java.sun.com/thread.jspa?threadID=5213196
    &tstart=15
    Now if only I lived in "middle-of-no-where"Virginia!
    Nice! ;-)I saw your note about "middle-of-nowhere" Virginia a little too late. And you don't need to live here; my Solaris machine is up and running 24/7 and is open for SSH and XClient. (Also open for telnet, which comes built into windows, I believe.) If you'd like to brush up on Solaris C, C++ and Java development, just let me know. You're more than welcome to use the machine. I have tons of space on the drive and a dedicated connection just to that machine. There is an application for windows called CygwinX which is an XClient for Solaris. You can use that to remotely log into the Solaris desktop. There are about fifteen other people that I let use the machine for various reasons. I host myriad open source projects for development that you're more than welcome to mess around with. Tools available to you would be NetBeans 5.5, Sun Studio (with the Sun C/C++/Fortran compiler - which is beautiful by the way); and the whole suite of GNU compilers. I have the CDE and the JavaDesktop built in. I also have tons of Motif tutorials and demonstrations if you're interested in those. Heads up, though ... XServer tends to run pretty slowly when I have more than about four users logged onto a desktop at once. But like I said, if you (or just about anyone else for that matter) are interested, let me know and I'd be more than glad to set you up.

Maybe you are looking for

  • Can't view output for concurrent request

    I apologize if this is a common error - I tried to research this in the forums but didn't find anything that I haven't already tried. I checked the OPP - it is running with 3 processes - no error in the log that I can see. I checked the profile for t

  • Report builder, image issue with PDF output

    hi there, i generate report to PDF. i got the company logo on the header. everything is working fine. my pdf is generated and my letter comes out nice and proper. now once the PDF is generate and i view it on adobe reader, i want to protect the logo

  • Delete button in tableviewcell disappear after orientation

    I create a table view, every time orientate, I will reload it. When i swipe to make the delete button appear, and then orientate the device, because of the reload, the delete button disappear. How can I solve it?

  • Material value which is MAP will be GR for free of chaged

    Hi, I have one material  with value stock and qty stock for inventory and using MAP . now current inventory qty  10 ea  current MVP  is 1000 US$ what if  the material will be Good Receipt  as  Free of charge ? my question,  do i have to suggest  501

  • PO Information is grad out for some of the employees in the assignment

    Hi All, I am facing an issue in the People--> Assignment--> "Purchase Order Information" tab. For some of the employees the accounting flexfield is updatable but for some of the employees it's graded out. Kindly provide route cause for this. Thanks a