473,396 Members | 1,970 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,396 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 1011

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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.