• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 162
  • Last Modified:

Graphics problem... Won't draw our damn oval!

We have some problems drawing an oval. The program is running, but it won't draw(fill) the oval.
The graphics object have been initialized.  

This code lies in a JPanel, that is used in a JApplet.
The code workes if we paste it into a new class(see below) but not in our situation...
Does anybody have an idea?

Thanks!


public void drawSpot(){
         
        Graphics g = getGraphics();
       
        g.setColor(new Color(0, 255, 55));      
        g.fillOval(100,100,15,15);
       
    }

==============================NEW CLASS==============================

package gui;

import java.awt.*;
public class testing1234 extends javax.swing.JApplet {
   
    private javax.swing.JButton jButton1;

    public testing1234() {
        initComponents();
     
    }
    public void drawSpot(){
         
        Graphics g = getGraphics();
       
        g.setColor(new Color(0, 255, 55));      
        g.fillOval(100,100,15,15);
       
    }
 
    private void initComponents() {
        jButton1 = new javax.swing.JButton();

        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        getContentPane().add(jButton1, java.awt.BorderLayout.CENTER);

    }

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
          drawSpot();
    }
   
   
}
0
ballahalla
Asked:
ballahalla
1 Solution
 
CEHJCommented:
Best to put the drawing code inside the overridden paintComponent(Graphics g) of the JPanel.
0
 
CleanupPingCommented:
ballahalla:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
girionisCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points to CEHJ

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

girionis
EE Cleanup Volunteer
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now