Repaint() doesnt call paint component

Hi all
i need to call a paintComponent method() so i use repaint();
but it doesnt work.
trigger's in mouse pressed, calls pageflip method, then in a pageflip method calls paintComponent
here's part of my code
addMouseListener(new MouseAdapter() {                                   
                public void mousePressed(MouseEvent e) {                   
                    if (boEvent==true){
                        System.out.println("mouse Pressed");
                        iMoux=e.getX();iMouy=e.getY();
                        if (iMoux>=(di.width/2)){
                             boSaveReverse = false;
                             PageFlip(0, 0, e.getX(), e.getY(), false, false, false, true);
                        else {
                            boSaveReverse = true;
                            PageFlip(0, 0, e.getX(), e.getY(), false, true, false, true);
                        boClicked=false;                                                   
public void PageFlip(int a, int b, int c, int d, boolean boe,
                             boolean bof, boolean bog, boolean boh){                      
            int bookx = a;int booky = b;int iMoux =c;int iMouy = d;
            boolean boClicked = boe;boolean boReverse = bof;
            boolean boZoom    = bog;boolean boDraw = boh;
            repaint();    //here repaint didint call paintComponent?       
        }did i do something wrong here?
Thx in advance

did i do something wrong here?Who knows? To get better help sooner, post a SSCCE that clearly demonstrates your problem.
luck, db

Similar Messages

  • Does repaint() not call paint()?

    I try to create a application where pictures are switching randomly one after another. User can specific how long this randomly displaying image application run. Then when the user click "start", the image will randomly change until it is timeout. As far as I know, I have this part finish.
    However, I want to add another part: when user click start a small clock display on the panel the amount of second counting down. However, when I set the timer to repaint() the application, it does not get in the paint() method. Below are my code, please help. Since my code are a bit long, I will post my entire code on a separate thread, hope that the admin and mod dont mind.
    This is where I implement paint(), and I click on the button, I repaint the panel
    public void paint(Graphics g)
            System.out.println("Inside Graphics");
            //Create an instance of Graphics2D
            Graphics2D g2D = (Graphics2D)g;
            g2D.setPaint(Color.RED);
            g2D.setStroke(stroke);
            DigitalNumber number = new DigitalNumber(numberX,numberY,numberSize,numberGap,Color.red, Color.white);
            //Get the time that the user input to the field
            String time = tf.getText();
            float locX = numberX;
            float locY = numberY;
            //Start drawing the number onto the panel
            for(int i=0; i<time.length(); i++){
                 number.drawNumber(Integer.parseInt(Character.toString(time.charAt(i))), g2D);
                 locX += numberSize + numberGap;
                 number.setLocation(locX, locY);
    private void createBtnPanel() {
          JButton startBtn = new JButton("Start");
          JButton stopBtn = new JButton("Stop");
          startBtn.addActionListener(new StartBtnListener() );
          stopBtn.addActionListener(new StopBtnListener());
          btnPanel.add(startBtn, BUTTON_PANEL);
          btnPanel.add(stopBtn, BUTTON_PANEL);
    private class StartBtnListener implements ActionListener {
          public void actionPerformed(ActionEvent e) {
             //get the time from the user input
             String input = tf.getText();
             numberOfMilliSeconds = Integer.parseInt(input)*1000;
             //get the current time
             startTime = System.currentTimeMillis();
             java.util.Timer clockTimer = new java.util.Timer();
             java.util.TimerTask task = new java.util.TimerTask()
                 public void run()
                      mainPanel.repaint();
             clockTimer.schedule(task, 0L, 1000L);
             rotatePictureTimer.start();
       }

    I am sorry. However, even though I try to make my code self contained, it still too long to post here. It is the DigitalNumber.java that contain all the strokes for draw the number is all too long. But I can tell you that DigitalNumber.java is worked because I wrote a digital clock before, and it worked. But below is the link to my DigitalNumber.java if u guy want to look at it
    http://www.vanloi-ii.com/code/code.rar
    Here is my code for DisplayImage.java in self-contain format. Thank you
    import java.awt.BasicStroke;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.BorderLayout;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import javax.swing.*;
    public class DisplayImage{
       private static final Dimension MAIN_SIZE = new Dimension(250,250);
       private static final String BUTTON_PANEL = "Button Panel";
       private JPanel mainPanel = new JPanel();
       private JPanel btnPanel = new JPanel();
       private JPanel tfPanel = new JPanel();
       private BorderLayout borderlayout = new BorderLayout();
       private JTextField tf;
       BasicStroke stroke = new BasicStroke(5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL);
       private float numberX = 100f;
       private float numberY = 100f;
       private float numberSize = 10f;
       private float numberGap = 2f;
       public DisplayImage() {
          mainPanel.setLayout(borderlayout);
          mainPanel.setPreferredSize(MAIN_SIZE);
          createTFPanel();
          createBtnPanel();
          mainPanel.add(tfPanel, BorderLayout.NORTH);
          mainPanel.add(btnPanel, BorderLayout.SOUTH);
       public void paint(Graphics g)
            System.out.println("Inside Graphics");
            //Create an instance of Graphics2D
            Graphics2D g2D = (Graphics2D)g;
            g2D.setPaint(Color.RED);
            g2D.setStroke(stroke);
            DigitalNumber number = new DigitalNumber(numberX,numberY,numberSize,numberGap,Color.red, Color.white);
            //Get the time that the user input to the field
            String time = tf.getText();
            float locX = numberX;
            float locY = numberY;
            //Start drawing the number onto the panel
            for(int i=0; i<time.length(); i++){
                 number.drawNumber(Integer.parseInt(Character.toString(time.charAt(i))), g2D);
                 locX += numberSize + numberGap;
                 number.setLocation(locX, locY);
       private void createBtnPanel() {
          JButton startBtn = new JButton("Start");     
          startBtn.addActionListener(new StartBtnListener() );    
          btnPanel.add(startBtn, BUTTON_PANEL);
       private void createTFPanel() {
          JLabel l = new JLabel("Enter Number of Seconds: ");
          tf = new JTextField(3);
          tfPanel.add(l);
          tfPanel.add(tf);
       private class StartBtnListener implements ActionListener {
          public void actionPerformed(ActionEvent e) {
             //get the time from the user input
             java.util.Timer clockTimer = new java.util.Timer();
             java.util.TimerTask task = new java.util.TimerTask()
                 public void run()
                      System.out.println("TimerTask");
                      mainPanel.repaint();
             clockTimer.schedule(task, 0L, 1000L);     
       private static void createAndShowUI() {
           DisplayImage displayImage = new DisplayImage();
          JFrame frame = new JFrame("Display Image");
          frame.getContentPane().add(displayImage.mainPanel);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setBackground(Color.white);
          frame.pack();
          frame.setLocationRelativeTo(null);  //center the windows
          frame.setVisible(true);
       public static void main (String args[]) {
          java.awt.EventQueue.invokeLater(new Runnable(){
             public void run() {
                createAndShowUI();
    }Edited by: KingdomHeart on Feb 22, 2009 6:12 PM

  • Paint Component

    Hi all
    i have four classes plot , plot3d, plotsurface and test
    plot is derived from JPanel and plot3d and plotsurface extend plot class
    i am trying to do a very simple operation . just making a tool bar with 2 buttons to switch between plots .
    the 2 plot classes plot3d and plotsurface just draw a line on the screen
    problem is that when the user clicks one button it doesnot show up on the screen but when the window is resized it does call paint component of the corresponding class
    can Any one explain why this is happening......
    package test;
    import javax.swing.*;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    public abstract class plot extends JPanel {
    plot()
    public void paintComponent(Graphics g)
    Graphics2D graphics2D=(Graphics2D)g;
    super.paintComponent(g);
    package test;
    import javax.swing.*;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    public class plot3d extends plot {
    plot3d(boolean resizable)
    public void paintComponent(Graphics g)
    Graphics2D graphics2D=(Graphics2D)g;
    super.paintComponent(g);
    graphics2D.drawLine(200,200,320,320);
    package test;
    import javax.swing.*;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    public class plotsurface extends plot {
    plotsurface(boolean resizable)
    public void paintComponent(Graphics g)
    Graphics2D graphics2D=(Graphics2D)g;
    super.paintComponent(g);
    graphics2D.drawLine(120,120,140,140);
    package test;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.Graphics2D.*;
    import java.applet.*;
    public class Test extends javax.swing.JApplet {
    private Container container;
    public Rectangle rect;
    JPanel toolBar;
    JButton contourButton;
    JButton surfaceButton;
    JPanel toolPanel;
    public Graphics g;
    public test.plot3d graph3D;
    public test.plotsurface graphSurface;
    private int plotType=0;
    private void graph3D(Graphics2D g2)
    graph3D=new plot3d(false);
    public void graphSurface(Graphics2D g2)
              graphSurface=new plotsurface(false);
    private void changeplottoContour()
    if(plotType==0)
    return;
    plotType=0;
    g=container.getGraphics();
    Graphics2D g2=(Graphics2D)g;
    container.removeAll();
    repaint();
    graphSurface=null;
    System.gc();
    graph3D(g2);
    container.add(toolPanel,BorderLayout.NORTH);
    container.add(graph3D,BorderLayout.CENTER);
    private void changeplottoSurface()
    if(plotType==1)
    return;
    plotType=1;
    g=container.getGraphics();
    Graphics2D g2=(Graphics2D)g;
    container.removeAll();
    repaint();
    graph3D=null;
    System.gc();
    graphSurface(g2);
    container.add(toolPanel,BorderLayout.NORTH);
    container.add(graphSurface,BorderLayout.CENTER);
    private void surfaceButtonActionPerformed(java.awt.event.ActionEvent evt)
         changeplottoSurface();
         repaint();
    private void contourButtonActionPerformed(java.awt.event.ActionEvent evt)
         changeplottoContour();
         repaint();
    public void init()
         container=getContentPane();
    g=container.getGraphics();
    Graphics2D g2=(Graphics2D)g;
    Rectangle r1= new Rectangle();
    rect=new Rectangle();
    //r1=container.getBounds();
    toolPanel= new JPanel(new BorderLayout());
    toolBar = new JPanel();
    contourButton = new JButton("Contour");
    toolBar.add(contourButton);
    contourButton.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    contourButtonActionPerformed(evt);
    surfaceButton = new JButton("Surface Plot");
    toolBar.add(surfaceButton);
    surfaceButton.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    surfaceButtonActionPerformed(evt);
    toolBar.setBackground(Color.white);
    toolPanel.add(toolBar,BorderLayout.NORTH);
    container.add(toolPanel,BorderLayout.NORTH);
    Rectangle r2= toolPanel.getBounds();
    Dimension appletSize = this.getSize();
    int appletHeight= appletSize.height;
    int appletWidth= appletSize.width;
              rect.setBounds(0,(int)r2.getHeight(),appletWidth,appletHeight-(int)r2.getHeight());
    plotType=0;
         graph3D(g2);
         container.add(graph3D,BorderLayout.CENTER);

    in your button action listeneres (e.g. contourButtonActionPerformed()) don't only call repaint(), but update(this.getGraphics());
    this should help in most cases. other refreshing methods are:
    java -Dsun.java2d.noddraw=true HelloWorld
    java.awt.Component.repaint()
    java.awt.Component.update(Graphics) (e.g. c.update(c.getGraphics());)
    java.awt.Component.validate()
    javax.swing.JComponent.revalidate()
    javax.swing.JComponent.updateUI()
    javax.swing.SwingUtilities.updateComponentTreeUI(java.awt.Component)

  • My repaint() doesnt work

    Hope somebody can help. I had posted this qtn on another site and got a response pointing to a java sun site talking about paint in general. unfortunately did not help.
    the issue is as follows:
    Heres the problem
    Have this drawing application with menus and stuff. so i draw box/lines/ circle etc. and when the mouse is released, i add the positions etc to an array, in my paint program, i parse thru the array and show the stuff. Now whatever i draw, doesnt appear immediately (although i have a repaint() (also tried validate, revalidate and every command i have learnt/come across).
    funny thing is, if i press my alt key, the "file" menu option will appear to be selected, when i press escape, the drawing window gets focus and immediately all my drawings appear. So my question, how do i make it do that.
    Additionally (while i am on the roll here) in my menu option i have a File/New when this is selected, i clear the array and do a repaint(). that works beautifully and all the drawing are gone. but if i click on a icon (designated as "new") that wont do anything until i go thru that pressing alt (or switching to another application using alt+tab and then coming back to my paint program).
    Any ideas?
    To add further this is how my code looks
    there is a frame called drawingWindow (my highest level).
    got a container Container drawBoard = getContentPane(); which is added to my frame.
    i got menubar and toolbar created and added to the drawingWindow
    Then i got this class which contains the paintcomponent routine.
    JPanel drawingArea = new DrawGraphics();
    and this is added to the container.
    drawBoard.add(drawingArea,BorderLayout.CENTER);
    as i mentioned earlier: when i draw something, the repaint doesnt show the stuff immediately. instead i have to switch to some other applications that overlaps this java program and when i switch back i will see my paint.
    why so and how can i ever get it to work.
    Thank you in advance.

    The same kind of problem I was also having some time back but what i did was sounding funny to me, but i did it.... as there is no way.Just do resize kind of operation.
    After calling repaint method , just get the current size of window, set it to next size and again set it back to original size.Screen will flicker for a fraction of second.It was working very well to me.Maybe it will help you too.......

  • My repaint( ) just re-paints but doesn't clear the back

    Hi, i am using repaint( ) with the timer method to randomly draw 100 randomly colored lines.But every time the timer calls actionperformed which contains repaint( ), the application just paints the new 100 lines on top of the old ones, not cleaning the first painting. Maybe this is the way to repaint continuesly, but isn't repaint( ) supposed to clear the back. Here is my code, thanks for helping!
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class RandomLines extends JFrame
    implements ActionListener {
    private int x1,y1,x2,y2;
    private int r,gr,b;
    Timer timer;
    public RandomLines()
    super("Drawing Random Lines");
    timer=new Timer(10000, this);
    timer.start();
    setSize(400,400);
    show();
    public void paint(Graphics g)
    for(int i=1;i<=100;i++)
    x1=1+(int)(Math.random()*399);
    y1=1+(int)(Math.random()*399);
    x2=1+(int)(Math.random()*399);
    y2=1+(int)(Math.random()*399);
    r=1+(int)(Math.random()*255);
    gr=1+(int)(Math.random()*255);
    b=1+(int)(Math.random()*255);
    g.setColor(new Color(r,gr,b));
    g.drawLine(x1,y1,x2,y2);
    public void actionPerformed(ActionEvent e)
    repaint();
    public static void main(String args[])
    RandomLines app=new RandomLines();
    app.addWindowListener(
    new WindowAdapter() {
    public void windowClosing(WindowEvent e)
    System.exit(0);
    }

    I reckon this might be part of it:
    Container update(Graphics g):
    Updates the container. This forwards the update to any lightweight components that are children of this container. If this method is reimplemented, super.update(g) should be called so that lightweight components are properly rendered. If a child component is entirely clipped by the current clipping setting in g, update() will not be forwarded to that child.
    Component update(Graphics g):
    Updates this component.
    The AWT calls the update method in response to a call to repaintupdate or paint. You can assume that the background is not cleared.
    The updatemethod of Component does the following:
    Clears this component by filling it with the background color.
    Sets the color of the graphics context to be the foreground color of this component.
    Calls this component's paint method to completely redraw this component.
    The apparently contradictory statements in the definition for Component are slightly puzzling - maybe they mean that "You can assume that the background has yet to be cleared"? This would also seem to imply that a Panel, being a container, does not clear its background, but that a Canvas does. I can't remember if this is the case. Anyone care to verify?--
    <sig> http://www.itswalky.com http://www.crfh.net </sig>

  • Paint component scope issues

    hi i have 2 classes one is my main and the other is the paint class with void paintcomponent() inside
    how do i pass the x variable inside main class so i can use it inside the Map class
    i know you can use scope e.g. Map map = new Map(x,y); but then i have to use a constructor with
    its own repaint(); method inside but it does not work.
    i was thinking of overloading a constructor aswell so inside one constructor is nothing and in the other with the (x, y) has
    the repaint method inside but that doesn't work either.
    main class
    public class Main
    public static void main(String[] args) {
    MainFrame frame = new MainFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(500, 500);
    frame.setVisible(true);
    class MainFrame extends JFrame
    private int x;
    private int y;
    // map class with paint component
    Map map = new Map(x,y);
    public MainFrame(){
    this.add(map);
    }paint class
    public class Map extends JPanel {
    private int x;
    private int y;
    public Map(){}
    public Map(int x, int y){
    this.x = x;
    this.y = y;
    repaint();
        @Override
        public void paintComponent(Graphics g){
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    }this does not work, any ideas?
    Edited by: nicchick on Nov 25, 2008 1:00 AM

    um that wasnt exactly what i was looking for i have a better example
    what im trying to do is pass/scope private varibles from the main class to the map class
    but since you use repaint(); to call the paintcomponent override method theres no way to scope varibles like
    x and y to panel?
    this example shows what im trying to do with a mouselistener
    main
    public class Main
    public static void main(String[] args) {
    MainFrame frame = new MainFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(500, 500);
    frame.setVisible(true);
    class MainFrame extends JFrame
    private int x;
    private int y;
    // map class with paint component
    Map map = new Map();
    // handler
    HandlerMotion handler = new HandlerMotion();
    public MainFrame(){
    this.add(map);
    map.addMouseMotionListener(handler);
         private class HandlerMotion implements MouseMotionListener
            public void mouseDragged(MouseEvent e) {
            public void mouseMoved(MouseEvent e) {
            x = e.getX();
            y = e.getY();
            new Map(x,y);
            repaint();
    }map
    public class Map extends JPanel {
        private int x;
        private int y;
        public Map(){}
        public Map(int x, int y)
        this.x = x;
        this.y = y;
        System.out.println("this is map" + x);
        System.out.println("this is map" + y);
        repaint();
        @Override
        public void paintComponent(Graphics g){
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.drawLine(0, 0, x, y);
        System.out.println("this is panel" + x);
        System.out.println("this is panel" + y);
    }

  • Applet (flashes when repaint is called)

    How can stop my applet from flashing when repaint is called? Someone had mentioned the update method from class component. Can anyone tell me how to use to eliminate the flashing?

    How can stop my applet from flashing when repaint is
    called? Someone had mentioned the update method from
    class component. Can anyone tell me how to use to
    eliminate the flashing?If you're using Swing, you should only be painting in the paintComponent method and shouldn't use update.
    You may also want to look into double-buffering.

  • Correct clipping when calling "paint()" from thread

    How do I achieve correct clipping around JMenus or JTooltips when calling paint() for a Component from a background thread?
    The whole story:
    Trying to implement some blinking GUI symbols (visualizing alerts), I implemented a subclass of JPanel which is linked to a Swing timer and thus receives periodic calls to its "actionPerformed()" methods.
    In the "actionPerformed()" method, the symbol's state is toggled and and repainting the object should be triggered.
    Unfortunately, "repaint()" has huge overhead (part of the background would need to be repainted, too) and I decided to call "paint( getGraphics() )" instead of it.
    This works fine as long as there is nothing (like a JMenu, a JComboBox or a JTooltip) hiding the symbol (partially or completely). In such case the call to paint() simply "overpaints" the object.
    I suppose setting a clipping region would help, but where from can I get it?
    Any help welcome! (I alread spent hours in search of a solution, but I still have no idea...)

    For all those interested in the topic:
    It seems as if there is no reliable way to do proper clipping when calling
    "paint()".
    The problem was that when my sub-component called "repaint()" for itself, the underlying component's "paintComponent()" method was called as well. Painting of that component was complex and avoiding complexity by restricting
    on the clipping region is not easily possible.
    I have several sub-components to be repainted regularly, resulting in lots of calls to my parent component's "paintComponent()" method. This makes the
    repainting of the sub-components awfully slow; the user can see each one begin painted!
    Finally I decided I had to speed up the update of the parent component. I found two possible solutions:
    a) Store the background of each of the sub-components in a BufferedImage:
    When "paintComponent()" is called: test, if the clipping rectangle solely
    contains the region of a sub-component. If this is true check if there
    is a "cached" BufferedImage for this region. If not, create one, filling
    it with the "real" "paintComponent()" method using the Graphic object of
    the BufferedImage. Once we have such a cached image, simply copy it the
    the screen (i.e. the Graphics object passed as method parameter).
    b) To avoid the handling of several of such "cached" image tiles, simply
    store the whole parent component's visible part ("computeVisibleRect()")
    in a BufferedImage. Take care to re-allocate/re-paint this image each
    time the visible part changes. (I need to restrict the image buffer to
    the visible part since I use a zooming feature: Storing the whole image
    would easily eat up all RAM!) In the "paintComponent()", simple check
    if the currently buffered image is still valid - repaint if not -
    and copy the requested part of it (clip rect) to the screen. That's it!
    The whole procedure works fine.
    Best regards,
    Armin

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

  • Call paint or validate

    What should I call paint or validate once a person
    minimizes or maximizes a frame or a dialog box.
    I have little confusion on this.
    rajesh

    paint is to render, validate is for layout stuff. Sometimes the UI becomes dirty even if the layout did not change. If your UI seems to be painted but display a bad layout, call validate. Note that you also might have to call both, empiric testing will prevail in this domain since Containers are sometimes a bit strange on their behaviours.
    Also, do not use paint but rather repaint(), it would be better. Also note that there's an invalidate method, depending on what you are doing, invalidate might be your answer.
    conclusion:
    use repaint(), invalidate(), validate(). the use of 3, 2 or 1 of those methods will be answered by empiric tests.

  • Calling paint(g) on components

    When can you call paint(g) on a component? Does it have to be on screen for it to have any effect? ie if I call paint(g) on a component when it is not visible will it have any effect on the g I pass to it? (g is a Graphics instance.)

    Hi,
    that actually depends on the component. JComponent for example first checks whether its size has width and height greater that zero. Unless it doesn't paint. And this may happen if you don't set the size manually if its not on screen.
    Other components may have some check if they're visible or something.
    However this depends on the component in question.
    Michael

  • How to call paint ( )?

    Hi,
    I am trying to display a tring but I dont know how to call paint ( ). I used show but its giving me mesg that show is deprecated.
    Can somebody help me in this regard?
    import java.awt.*;
    class DisplayText extends Frame{
    DisplayText (String s) {
      super(s);
    public void paint (Graphics g) {
      g.drawString("Hello World", 10,10);
    public static void main (String args[ ]) {
       DisplayText screen = new DisplayText("Example 1");
                screen.setSize(500,100);
                screen.setVisible(true);
    }Zulfi.

    I don't really recommend using the paint() methodfor
    drawing Strings on the Frame. Paint should be used
    just for Graphics
    So how do you make a component show a text? Use a Label :-)If your custom component needs to paint graphics and text then there is nothing wrong with drawing a String in the paintComponent() method. (In Swing you should override paintComponent(), not paint(). It doesn't make sense to create a JLabel with all the extra overhead that requires.
    The problem with this posting is overriding the paint(..) method of the entire frame is not a good idea.

  • Calling fragment component from page  in Oracle ADF.

    Hi ,i am  using Jdev 11.1.1.5 and  i have a requirement to call a fragment component(Eg:SelectoneChoice) which is using in a region and i want to call that component from a link from my jspx page.now the problem is ,the link which is in a jspx is a HTML link.
    Now the clear question is i want to disable that  dropdown which is in a fragment on the click of that html link which is in a jspx page.i will appreciate your valuable answer.
    Thanks.
    Satya

    Thanks Prateek,The exact requirement is to disable a drop down which is in a fragment and used as a region in a jspx page,now i have a link in the same jspx page.so when the user click that link (Eg:it should have a html link) the drop down should disable.
    Yes i agree with your point is to add a go-link or command link but requirement is to have a html link.if it would have ADF link then i should use setPropertyLitsener using the session.but its  a html link.
    Now i have some plan to use Jquery , i will appreciate if you could put some idea on that.
    Thanks,
    satya

  • Can we call COM component in JSP???????????

    Hi,
    I need to call a COM Component which is written in VB in my JSP Page. Is it possible to call??? If yes, plz let me know how with details? Fast and immediate reply will be appreciated...
    Thanks in advance
    A C Sekhar

    You do know that JSP runs on the server and produces HTML that runs on the browser, right? So do you want to call this COM component on the server or on the browser? If it's on the browser, then your question becomes "Can we call COM component in HTML (tiresome number of ?)". And this you can probably answer for yourself. If it's on the server, see the previous response by Breakfast.

  • Calling pdk component in webdynpro

    Dear All
    is it possible to call a pdk component in webdynpro
    Please provide your inputs
    Thanks
    Karthi D

    Karthik,
    When you say call a portal component, do you want to navigate away from your webdynpro and call a any portal component?
    If yes,It is possible to call portal component. Just create an Iview for the portal component and assign that into portal page.
    Call the component using EPCF navigation api inyour web dynpro by passing pcd location of the page.
    Ram

Maybe you are looking for

  • Change GL account for the valuation class

    Hi, Currently I have a valuation class SUPP which is assign to GL account 14800, now the customer have the request to change it to GL account 14100. There is an option to change it in Config OBYC, but there are a lot of materials involved and a lot o

  • Enterprise Manager Configin a new host after recovery from cold backup

    Dear friends , we have recovered a DB in new host(windows) from the cold backup. Listener is configured and EM is also configured . I am able to login through the EM . In the front page i get an error like java.lang.exception:unknownhost exception se

  • Break out session layout

    Adobe Connect 8 attendee can not see breakout room layout, why?

  • Call a function from a href in my irpt page

    I have an irpt that has three rows to a table.  The middle row is my iFrame.  The bottom row contains my hyperlink menu selections.  I would like to take my mouse over the particular word and do a hyperlink that calls a function to load the iframe wi

  • WLC 5508 Distribution Ports

    Dear Community, i have a small Q that should we configure any of distribution port of WLC 5508 with speed 10/100 to connect it with cisco's 3750 on fastethernet port. By default WLC ports are gig ports so is there any comand or option to configure th