Why the graphics doesn't show on screen?

I wrote the code using AWT to draw an Arc2D to window after received input numbers but it draws nothing to screen. I tried to debug and found nothing. Can someone help me on this?
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
public class PieChart extends JFrame implements ActionListener
private JPanel inputP;
private DrawPanel drawP;
private JLabel instruct, prompt1, prompt2, prompt3, prompt4; //all prompt labels
private JTextField num1, num2, num3, num4; //input text field
int value1, value2, value3, value4, total;
//Graphics2D g2d;
public PieChart()
super( "Drawing 2D PieChart" );
Container c = getContentPane();
c.setLayout(new FlowLayout());
     inputP = new JPanel();
inputP.setLayout(new GridLayout(4,2));
                                                                                //initial text prompts
instruct = new JLabel("Enter the number at each prompt and press enter");
     prompt1 = new JLabel("First Number:");
prompt2 = new JLabel("Second Number:");
     prompt3 = new JLabel("Third Number:");
prompt4 = new JLabel("Fourth Number:");
                                                                                //initial input fields
num1 = new JTextField(5);
     num1.addActionListener(this);
     num2 = new JTextField(5);
     num2.addActionListener(this);
     num3 = new JTextField(5);
     num3.addActionListener(this);
     num4 = new JTextField(5);
     num4.addActionListener(this);
     inputP.add(prompt1);
     inputP.add(num1);
     inputP.add(prompt2);
     inputP.add(num2);
     inputP.add(prompt3);
     inputP.add(num3);
     inputP.add(prompt4);
     inputP.add(num4);
     c.add(inputP, BorderLayout.NORTH);
drawP = new DrawPanel(350,180);
drawP.add(instruct);
c.add(drawP, BorderLayout.CENTER);
setSize( 350, 560 );
show();
public void actionPerformed(ActionEvent e)
          String getInput;
          if(e.getSource() == num1)
               getInput = num1.getText();
               value1 = Integer.parseInt(getInput);
num2.grabFocus();
          if(e.getSource() == num2)
               getInput = num2.getText();
               value2 = Integer.parseInt(getInput);
num3.grabFocus();
          if(e.getSource() == num3)
               getInput = num3.getText();
               value3 = Integer.parseInt(getInput);
               num4.grabFocus();
          if(e.getSource() == num4)
               getInput = num4.getText();
               value4 = Integer.parseInt(getInput);
               drawP.setPie(value1, value2, value3,value4);
The main function will generate the new PieChart object and Overridden so we can exit when window is closed.*********************/
public static void main( String args[] )
PieChart app = new PieChart();
app.addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent e )
System.exit( 0 );
}//endmain
class DrawPanel extends JPanel {
//private int currentChoice = -1; // don't draw first time
private int width = 100, height = 100;
private int vl1, vl2, vl3, vl4, total ;
Graphics2D g2d;
public DrawPanel( int w, int h )
width = ( w >= 0 ? w : 100 );
height = ( h >= 0 ? h : 100 );
public void paintComponent( Graphics g )
super.paintComponent( g );
// create 2D by casting g to Graphics2D
g2d = ( Graphics2D ) g;
if(total == 0 )
g2d.setPaint(Color.black);
g2d.setStroke(new BasicStroke(1.0f));
g2d.draw(new Arc2D.Double(250,90,80,100,0,360,Arc2D.PIE));
System.out.print("Done drawing a cirle");
}else // draw 2D pie-shaped arc in white
g2d.setPaint( Color.cyan );
g2d.setStroke( new BasicStroke( 2.0f ) );
g2d.fill(new Arc2D.Double(120,90,80,100,0,(vl1*360/total),Arc2D.PIE));
g2d.setPaint( Color.blue );
g2d.setStroke( new BasicStroke( 2.0f ) );
g2d.fill(new Arc2D.Double(120,90,80,100,(vl1*360/total),(vl2*360/total),Arc2D.PIE));
g2d.setPaint( Color.green );
g2d.setStroke( new BasicStroke( 2.0f ) );
g2d.fill(new Arc2D.Double(120,90,80,100,(vl2*360/total),(vl3*360/total),Arc2D.PIE));
g2d.setPaint( Color.red );
g2d.setStroke( new BasicStroke( 2.0f ) );
g2d.fill(new Arc2D.Double(120,90,80,100,(vl3*360/total),(vl4*360/total),Arc2D.PIE));
System.out.print("End of drawing ");
public void setPie( int v1, int v2, int v3, int v4 )
total = 0;
vl1 = v1;
vl2 = v2;
vl3 = v3;
vl4 = v4;
total = v1 + v2 + v3 + v4;
System.out.print(v1+ " "+ v2+" "+v3+" "+v4+ " Total value: " + total);
repaint();
}

The first thing I see is the you have declared 'total' in DrawPanel. As it is never set there, you are testing a variable which is always zero.

Similar Messages

  • When i click on a photo to edit, the photo doesn't show up and the area where the photo should show up is black.  Why?

    When i click on a photo to edit, the photo doesn't show up and the area where the photo should show up is black.  Why?  I can edit some photos, whereas others I can not.

    There are several possible causes for the Black Screen issue
    1. Permissions in the Library: Back Up and try rebuild the library: hold down the command and option (or alt) keys while launching iPhoto. Use the resulting dialogue to rebuild. Include the option to check and repair permissions.
    2. Minor Database corruption: Back Up and try rebuild the library: hold down the command and option (or alt) keys while launching iPhoto. Use the resulting dialogue to rebuild.
    3. A Damaged Photo: Select one of the affected photos in the iPhoto Window and right click on it. From the resulting menu select 'Show File (or 'Show Original File' if that's available). (On iPhoto 11 this option is under the File -> Reveal in Finder.) Will the file open in Preview? If not then the file is damaged. Time to restore from your back up.
    4. A corrupted iPhoto Cache: Trash the com.apple.iPhoto folder from HD/Users/Your Name/Library/ Caches...
    5. A corrupted preference file: Trash the com.apple.iPhoto.plist file from the HD/Users/ Your Name / library / preferences folder. (Remember you'll need to reset your User options afterwards. These include minor settings like the window colour and so on. Note: If you've moved your library you'll need to point iPhoto at it again.)
    If none of these help:
    As a Test:
    Hold down the option (or alt) key key and launch iPhoto. From the resulting menu select 'Create Library'
    Import a few pics into this new, blank library. Is the Problem repeated there?

  • Hi there, i have a ipod nano general 7, just used one year. Now can't charge battery. When charging, the icon shows full power, but disconnect it. It becomes dark, no power. Why, the battery doesn't work ?

    I've a ipod nano general 7, I've just used it one year. Now, I can't charge the battery. When charging, the icon shows full power. But when I disconnect, the ipod becomes dark, no power is keeped. Why, the battery doesn't work ? the life of my ipod's battery is too short ? 

    Howdy tamsg,
    Welcome to Apple Support Communities.
    The article linked below provides a lot of great troubleshooting tips that can help you resolve the issue with your iPod nano charging or displaying a blank black screen.
    iPod nano (7th generation): Hardware troubleshooting - Apple Support
    So long,
    -Jason

  • When i add a new contact to my phone, their details are saved in my contact list, but the name doesn't show up when they ring or txt me, how can i change that?

    when i add a new contact to my phone, their details are saved in my contact list, but the name doesn't show up when they ring or txt me, how can i change that?

    First, try a system reset.  It cures many ills and it's quick, easy and harmless...
    Hold down the on/off switch and the Home button simultaneously until the screen blacks out or you see the Apple logo.  Ignore the "Slide to power off" text if it appears.  You will not lose any apps, data, music, movies, settings, etc.
    If the Reset doesn't work, try a Restore.  Note that it's nowhere near as quick as a Reset.  Connect via cable to the computer that you use for sync.  From iTunes, select the iPad/iPod and then select the Summary tab.  Follow directions for Restore and be sure to say "yes" to the backup.  You will be warned that all data (apps, music, movies, etc.) will be erased but, as the Restore finishes, you will be asked if you wish the contents of the backup to be copied to the iPad/iPod.  Again, say "yes."
    Finally, if the Restore doesn't work, let the battery drain completely.  Then recharge for at least an hour and Restore again.

  • WiFi ON/OFF button Doen't Work, the IPod doesn't show the on/off button in the Settings- General - WiFi

    After My IPod Touch 4th Geneartion was broken I had to fix the screen, which cost me a lot, after a perfect restore through the ITunes I went to connect to my IPod to the WiFi network then the WiFi ON/OFF button Doen't Work, the IPod doesn't show the on/off button in the Settings-> General -> WiFi.
    And another problem I encountered during this operation was that the Games I downloaded through the ITunes doesn't work, when I click on the icon ( Game Icon) it starts an then closes in a few seconds

    See:
    iOS: Wi-Fi or Bluetooth settings grayed out or dim
    One user reported that placing the iPod in the freezer fixed the problem. A trick that works frequently with iPhones:
    Settings > AirPlane Mode ON, Do Not Disturb ON
    Power down and wait 5-10 minutes
    Power up
    Settings > AirPlane Mode OFF, Do Not Disturb OFF
    If not successful, an appointment at the Genius Bar of an Apple store is usually in order.
    Apple Retail Store - Genius Bar
    Apple wil not help since yo took the iPod apart
    Try taking  it apart and look for a disconnected antenna.
    Installing iPod Touch 4th Generation Wi-Fi Antenna - iFixit

  • I can't open my iPod library in iTunes, the app doesn't show the device at all, no error message, nothing, but windows 8 opens it like it would a flash drive. It has worked for me before just fine and both have the most updated software versions.

    I can't open my iPod library in iTunes, the app doesn't show the device at all, no error message, nothing, but windows 8 opens it like it would a flash drive. It has worked for me before just fine and both have the most updated software versions. HELP PLEASE!

    yeah i plugged in my iphone to my computer and itunes does not even notice that i plugged it in.

  • How can I import pictures from my iphone to PC which I imported to the iphone from another PC? The folder doesn't show on my computer. I see all other pictures I took with the phone but not the imported folder.

    How can I import pictures from my iphone to PC which I imported to the iphone from another PC? The folder doesn't show on my computer. I see all other pictures I took with the phone but not the imported folder.

    Photos that were synced from a computer won't show for copying to a computer. If you want to copy them back then you will need a third-party app on your phone such as Simple Transfer which can copy them off via your wifi network. But photos are 'optimised' when they are synced to a device, any that you then copy back to a computer may not be exactly the same as they originally were on your computer (e.g. their dimensions might be different and their colours may look a bit different).

  • I have updated to the latest version of iTunes (11.2.2.3). However, when I connect my iPod it shows in My Computer and iTunes opens automatically when the iPod is connected but the device doesn't show in iTunes.  Any ideas?

    I have updated to the latest version of iTunes (11.2.2.3). However, when I connect my iPod it shows in My Computer and iTunes opens automatically when the iPod is connected but the device doesn't show in iTunes.  Any ideas?  I am on Windows 8.1 and my iPod is a Classic

    Hi murr18140,
    Welcome to the Support Communities!  The article below will help you troubleshoot the issue you are having with your iPod classic not being recognized in iTunes for Windows:
    iPod: Appears in Windows but not in iTunes
    http://support.apple.com/kb/TS1363?viewlocale=en_US
    I hope this information helps ....
    - Judy

  • Why the preloader doesn't work in IE 8 but works in FireFox?

    Why the preloader doesn't work in IE 8 but works in FireFox?
    Please see the attached files.  Thanks in advance.

    Why doesn't the preloader work in IE8?
    What's "virtual sandbox"?

  • I have connected a new (set up for mac) seagate external HD and although file sharing is turned on the HD doesn't show up on any of the other computers on our network??????  Please help!!!!!

    I have connected a new (set up for mac) seagate external HD and although file sharing is turned on the HD doesn't show up on any of the other computers on our network??????  Please help!!!!!

    If the HD is setup for Mac and plugged into the AE.. with file sharing on, it should work.
    Try manually mounting the disk.
    In finder use go, connect to server, and type in AFP://AEName or AFP://AEIPaddress.. where you replace what I wrote with the actual name or actual IP.
    Later versions of Mac OS.. like ML for some strange reason have their preferences set by default to not show network drives.. change finder preference to see everything.

  • When I perform a split audio edit, the timeline doesn't show it when the clips are collapsed!

    Especially the clip whose audio is 'covering' another... the timeline doesn't show it's audio as extending, and it would appear only that the clip for which audio has been shortened, is still there, or at "0"... what gives? If you uncollapse the audio, or detach it, you do, once again, see the split audio.
    Thanks

    libovh wrote:
    Especially the clip whose audio is 'covering' another... the timeline doesn't show it's audio as extending, and it would appear only that the clip for which audio has been shortened, is still there, or at "0"... what gives? If you uncollapse the audio, or detach it, you do, once again, see the split audio.
    Thanks
    Like Zambonisurfer suggested, this is so by design.

  • When I rip a cd, then use another program, then come back to itunes, the cd stops ripping and the cd doesn't show up in the side bar anymore. What's going on here?

    When I rip a cd in itunes, then go to use another program, then come back to itunes, the cd stops ripping and the cd doesn't show up in the side bar anymore. What's going on here?  I am running the x64 version of itunes in Windows 7.

    Just wanted to say that you're not the only one with the problem: http://discussions.apple.com/thread.jspa?messageID=13009436

  • I'm trying to set up time machine to back up on an external HD connected t my airport extreme, but the disk doesn't show as an option in the time machine selecting a disk, any suggestion anyone? My mac "sees" the airport extreme   ??

    I'm trying to set up time machine to back up on an external HD connected t my airport extreme, but the disk doesn't show as an option in the time machine selecting a disk, any suggestion anyone? My mac "sees" the airport extreme   ??

    The first important thing to consider here is that Apple does not support Time Machine backups to a drive at the USB port on the AirPort Extreme, so that may likely have something to do with your difficulties.
    If you want to continue to try this, the drive must be formatted in Mac OS Extended (Journaled) and you almost always have to use a powered USB hub with a drive at the port of the Extreme...even if the hard drive has its own power supply....because the port on the Extreme is under powered.
    Most users who try this unsupported method have corruption difficulties sooner or later, but we do hear from some users who seem to be able to make it work.
    The bottom line is that there is no support from Apple on this if you have difficulties, so you may want to consider a secondary backup plan for your important data.

  • Why the imsg doesn't work without a sim card with iOS 7???

    Why the imsg doesn't work without a sim card with iOS 7???

    If it worked for you using iOS 6, then it appears iOS 7 has made some changes.  Was it working before?

  • Why the iPhone dose not show the witting in case if the other person have a call and I'm on witting?

    Why the iPhone dose not show the witting in case if the other person have a call and I'm on witting? really I'm dissappointed with this point Why we do not have this service?

    That is not a feature of the iPhone (or of any phone I've ever had so apparently it's far from universal). Apple has not said why they have no such feature.
    You can request such a feature here:
    http://www.apple.com/feedback
    Either the person you're calling will answer you or they won't. What difference does it make why?

Maybe you are looking for

  • PHP and oracle problem

    Hi, I'm trying to create a chart with php ad oracle. I'm using this code <?      function Num_of_Rows($column, $status, $table){                                    $conn = oci_pconnect("$username", "$passwd", "$host");                $sql_query = "SE

  • HT204074 Can't find "manage devices" in itunes...

    I want to remove a device from itunes. Apple says: Removing an associated device or computer from an Apple ID To remove a device or computer from your Apple ID: Open iTunes. Sign in to your Apple ID by choosing Store > Sign In from the iTunes menu. C

  • Report Painter guide

    Hello, Kindly provide documentation on Report painter for step by step creation of Report through Report painter. please send Thanks a lot for your valuable cooperation. points will be rewarded.. Jignesh

  • Error message in va02

    Hi, When i am any sale document in va02 , its giving error message as 'Specify either address number or address handle'. I searched in sdn, but no solution found. Provide any solution Thanks in advance

  • Demantra Integration Interface - export

    Hi all, I'm trying to export the results after each forecast and for that I created an workflow that containes a transfer step which refers to a Export Integration Interface. -I set the following series to be exported: sales_date, history, forecast,