Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: A different code runs

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default A different code runs

    hello friends, need ur help, dnt knw what's wrong. A different code runs(i.e a code i ran previously) instead of the present code on my editor that i tried running after coding. here is the present code
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
     
    public class gui11 extends JPanel{
    	public void paintComponent(Graphics g){
    		super.paintComponent(g);
    		this.setBackground(Color.WHITE);
     
    		g.setColor(Color.BLUE);
    		g.drawLine(10, 25, 200, 45);
     
    		g.setColor(Color.RED);
    		g.drawRect(10, 55, 100, 30);
     
    		g.setColor(Color.GREEN);
    		g.fillOval(10, 95, 100, 30);
     
    		g.setColor(Color.ORANGE);
    		g.fill3DRect(10, 160, 100, 50, true);
     
     
    	}
     
    }
    the previous code that wouldnt stop running is
    package gui;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
     
    public class Gui10 extends JPanel{
     
    	public void paintComponent(Graphics g){
    		super.paintComponent (g);
    		this.setBackground(Color.WHITE);
     
    		g.setColor(Color.BLUE);
    		g.fillRect(25, 25, 100, 30);
     
    		g.setColor(new Color(190,81,215));
    		g.fillRect(25, 65, 100, 30);
     
    		g.setColor(Color.RED);
    		g.drawString("this is some text", 25, 120);
     
    	}
     
     
    }
    i'll be gratefull to knw the cause soln, both code are same package. thanks!


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: A different code runs

    What do you mean "A different code" runs.
    What do you mean "the previous code that wouldn't stop running"
    I do not see anything wrong with either class posted, what seems to be the problem?
    What code are you using to create these "JPanels" and display them?

  3. The Following User Says Thank You to jps For This Useful Post:

    chized (May 23rd, 2013)

  4. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: A different code runs

    i use eclipse, tried running the first class, doesnt show any error but, the second class runs instead. it seems the second class is overwritting or stoping the first class from running(or showing). cant see the output of ths first class . thanks

  5. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: A different code runs

    What code are you using to create and display these JPanels?
    What type of output do you expect to get from a paintComponent method in an otherwise empty class?

  6. #5
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: A different code runs

    i finally found my mistake, am newbie. both class use same main, i didnt put the name of newer class in the main, that's why the previous class kept running. tnx

Similar Threads

  1. java using textpad. Atm code not having any syntax error but runs funny
    By bukasmayor in forum What's Wrong With My Code?
    Replies: 8
    Last Post: January 28th, 2013, 07:55 AM
  2. My code runs forever without output
    By jbinsomnia in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 8th, 2011, 07:53 AM
  3. while(true){ section of code runs 200 times}
    By jack_nutt in forum Java Theory & Questions
    Replies: 7
    Last Post: June 23rd, 2011, 07:06 AM
  4. while(true){ section of code runs only once}
    By jack_nutt in forum Java Theory & Questions
    Replies: 5
    Last Post: June 19th, 2011, 06:15 PM
  5. runs once only
    By silverspoon34 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 21st, 2009, 03:31 AM