473,408 Members | 1,876 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,408 software developers and data experts.

JPanel colour not changing

I was writing a code to change the colour of frame continuously but it is not happening,Can someone point the mistake in my code.

Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import javax.swing.*;
  3. class cr{
  4.         Color c[] = { Color.BLUE , Color.GREEN , Color.RED };
  5.         int i=0;
  6.         public void design()
  7.         {
  8.                 JFrame f = new JFrame();
  9.                 f.setSize(200,200);
  10.                 f.setVisible(true);
  11.                 f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  12.                 DrawPanel p = new DrawPanel();
  13.                 f.add(p);
  14.                 while(true)
  15.                 {
  16.                         p.repaint();
  17.                         try
  18.                         {
  19.                                 Thread.sleep(5);
  20.                                 i++;
  21.                         }
  22.                         catch(Exception e)
  23.                         {
  24.                                 System.out.println("error");
  25.                         }
  26.                 }
  27.         }
  28.         public class DrawPanel extends JPanel{
  29.                 public void PaintComponent(Graphics g)
  30.                 {
  31.                         g.setColor(c[i%3]);
  32.                         g.fillRect(0,0,this.getWidth(),this.getHeight());
  33.                 }
  34.         }
  35.         public static void main(String args[])
  36.         {
  37.                 cr c = new cr();
  38.                 c.design();
  39.         }
  40. }
  41.  
  42.  
  43.  
Oct 12 '15 #1
0 1012

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

Similar topics

1
by: xtrmntr: a northern soul | last post by:
alright there, i'm pretty much throwing myself on everyone here's mercy, as i'm struggling to even articulate what i mean, never mind create the behaviour i want. i've a website with a...
7
oll3i
by: oll3i | last post by:
i want to change the values in two columns one colum is a combobox and the secons column is editable too i want to get the value of that second column and the value of combobox and sent that...
1
by: nt5515 | last post by:
hey Im trying to make a game of pairs (the memory game) i have set up a grid which displays a graphic for the card back. im trying to link the edit menu to choose the graphic to be displayed. i've...
8
by: eddiewould | last post by:
Hi, I want to write a custom widget which will act similarly to a JPanel (i.e it can contain other Components), but semantically it's not a kind of JPanel so it shouldn't extend from it. Here is...
1
by: Akino877 | last post by:
Hello, I have a question regarding Java and Swing programming I wonder if I could ask the forum for some help. I have a JPanel that has a couple of radio buttons and an "OK/Next" button on it. ...
1
TheMan1
by: TheMan1 | last post by:
Hi guys. I have a mouse event on my frame that enlarges the size of a JPanel that in on a JScrollPane. When the JPanel's size changes, the JScrollPane's scrollbars don't "refresh" ie. their max...
4
by: sgxbytes | last post by:
Hi, My html has <Table style="year-button-archive" width="60%" > <tr> <td class="gold" > <a title="year">By Year:</a> <td class="gold"> <a id = "2008"...
0
Matthewborg
by: Matthewborg | last post by:
I am doing an assignment which it consists of an Applet, where the user has to insert several values and the program has to draw a quadratic graph. In my applet I want to display the graph in the...
0
by: javalex | last post by:
I've been spending a lot of hours fixing this, I'm a 2nd year college student in Computer Science, my professor lack time teaching us about this and she gave us our final project for the semester and...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.