What's wrong on the superclass and subclass

Dear all,
The drawing panel cannot draw the figures, what's wrong?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class CustomPanel1 extends JFrame { 
private final String list[] = { "Circle", "Square", "Triangle"};
private FlowLayout layout1, layout2, layout3;
private DrawShape drawPanel;
private JButton clearButton;
public static JLabel label;
private JComboBox shapeList;
private JTextField textField1, textField2;
public static int size;
// set up GUI
public CustomPanel1() {   
// create custom drawing area
drawPanel = new DrawShape(this);
// set up ClearButton
clearButton = new JButton( "Clear" );
// add the ActionListeber
clearButton.addActionListener(
new ActionListener() { // anonymous inner class
// handle action perform event
public void actionPerformed( ActionEvent event ) {        
// clear originList
drawPanel.originList.clear();
drawPanel.area = 0;
drawPanel.perimeter = 0;
label.setText("Area " + drawPanel.area +
" Perimeter " + drawPanel.perimeter );
repaint();
}// end handle
} // end anonymous inner class
); // end call to addActionListener
//set up combox
shapeList = new JComboBox(list);
shapeList.setMaximumRowCount(3);
//add ItemListener
shapeList.addItemListener(
new ItemListener(){
// handle item state change event
public void itemStateChanged (ItemEvent event) {                  
if(event.getStateChange() == ItemEvent.SELECTED){
// draw circle
if( shapeList.getSelectedIndex() == 0){           
DrawCircle.shape = 0;
DrawCircle.draw(DrawCircle.Circle);
} // end if
// draw square
else if ( shapeList.getSelectedIndex() == 1) {           
DrawShape.shape = 1;
DrawSquare.draw( DrawSquare.Square);
} // end if
// draw triangle
else if ( shapeList.getSelectedIndex() == 2) {           
DrawShape.shape = 2;
DrawTriangle.draw( DrawTriangle.Triangle);
} // end if
} // end if
} // end handle
} // end anonymous inner class
); // end call to addActionListener
// set up parameter panel containing parameter
JPanel parameterPanel = new JPanel();
layout1 = new FlowLayout();
parameterPanel.setLayout(layout1);
parameterPanel.setBackground( Color.PINK );
layout1.setAlignment( FlowLayout.CENTER);
parameterPanel.add( new JScrollPane(shapeList));
parameterPanel.add( clearButton );
// set up the text Panel and textfield
JPanel textPanel = new JPanel();
layout3 = new FlowLayout();
parameterPanel.setLayout(layout3);
textPanel.setBackground( Color.PINK );
layout3.setAlignment( FlowLayout.CENTER);
textField1 = new JTextField( "Size");
textField1.setFont(new Font("Serif",Font.BOLD,14));
textField1.setEditable (false);
textField2 = new JTextField( "",6);
textField2.setFont(new Font("Serif",Font.BOLD,14));
// add ActionListener
textField2.addActionListener(
new ActionListener(){
// handle action perform event
public void actionPerformed (ActionEvent event) {         
JTextField field = (JTextField)event.getSource();
String entry = field.getText();
size = Integer.parseInt(entry);
} // end handle
} // end anonymous inner class
); // end call to addActionListener
textPanel.add(textField1, BorderLayout.NORTH);
textPanel.add(textField2, BorderLayout.SOUTH);
// set up the combine panel of parameterPanel and textPanel
GridLayout gridLayout = new GridLayout();
gridLayout.setRows(2);
gridLayout.setColumns(1);
JPanel combinPanel = new JPanel();
combinPanel.setBackground( Color.PINK );
combinPanel.setLayout(gridLayout);
combinPanel.add(parameterPanel, BorderLayout.NORTH);
combinPanel.add(textPanel, BorderLayout.SOUTH);
// set up datapanel conaining data
JPanel dataPanel = new JPanel();
layout2 = new FlowLayout();
dataPanel.setLayout(layout2);
dataPanel.setBackground( Color.PINK );
label = new JLabel ("Area " + drawPanel.area + "Perimeter " +
drawPanel.perimeter, SwingConstants.CENTER);
dataPanel.add( label);
// attach button panel & custom drawing area to content pane
Container container = getContentPane();
container.add( combinPanel, BorderLayout.NORTH);
container.add( drawPanel, BorderLayout.CENTER );
container.add( dataPanel, BorderLayout.SOUTH );
setSize( 500, 500 );
setVisible( true );
} // end constructor CustomPanelTest
// main
public static void main ( String args[] ) {   
CustomPanel1 app = new CustomPanel1();
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} // end main
} // end class CustomPanelTest
// A customized JPanel class.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
class DrawShape extends JPanel {
public final static int Circle = 0, Square = 1, Triangle = 2;
public static int shape;
public int xPos,yPos;
java.util.List originList;
public int count = 0;
public static double area ;
public static double perimeter ;
final double pi=3.141592;
CustomPanel1 client;
boolean shapeWasCreated = false;
public DrawShape(CustomPanel1 customer){     
this.client = customer;
// set up the list of shape to draw
originList = new ArrayList();
// set up mouse listener
addMouseListener(
new MouseAdapter() {  // anonymous inner class
// handle mouse press event
public void mousePressed( MouseEvent event )
xPos = event.getX();
yPos = event.getY();
originList.add(count, new String(
shape + "." + xPos + "," + yPos + "*" + CustomPanel1.size ));
// set to draw ready
shapeWasCreated = true;
repaint();
} // end handle
} // end anonymous inner class
); // end call to addMouseListener
} // end method
} // end class
// A customized JPanel class.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class DrawCircle extends DrawShape {
public static double circleArea, circlePerimeter;
public DrawCircle(CustomPanel1 customer){
super(customer);
} // end method
// use shape to draw an oval, rectangle or triangle
public void paintComponent( Graphics g )
super.paintComponent( g );
initializeShapeVariables();
for(int i = 0; i<originList.size(); i++){
String XY =(String)originList.get(i);
int star = XY.indexOf("*");
int dot = XY.indexOf(".");
int comma = XY.indexOf(",");
int shapeToDraw = Integer.parseInt(XY.substring(0,dot));
int pickedX = Integer.parseInt(XY.substring(dot + 1,comma));
int pickedY = Integer.parseInt(XY.substring(comma + 1, star));
int shapeSize = Integer.parseInt(XY.substring(star + 1));
int x = pickedX-(shapeSize/2);
int y = pickedY-(shapeSize/2);
// draw a circle
if ( shapeToDraw == Circle ) {        
g.drawOval(x ,y , shapeSize, shapeSize );
if(shapeWasCreated){
circleArea = (pi * (((double)(shapeSize)/2) * (((double)shapeSize)/2)));
area += circleArea;
circlePerimeter = (pi * (shapeSize));
perimeter += circlePerimeter;
CustomPanel1.label.setText("Area " + area + "Perimeter " + perimeter);
} //end if
} //end if
} // end for
if(shapeWasCreated)
shapeWasCreated = false;
} // end if
private void initializeShapeVariables(){
area = 0;
perimeter = 0;
circleArea = 0;
circlePerimeter = 0;
} // end method
// set shape value and repaint
public static void draw( int shapeToDraw )
shape = shapeToDraw;
//repaint();
} //end method
} // end class
// A customized JPanel class.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class DrawSquare extends DrawShape {
public static double squareArea, squarePerimeter;
public DrawSquare(CustomPanel1 customer){
super(customer);
} // end method
// use shape to draw an oval, rectangle or triangle
public void paintComponent( Graphics g )
super.paintComponent( g );
initializeShapeVariables();
for(int i = 0; i<originList.size(); i++){
String XY =(String)originList.get(i);
int star = XY.indexOf("*");
int dot = XY.indexOf(".");
int comma = XY.indexOf(",");
int shapeToDraw = Integer.parseInt(XY.substring(0,dot));
int pickedX = Integer.parseInt(XY.substring(dot + 1,comma));
int pickedY = Integer.parseInt(XY.substring(comma + 1, star));
int shapeSize = Integer.parseInt(XY.substring(star + 1));
int x = pickedX-(shapeSize/2);
int y = pickedY-(shapeSize/2);
if ( shapeToDraw == Square ){        
g.drawRect( x, y, shapeSize, shapeSize );
if(shapeWasCreated){
squareArea = ( shapeSize * shapeSize);
area += squareArea;
squarePerimeter = (4 * shapeSize);
perimeter += squarePerimeter;
CustomPanel1.label.setText("Area " + area + "Perimeter " + perimeter);
} //end if
} //end if
} // end for
if(shapeWasCreated)
shapeWasCreated = false;
} // end if
private void initializeShapeVariables(){
area = 0;
perimeter = 0;
squareArea = 0;
squarePerimeter = 0;
} // end method
// set shape value and repaint
public static void draw( int shapeToDraw )
shape = shapeToDraw;
//repaint();
} //end method
} // end class
// A customized JPanel class.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class DrawTriangle extends DrawShape {
public static double triangleArea, trianglePerimeter;
public DrawTriangle(CustomPanel1 customer){
super(customer);
} // end method
// use shape to draw an oval, rectangle or triangle
public void paintComponent( Graphics g )
super.paintComponent( g );
initializeShapeVariables();
for(int i = 0; i<originList.size(); i++){
String XY =(String)originList.get(i);
int star = XY.indexOf("*");
int dot = XY.indexOf(".");
int comma = XY.indexOf(",");
int shapeToDraw = Integer.parseInt(XY.substring(0,dot));
int pickedX = Integer.parseInt(XY.substring(dot + 1,comma));
int pickedY = Integer.parseInt(XY.substring(comma + 1, star));
int shapeSize = Integer.parseInt(XY.substring(star + 1));
int x1=pickedX-(shapeSize/2);
int y1=pickedY+(shapeSize/2);
int x2=pickedX+(shapeSize/2);
int y2=y1;
int x3=pickedX;
int y3=pickedY-((int)(1.73205*shapeSize*0.33333));
if (shapeToDraw == Triangle)
g.drawLine(x1, y1, x2, y2);
g.drawLine(x1, y1, x3, y3);
g.drawLine(x3, y3, x2, y2);
if(shapeWasCreated){
triangleArea = (double)(shapeSize * shapeSize/2);
area += triangleArea;
trianglePerimeter = (3 * (shapeSize));
perimeter += trianglePerimeter;
CustomPanel1.label.setText("Area " + area + "Perimeter " + perimeter);
} //end if
} //end if
} // end for
if(shapeWasCreated)
shapeWasCreated = false;
} // end if
private void initializeShapeVariables(){
area = 0;
perimeter = 0;
triangleArea = 0;
trianglePerimeter = 0;
} // end method
// set shape value and repaint
public static void draw( int shapeToDraw )
shape = shapeToDraw;
//repaint();
} //end method
} // end class

The drawing panel cannot draw the figures, what's
wrong?You can't have written this much code and then suddenly detected it doesn't work at all. You must now restart from the point where you had a working program. Then you add code is small increments and see to it that it works in each step and you understand why it works. This method is called stepwise refinement and it does wonders.

Similar Messages

  • Red highlight next to code in dreamweaver. What is wrong with the code and is it affecting the websi

    What is wrong with the code and is it affecting the website?

    Line 107 looks dodgy to me and it won't have any effect on your code.  However, it is a good idea to post a complete link to your CSS for us to see it in full and to validate it using external tools.  In fact, you could validate the CSS (and HTML) yourself..
    <http://jigsaw.w3.org/css-validator/>
    Good luck.

  • What's wrong with the display and what will be the solution?

    It shows greenish light on bottom left side every time I it turn on and last for 5-6 mins then It turn into white like brightness is  high on that part of the display. It's hard to notice that in a room if lights are on but can easily noticeable in a dark room. I have sent it to warranty but they said it's a rare problem if its not detectable by diagnosis (May be by software) then I will not get it fix under warranty. What i will do if they could not detect the problem through diagnosis? I am from Bangladesh i have purchased it from a authorized reseller in Bangladesh apple store is not available.
    Its MacBook Pro 15ins Retina Display purchased on February/2014.

    There is an internal screen problem or there is a software bug a lot has been wrong with the mac with retina its just because of the display, my advice just wait until Yosemite comes out then you will resolve your problem hope. Or you can always try an SMC reset just look that up on youtube! ~STEBDOR WAS HÈRE

  • What is wrong with the MLB and NHL applications?  ( I have a Roku2 in the house and they work fine there so it is not the providers.)

    Yesterday, both the MLB and NHL apps stopped working.  The NHL app loads and then does nothing.  The MLB app tells me "Error loading xml."  Both had been working fine until 4-8-15.

    Hi Bob_001,
    Thanks for using Apple Support Communities. Based on what you stated, it sounds like a few apps on the Apple TV are not responding. I would recommend that you read these articles, they may be helpful in troubleshooting your issue.
    Restore your Apple TV (2nd and 3rd generation) - Apple Support
    How to restart your Apple TV - Apple Support
    Cheers,
    Mario

  • What is wrong with the music and videos?

    All the music and every video on the music and video programs are not playing. The sound from every app, and the selection sounds are working but not anything from itunes. I t isn't only the volume or audio because when I press play the time does not start on the music, and the videos do not load. What would have caused this? Would this be something from the i tunes program, or a virus on my i pod?

    Try:
    - Reset the iPod. Nothing will be lost
    Reset iPod touch: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup
    - Restore to factory settings/new iPod.
    - Make an appointment at the Genius Bar of an Apple store.
    Apple Retail Store - Genius Bar

  • IPhone 4 cannot send/recieve calls/texts but is still able to connect to the internet. What is wrong with the phone and how do I fix it?

    A friend of mine has an iPhone4 (not 4s) and she has been dropping it when she was drunk. She also lost it for nearly a week and it got handed back to her, luckily. She blocked the phone after she lost it so that other's couldn't use her contract (which is paid by her father). When she received the phone back, she asked O2 to unblock it an they gave her a new sim card and asked her to wait 24 hours. It started working again, for about a day, where she could receive and send texts/calls and Internet - the lot! But after that day, she can no longer get any signal on her phone to send or receive calls or texts. We have tried putting the sim card in another phone to see if that was the problem, but it worked fine with full signal, so we're guessing that O2 aren't the problem. I'm guessing that it is the phone but I'm not sure whether it's a hardware issue or software. We've recently installed the new iOS5 today and it still doesn't work correctly. Do you think that some hardware needs to be replaced? I was wondering if anyone knew if the phone signal and 3G signal run on the same antena or different ones in the 4S?
    Thank you for your time and help in advance. Any help/knowledge will be much appreatiated.

    oh my god, i can't believe i am having the exact same situation as yours. i lost my phone for about 2 weeks and got it back. when it was lost I asked O2 to block it and later I asked them to unblock it after I got my phone back. My internet seems to be working fine, but I cant receive or make calls. I went to apple store to tell them about that, they did a factory setting, but still can't get it working and later told me that its not the phone's fault but O2's fault because I could see the O2 on top, with no any bars and she assumed that i would not have been able to see the O2 written on top if it wasn't O2 fault. I told them that I can use the internet from O2 however, but in reply she asked me to show the internet (i still wonder what she meant by that), I tried to explain that the internet is from my data plan, but no... she insisted me on showing the internet, i wonder what exactly did she wanted to prove by that. Or maybe she was in a hurry to get home, because it was almost at the end of the day. Anyway I have changed my sim and it seems to be working fine on another phone, but its the same problem in my iphone 4. I haven't been able to use my phone for more than a month now and its really frustating. I have booked another appointment with apple day after tomorrow, just hoping for the best now

  • The iPod touch 5 battery won't charge, the iPod battery gets hot and doesn't turn on...  What is wrong?  Can photos and data be retrieved?

    The iPod touch 5 battery won't charge, the iPod battery gets hot and doesn't turn on...  What is wrong?  Can photos and data be retrieved?

    - See:      
    iPod touch: Hardware troubleshooting
    - Try another cable. Some 5G iPods were shipped with Lightning cable that were either initially defective or failed after short use.
    - Try another charging source
    - Inspect the dock connector on the iPod for bent or missing contacts, foreign material, corroded contacts, broken, missing or cracked plastic.
    - Make an appointment at the Genius Bar of an Apple store. I suspect a hardware problem  due to the hotness. If iTunes can't see the iPod then uor only hope if to contact a data recovery company for getting data off the iPod. If you have an iPod backup you can restore another iPod, iPhone or iPad from the backup to get the data that was in the backup
    Apple Retail Store - Genius Bar                          

  • Hi my iph4s wont turn on or off and seems to be zoomed into a particular part of the screen, loads normally when rebooted the phone. what is wrong with it? and how would i go abouts fixing it?thanks

    hi my
    iph4s wont turn on or off and seems to be zoomed into a particular part of the screen, loads normally when rebooted the phone. what is wrong with it? and how would i go abouts fixing it?
    also recovery mode shows up as a red icon instead of a blue one, not jail broken or had any third party alterations
    thanks

    Reset the PRAM
    Reinstall the operating system from the dvd (you will not loose your data)

  • What's wrong with the activation server? i just bought my ipad wifi celllular... and have a 3g cellular network connection... when i press the bottom to activate my ipad it says the activation server cannot be reached. what to do then?

    what's wrong with the activation server? i just bought my ipad wifi celllular... and have a 3g cellular network connection... when i press the bottom to activate my ipad it says the activation server cannot be reached. what to do then?

    Hey aries35,
    I found the following that goes over troubleshooting the same issue for the iPhone. I know you have an iPad, but the steps should still apply:
    Perform the following steps:
    Restart the iPhone.
    Try another means of reaching the activation server and attempt to activate.
    Try connecting to a known-good Wi-Fi network if you're unable to activate using a cellular data connection.
    Try connecting to iTunes if you're unable to activate using Wi-Fi.
    Restore the iPhone.
    If you receive an alert message when you attempt to activate your iPhone, try to place the iPhone in recovery mode and perform a restore. If you're still unable to complete the setup assistant due to an activation error, contact Apple for assistance.
    via: iPhone: Troubleshooting activation issues
    http://support.apple.com/kb/TS3424
    Cheers,
    Delgadoh

  • What's wrong with the itunes store UAE? i couldnt buy my favorite songs and movies because there's no "music" and "movies" category. please do something... thanks!

    what's wrong with the itunes store UAE? i couldnt buy my favorite songs and movies because there's no "music" and "movies" category. please do something... thanks!

    You are not addressing Apple here...
    This is a User to User forum...
    iTunes Store: Which types of items can I buy in my country?

  • What's wrong with the IOS5 download, it downloads and then after its finished it says server timed out, how do i sort this out

    What's wrong with the IOS5 download, it downloads and then after its finished it says server timed out, how do i sort this out?

    The Firefox versions which come with many Linux distros have the default Mozilla Firefox updater disabled and use the distros built-in updater.
    See this - http://linuxforums.org.uk/netbooks/install-firefox-6-on-an-acer-aspire-one-running-linpus-lite-linux/

  • All of my apple sets (iphone, ipad and computer) cannot connect the app store since yesterday, what's wrong with the app store?

    All of my apple sets (iphone, ipad and computer) cannot connect the app store since yesterday, what's wrong with the app store? do you know? or do you have have the same experience?

    I still have access.  Must be your phone or your internet connection.

  • I can't print using airprint from my iPhone 4.  Everything with the phone and the printer and router are up to date.  I can print from my iPad 2 with no problems.  What's wrong with the iPhone 4?

    I can't print using airprint from my iPhone 4.  Everything with the phone and the printer and router are up to date.  I can print from my iPad 2 with no problems.  What's wrong with the iPhone 4?

    I just wanted to leave a note that it's working now. I'm not sure if it was the latest iTunes update that got it working or that i decided to start a new library instead of using the one i had backed up on Windows 8 (it didn't occur to me to check using the old library when i re-installed iTunes). But if anyone is having this problem, it might be worth trying again with a new installation of iTunes to see if the latest update works for you, and if not, try using a fresh library instead of a backup (by fresh library i mean discard your old library completely and start a new library, not just restore as new iPhone, a whole new library).

  • The printing of .pdf file from Project 2013 stops when the file name should be written. Project 2013 crashes. Does someone know what is wrong between Project 2013 and Adobe Acrobat 9?

    The printing of .pdf file from Project 2013 stops when the file name should be written. Project 2013 crashes. Does someone know what is wrong between Project 2013 and Adobe Acrobat 9?

    The Acrobat 9.x product family passed into "End of Support" mid-year of 2013.
    Acrobat 9 support of MS Project via PDFMaker stops with Office 2007.
    For Office 2013 support you must use Acrobat XI (11.0.1) or newer. 
    A good to have reference:
    https://helpx.adobe.com/acrobat/kb/compatible-web-browsers-pdfmaker-applications.html
    Acrobat Pro and Standard DC are what are currently available for purchase. 
    Be well...

  • What is wrong with the app store and how long before its fixed, im downloading atna very slow pash and i have a 10mb uncontested line.

    What is wrong with the app store and how long before its fixed, im downloading atna very slow pash and i have a 10mb uncontested line.

    Sorry, its on both my iphone 4s (2 iphones) and ipad2 that the app store is slow, I have done all the above and still when i download a 1 mb app it take about a half a hour just to download and previously it wasn't even a second. When browsing the web the devices are fast and internet speed is good, but when going in to app store it takes long to load and show me the new app, updates, featured app ect. We watch movie online and the streaming is brilliant. Even on my windows pc the app store is slow and sometimes says that i store could not be opened, i have also tried on my buddies wifi and there it does exactly the same which makes me think that its on apples side, but why do you not have any problems? 

Maybe you are looking for

  • Pictures not visible in 'faces'' folders

    I need some help with faces within Iphoto. I tagged all the people in my pictures. Most of the people are added in the right folder in ''faces''. However some are missing. When I go back to the particular picture and press the name of a specifi perso

  • Smart form driver program for VF23

    hi any one can tell me is there a standard driver program for a smartform to run  transaction VF23. There is a Standard SAP script program named RVADIL01 . Is there a similar driver program for Smartform for the same Invoice List Transaction .

  • Connection factories in clusters - Help asap!!

    Hi All, I have a clusterd envrionment with an admin server ,4 managed servers. the admin and managed server being on different machines. The DB Adapter has been deployed on all the servers available. Now , I created a connection factory , gave the da

  • Get info about the current call

    I need a solution (eg ANE) for information about the current call - event of success, of duration, of ending. Is that possible?

  • Problem finding a website to download photoshop elements 8 and 10

    Does anybody know where I can download Photoshop Elements 10 from.  I have the install disk and s/n, but my built in DVD player is not working.  I would actually prefer Elements 8 but I understand it is no longer available. Thanks