473,388 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Can someone tell why is paint method executing eventhough it is not called

Expand|Select|Wrap|Line Numbers
  1. import javax.swing.*;
  2. import java.awt.*;
  3.  
  4. public class ShapeTest extends JFrame{
  5.      public ShapeTest(){
  6.           setSize(400,400);
  7.           setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  8.          // setLocationRelativeTo(null);
  9.           setVisible(true);
  10.      }
  11.  
  12.      public static void main(String a[]){
  13.          new ShapeTest();
  14.      }
  15.  
  16.      public void paint(Graphics g){
  17. g.setColor(Color.RED);
  18.          // g.drawOval(40, 40, 60, 60); //FOR CIRCLE
  19.           g.drawRect(80, 30, 200, 200); // FOR SQUARE
  20.        //   g.drawRect(200, 100, 100, 200); // FOR RECT
  21.      }
  22. }
Aug 21 '15 #1

✓ answered by chaarmann

You are extending your class from JFrame. That means that your class also has all methods that JFrame has but that are not in your code listing.

Some of these methods in JFrame registers a listener. This is a class that calls the paint-method that you have written. It can call your paint method any time, for example when the screen needs to be refreshed.

That means the call is not originated in your class, but will happen from outside by other classes. That's why the paint() method is also called a callback-method.

2 1420
The jvm engine calls the paint method every time the operative system reports that the canvas has to be painted. When the window is created for the first time, paint is called by the JVM. The paint method is also called if we minimize and after we maximize the window and if we change the size of the window with the mouse.
Aug 31 '15 #2
chaarmann
785 Expert 512MB
You are extending your class from JFrame. That means that your class also has all methods that JFrame has but that are not in your code listing.

Some of these methods in JFrame registers a listener. This is a class that calls the paint-method that you have written. It can call your paint method any time, for example when the screen needs to be refreshed.

That means the call is not originated in your class, but will happen from outside by other classes. That's why the paint() method is also called a callback-method.
Sep 2 '15 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: DraguVaso | last post by:
Hi, In the override of the Paint-method of a DataGridTextBoxColumn I want to show an image with BitBlt, to see what I can gain there on performance. The problem is: It doesn't show me the image...
0
by: John Richardson | last post by:
I have a DataGridLabelColumn I've made by overriding a DataGridColumnStyle object. (based on an MSDN article by Chris Sano). In the Paint method, I use a StringFormat object, and pass that to a...
1
by: tony | last post by:
Hello!! Hello Victor! I use a product called flygrid to create grid tables. In many of my forms I create such grid tables. Some columns in these grid tables is of type drop down list where I...
2
by: void.no.spam.com | last post by:
I'm a novice at Python, and found some code samples on how to use threads. My script is being run by a product that contains a Jython interpreter. Can someone please explain why I get the...
6
by: bryanbabula | last post by:
I have a question about overriding i was wondering if anyone could help me with, or even suggesting a better/different way. I have no idea if this can even be done or not. I was wondering if there...
0
by: TarTar | last post by:
Hello, I have the following code on my ASP.NET page: <asp:DataList ID="CustomersList" DataSourceID="CustomerDataSource" runat="server"> <ItemTemplate> Name: <asp:Label id="lblName" Text='<%#...
3
by: natraj A V | last post by:
Which method will be called when executing a .exe file?
1
by: Rudiger Diezman | last post by:
I am using a tabbed pane with four tabs - three of which work perfectly - the fourth one is supposed to display an image but does NOT ever call the paint method. When I use the same ImagePanel code...
0
by: CodeNoob117 | last post by:
I am making a game in which it has a JFrame that contains a gridlayout full of Jlabels. I want to make a separate image class that can be added to the JLabels. So far, I have been trying to override...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.