Can someone test my Java 2D application? Something gone abit weird/wrong..

Hi there
I have just written a Java 2D Graphics Application. I think its complete but the problem is when i run it, it come out with weird result.
Below is my code:
import java.awt.*;
import javax.swing.*;
public class GraphicsView extends JPanel{
     private double px = 50;
     private double py = 50;
     private double qx = 200;
     private double qy = 50;
     private double rx = 50;
     private double ry = 200;
     private double sx = 200;
     private double sy = 200;
     public GraphicsView(){
     public void paintComponent(Graphics g){
          super.paintComponent(g);
          g.drawLine((int)px, (int)py, (int)qx, (int)qy);
          g.drawLine((int)px, (int)py, (int)rx, (int)ry);
          g.drawLine((int)qx, (int)qy, (int)sx, (int)sy);
          g.drawLine((int)rx, (int)ry, (int)sx, (int)sy);
          double u = 0.1;
          for(int k = 0; k < 55; k++){
               px = ((1 - u) * px) + (u * qx);
               py = ((1 - u) * py) + (u * qy);
               qx = ((1 - u) * qx) + (u * sx);
               qy = ((1 - u) * qy) + (u * sy);
               sx = ((1 - u) * sx) + (u * rx);
               sy = ((1 - u) * sy) + (u * ry);
               rx = ((1 - u) * rx) + (u * px);
               ry = ((1 - u) * ry) + (u * py);
               g.drawLine((int)px, (int)py, (int)qx, (int)qy);
               g.drawLine((int)qx, (int)qy, (int)sx, (int)sy);
               g.drawLine((int)sx, (int)sy, (int)rx, (int)ry);
               g.drawLine((int)rx, (int)ry, (int)px, (int)py);
import java.awt.*;
import javax.swing.*;
public class Program extends JFrame {
     public Program(){
          makeStuff();
     public void makeStuff(){
          setPreferredSize(new Dimension(350,300));
          getContentPane().add(new GraphicsView());
          pack();
          setVisible(true);
        public static void main(String[] args) {
          Program program = new Program();
}The problem is that:
When i maximise it the 2D drawing appears weird, out of position, fuzzy & totally messed up! AND when i minimize it back to original window frame size - The 2D drawing totally disappeared/Gone!!!
Anyone know why is that a problem?
Is it a Swing problem? Or Java 2D problem?
oh- above 2 segments of code represent a class each respectively...

You're trying to do program logic within the paintComponent method. When your paintComponent method ends, lord knows what the final value of your different x and y variables are. They certainly aren't the same values as when you first did the drawing. What ends up happening is that hte drawing is likely done, but is very very small. Throw in some System.out. println's and you'll see.
I recommend that you do all your equations outside of the paintComponent, and save the line coordinates in an ArrayList of objects of a class you can create. Then have the paintComponent simply iterate through the arraylist drawing based on the values in the objects held by the list.
Edit: one easy object to use is a Line2D and then have your arraylist hold these objects. Then simply use a Graphics2D object to draw all the Line2D's held in the list.
Edited by: Encephalopathic on Oct 7, 2008 8:33 PM

Similar Messages

  • Crackling loudspeaker? Can someone test this for me?

    I've noticed something that might be abnormal about the speakers on my iPhone 4S.
    Could someone test this for me please? Go to ringtones, and play the 'bell tower' ringtone making sure your ringer volume is all the way up. Listen closly to the speaker, can you notice a slight crackling sound at parts?
    Thanks

    So when you play the bell tower tone at full volume it sounds perfectly cripst and doesn't 'crackle' or distort a little bit because mine does.
    Also when I've asked siri a question, the tone after that when it plays sounds like it distorts a bit to.
    Cheers

  • Cracking Loudspeaker? Can someone test this for me

    I've noticed something that might be abnormal about the speakers on my iPhone 4S.
    Could someone test this for me please? Go to ringtones, and play the 'bell tower' ringtone making sure your ringer volume is all the way up. Listen closly to the speaker, can you notice a slight crackling sound at parts?
    Thanks

    So when you play the bell tower tone at full volume it sounds perfectly cripst and doesn't 'crackle' or distort a little bit because mine does.
    Also when I've asked siri a question, the tone after that when it plays sounds like it distorts a bit to.
    Cheers

  • How to launch my RESTful TEST with JAVA EE application in NetBeans 6.5

    Hi, I want to TEST my RESTful WebService in my JAVA Enterprise Application.
    I have a bit database in my EJB Module. Resuming, I have two modules (EJB + WAR) and Enterprise Application (JAVA EE that contains the before modules). Appears two kind of errors:
    1) When I only deploy JAVA Enterprise Project an then I run my TEST Restful, appears an error that says: "Another module has been deployed" . This error is about JAVA Enterprise Application has been deploy before.
    2) If I only deploy TEST Restful, this doesn't find Facaderemote class of my EJB Module, because WAR Project hasn't the EJB references.
    Thanks a lot.

    VM7, welcome to the forum. Please don't post in threads that are long dead and don't hijack other threads. When you have a question, start your own topic. Feel free to provide a link to an old post that may be relevant to your problem.
    I'm locking this thread now.
    db

  • Can I setup a Java Web Application on Business Catalyst?

    I wanted to know if I can upload a Java Web Application on to Business Catalyst.  What kind of features are supported, etc, for Java Developers, ex. Spring, Jar Integration, etc.
    Thank You.

    Hi there,
    No you cant. You can not install any server side programming on BC. It is a closed system. it is also .NET based.

  • I can't install Sun Java System Application Server!! Who can help me??

    I download Sun Java System Application Server(sjsas_pe-9_0_01-p01-windows.exe),and the first time of my installation, it was blocked after it was istalled 14%, half an hour later I canceled the installation and wanted to re-install it, and I tried many times,but every time after I choose the "Installation Directory" and cliced the "Next" button it would be blocded, all of the bttons was disabled except "Choose directory" and "X"(close) buttons.
    OS: Win2000 Service Pack 4
    Thanks in advance

    Yeah, I had the same problem!
    And The Wiki helped me http://wiki.java.net/bin/view/Projects/WinHang
    Even my Firewall had the function "Disabled Mode", I needed to fully stop all the services of Antivirus and Firewall. After that i deleted the "productregistr*" file and ran installation from the console.
    And it was the only right way to install!
    Now enjoying =)

  • What are popular automated tests for Java GUI applications

    Hi, I want to find a good automated test for java swing for my project. I have a list of UISpec4j, JFCUnit and Abbot.

    There is also jemmy. I haven't used any of them, though...
    -Puce

  • Can someone test a prog for me, and help reading from an exty file

    Okay, I have a program to calculate the Pearson product-moment correlation coefficient ( http://en.wikipedia.org/wiki/Pearson_correlation_coefficient ) from an external file that I've just written for an assignment on Monday.
    I can't actually run it because I can't find a machine with Java on that works, though I can compile it. Why is a long story, but University Admin are going to feel my wrath.
    I would like two things.
    1) would someone be kind enough to try to run it and test it in anyway and report any bugs or inadequacies back to me. (you will need to create a text file called data.dat with some numbers in, e.g.
    14.234 54.4534
    376.56 432.2332
    23432. 23234.23
    2) How can I can the computer to ask the user to enter either a) the name of the file from system.in or b) from a popup dialogue box with a browse feature (or is that incompatible with some OSs?).
    The file follows:
    // Import packages
         import java.io.*; // Import all the Java input/output packages
         import java.util.StringTokenizer; // Import a utility package
    class Pearsontwo
    public static void main (String[] args)
         /* Define variables.
              (double any number with decimal point.
              ints take integer value) */
              double     sumx, sumy,               // sum of x and sum of y
                        sumxx, sumyy,          // sum of x squared and y squared
                        sumxy;                    // sum of products of x and y
              int n;                              // n is number of lines
         // Set name of file to be read
              String fileName = data.dat; // define the name of the file
         //     (Enhancement: use user input. This requires the use of System.in which is a bit complicated.
              //System.out.print("Please type the name of the file you wish to run the analysis on:");
              //fileName = TextIO.getInt();
         // Set things for reading external file
    BufferedReader br;     // Will be used to read the file
    String line;          // Will be used to hold a line read from the file
    StringTokenizer st; // Will be used to break a line into separate words
              String firstWord, secondWord;     // File will be read as string type
    double firstNumber, secondNumber;     // that need to be converted into numbers.
    try // if an error occurs, go to the "catch" block below
    // Create a buffered file reader for the file
         br = new BufferedReader (new FileReader(fileName));
    // Continue to read lines whilst there is one or more left to read
                        while (br.ready())
                        {   line= br.readLine();               // Read one line of the file
                             st = new StringTokenizer(line);     // Prepare to split the line into "words"
                             // Get the first two words (invalid --> error --> catch)
                                  firstWord = st.nextToken();
                                  secondWord = st.nextToken();
                             // Turn words into numbers (invalid --> error --> catch)
                                  firstNumber = Double.parseDouble(firstWord);
                                  secondNumber = Double.parseDouble(secondWord);
                             // Add the numbers to the previously stored numbers
                                  sumx = sumx + firstNumber;
                                  sumy = sumy + secondNumber;
                                  sumxx = sumxx + (firstNumber * firstNumber);
                                  sumyy = sumyy + (secondNumber * secondNumber);
                                  n = n++; add one to the value of n.
    // Close the file
    br.close();
    // Handle any error in opening the file
                   catch (Exception e)
                   {   System.err.println("File input error.\nPlease amend the file " + fileName);
              //     Calcuate r in stages, variance and covariance first.
                   double variancex = (sumx2 - (sumx * sumx / n)) / (n - 1);     // calculates the variance of x ...
                   double variancey = (sumx2 - (sumx * sumx / n)) / (n - 1);     // ... and y
                   double covariance = (sumx * sumy - sumx * sumy / n ) / (n - 1);     // and the covariance of x and y
                   double r = covariance / Math.sqrt(variancex * variancey);     // and the Pearson r value
                   // Printout
                   System.out.print("The Pearson product-moment correlation for these data is:" );
                   System.out.println ( r );
                   // Also print to file ?
    Cheers,
    Duncan.
    (Note: this is my own work by Duncan Harris at Cariff University, so I'm not plaigerising anyone other than myself if I post it here and it subsequently gets found by one of the course organisers who have given permission for this sort of thing anyway!)

    "I can't actually run it because I can't find a machine with Java on that works, though I can compile it. Why is a long story, but University Admin are going to feel my wrath."
    I'm sure they're worried.
    I don't understand this. You can compile, but not run? This makes no sense at all.
    Why can't you simply download the JDK from Sun and install it on a machine? You could both compile and run then.
    You don't need a pop-up dialog box to get an input file name from a user. The command prompt is quite sufficient.

  • Can someone test my podcast on their iPod please?

    hello -- i just set up my first podcast but don't have an iPod to test it on. is it possible someone could test it out? i subscribed to my own feed in itunes and it works, but it's not searchable yet via itunes, and i don't have an iPod to test that my clip was encoded properly. anyone willing to drop it into their iPod and test it out??
    here's the rss link:
    http://www.maplepalmmovie.com/podcasts/rss.xml
    thx

    I don't have an iPod either, but one quick way to tell if it is in the correct format is to subscribe to your own podcast, you can manually subscribe to it using the Advanced >Subscribe to podcast option in iTunes. Once you've downloaded the video, select the video, then choose Advanced> Convert selection for iPod.
    If it is in the correct format it will display a message "One or more selections couldn't be converted since they are already in the correct format"
    If not, it will begin the conversion for you.
    In this case, your video is not in the correct format.
    The iTunes spec indicates which formats, sizes, bitrates, etc.. the iPod can play:
    Creating Video Podcasts
    Although iTunes can play a variety of .mp4, .m4v, and .mov video formats, video iPods require more specific formats. By following the steps in the Creating Video for iPod tutorial, QuickTime 7 Pro will automatically create an .m4v file containing H.264 video and AAC audio that is optimized for iPod. iPod can play the following video formats:
    * H.264 video, up to 1.5 Mbps, 640 x 480, 30 frames per sec., Baseline Low-Complexity Profile with AAC-LC audio up to 160 kbps, 48 Khz, stereo audio in .m4v, .mp4, and .mov file formats
    * H.264 video, up to 768 kbps, 320 x 240, 30 frames per sec., Baseline Profile up to Level 1.3 with AAC-LC audio up to 160 kbps, 48 Khz, stereo audio in .m4v, .mp4, and .mov file formats
    * MPEG-4 video, up to 2.5 Mbps, 640 x 480, 30 frames per sec., Simple Profile with AAC-LC audio up to 160 kbps, 48 Khz, stereo audio in .m4v, .mp4, and .mov file formats
    One quick and easy way to get it in the proper format is to use Quicktime Pro to export your original source video. There is a export option "Movie to iPod" this will convert it to a iPod compatible format.
    Erik

  • Can someone test this for me

    OK not sure if it is just my phone or a bug or a WAD. But here is the scenario :
    1. Turn off iPhone 3g
    2. Plug it into the wall adapter that came with the phone, while it is plugged into the wall.
    3. Turn it on by hitting the sleep/wake button.
    4. Phone appears to boot, then after a time vibrates and sits on Apple logo (repeats).
    4a. I let it do this under 2.0 and 2.0.1 same issue
    5. Hold down home and sleep/wake to turn it off from failed boot
    6. Unplug and press sleep/wake and up it comes just fine
    I have tried this a few times and the same thing happens. I don't turn my phone off that often, but if it is a bug, its best someone fix it.
    Also, phone charges just fine in off mode and on mode with this charger (the original that came with the phone).
    I have not yet tried this while with the computer.
    Thanks

    dev_all posted something on 11/25/06 11:06 PM so i blathered
    about to and
    fro:
    > Hi,
    >
    > I've haven't logged on in a while, but I need some help.
    And I know how
    > helpful you all are.
    >
    > I've had several registrants at one of my sites, but one
    of them has reported
    > that they cannot log on to my site on IE and only if he
    checks the "remember
    > me" button on FF.. (I know, weird huh?) Even weirder,
    both IE and FF work for
    > me just fine!
    >
    > I'm begging someone to do a test run for me.
    >
    > Instructions:
    > Go to:
    >
    http://cashlessmarketer.com/member/index.php?option=com_registration&task=regi
    > st
    > er (
    Use fake information and a [email protected] email
    address, if
    > you want.)
    >
    > After registration you should be able to immediately
    login.
    >
    > Try to login - after login, if you are directed to a
    page that says "no items
    > to be displayed" then click the members home button in
    the top menu.
    >
    > If it is working correctly you should go to a page that
    has a some content (a
    > couple ebooks, nothing you care about).. If it doesn't
    work the complaint was
    > that it says "you are not authorized to view this
    resource, you need to
    > login"..
    >
    > The person said the IE6 doesn't work at all and FF 2.0
    only works if you check
    > the "remember me" box. I have only had one complaint, so
    I need to know for
    > sure if this is just a fluke or if this is happening to
    anyone else.
    >
    > I greatly appreciate this guys,
    >
    > Thanks alot
    > Dev_all
    >

  • Can someone help with this simple application

    I am taking my first java class and there are limited resourses for the class as far as getting help with coding.
    Any hoo if any one can point me in the correct direction from the following information listed below I would be greatfull. I am trying to use the set and get methods on the instance veriables and then I am goign to post the results once I get them workign to a JOption pane window.
    examples are most welcome thanks
    // Invoice.java
    // Homework assignment 3.13
    // Student Arthur Clark
    public class Invoice // public class
    String partNumber;// instance veriable quantity
    String partDescription;// instance verialbe partDescription
    //constructors
    public void setpartNumber( String number, String description )
              partNumber = number; //initalize quantity
              partDescription = description; // initalize partDescription
         }// end constructors
    //method getpartNumber
    public String getpartNumber()
              return partNumber;
         }//end method getpartNumber
    public String getpartDescription()
              return partDescription;
         }// end method getpartDescription
    public void displayMessage()
         //this is the statement that calls getpartNumber
         System.out.printf(" part number # \n%s!\n the description", getpartNumber(), getpartDescription() );
    } // method displaMessage
    }// end method main
    // Fig. 3.14 InvoiceTest.java
    // Careate and manipulate an account object
    import java.util.Scanner;
    import javax.swing.JOptionPane;//import JOptionPane
    public class InvoiceTest{
         // main method begins the exciution of the program
         public static void main ( String args [] )
              // create Scanner to obtain input from mommand window
              Scanner input = new Scanner ( System.in );
              // create a Invoice object and assig it to mymethod
              Invoice myMethod = new Invoice();
              Invoice myMethod2 = new Invoice();
              // display inital value of partName, partDescriptoin
              System.out.printf( "inital partname is %s\n\n", myMethod.getpartNumber() );
              // prompt for and read part name, partDescription
              System.out.println( "please enter the Part Number:" );
              String theNumber = input.nextLine(); // read a line of text
              myMethod.setpartNumber( theNumber ); // set the part name with in the parens
              System.out.println();// outputs blank line
              myMethod.displayMessage();
              System.out.println( "please enter the Part Description" );
              String theDescription = input.nextLine(); // read a line of text
              myMethod2.setpartDescription( theDescription );// set the part description
              System.out.println();// outputs blank line
              myMethod2.displayMessage();
         }// end main mehtod
    }// end class

    //constructors
    public void setpartNumber( String number, String description )
              partNumber = number; //initalize quantity
              partDescription = description; // initalize partDescription
         }// end constructorsThe above code is not a constructor. You do not include a return type, void or anything else. Also, the constructor should be called the same as your class.
    public Invoice( String number, String description )
              partNumber = number;
              partDescription = description;
         } Another thing, comments should only be used when it isn't bleedingly obvious what your code is doing.
    P.S. is your middle initial C?

  • Can someone point me to an application built in Flex that is in the Apple App Store

    I keep seeing videos from adobe that shows apps running on IOS  devices. Im getting mixed messages about the whole process.     
    Forgive me if Im just missing something or have not been paying  attention enough to know..  How in the world is this being deployed on a  iPhone if it doesnt run flash?
    Is it true or not that I will  be able to submit my app to the appstore? If it is true please give me  an example of it in the real world.
    Im a flex developer but  have pretty much thrown the whole idea of working on iPhone apps in flex  because of the lack support of flash.
    I dont get it; what  has changed and why doesnt the rest of the world know that they can  run  flash on their iPhone. I feel like this would be big news.

    dataffect wrote:
    I keep seeing videos from adobe that shows apps running on IOS  devices. Im getting mixed messages about the whole process.     
    Forgive me if Im just missing something or have not been paying  attention enough to know..  How in the world is this being deployed on a  iPhone if it doesnt run flash?
    Adobe supply an IOS packager that translates the Flex/Flash project into an IOS project equivalent. There are some restrictions. The igadget family doesn't run flash.
    Is it true or not that I will  be able to submit my app to the appstore? If it is true please give me  an example of it in the real world.
    You can submit an app to the appstore. I'm not going to go hunting for one for you.
    Im a flex developer but  have pretty much thrown the whole idea of working on iPhone apps in flex  because of the lack support of flash.
    I dont get it; what  has changed and why doesnt the rest of the world know that they can  run  flash on their iPhone. I feel like this would be big news.
    The iPhone doesn't run Flash. Adobe have created a packager that translates a Flash or Flex project into an IOS/Objective-C one.
    The mechanism has been discussed and described all over the web.

  • Internet slow - how can I test if Time Machine vs something else?

    Just set up my new Time Machine (excellent!), but my internet connection has been painfully slow (not excellent!).
    I'm wondering if there is an easy way to tell if the Time Capsule is slowing things down, or if it is simply my internet provider. Is there a simple test that will do that? Will an online DSL test work (just try it with and without the Time Capsule)?
    Thank you-

    You could probably do it via ControlPlane.

  • Can someone help me with the application?

    Hello there,
    I have a problem:
    I have made this layout and I can not find the functions.
    I would like to have: if the user selects a region and a different year, then it should be displayed on
    the left diagram beneath.
    If the user selects - in the second row - a region and a year, then it should be displayed in the right diagram.
    <a href="http://www.haus-horngacher.at/1222.jpg">http://www.haus-horngacher.at/1222.jpg</a>
    You can see it here.
    Please help me, thank you!
    Regards
    Markus

    ..as you can see in the picture the to (region, year) in the first
    row should be imaged in diagram1. The two in the second line should
    be imaged in the second diagram.
    Above there is a simple Excel-Table
    looks like this:
                    Jahr 2008                   Jahr 2009            Jahr 2010
    Region1     44                                   44                         43
    Region2      43                                   43                         43

  • Can someone test my movie on a PC?

    If you have QT7 and run IE7, I am interested if my movie will load up and run for you. I posted a movie exported from QTpro as a QT movie and another one as an mp4 movie. They work for two of my friends but don't work for my father. I set the QT movie as Broadband High with h.264 codec with deinterlacing turned on. Much appreciated if you can help.
    Here's the QT movie:
    http://web.mac.com/hooktrunk/iWeb/site/prints.html
    Here's the mp4 movie:
    http://web.mac.com/hooktrunk/iWeb/e/6.html
    iBook G4   Mac OS X (10.4.5)   Printer: Epson PX-G930(same as R800 in US)

    Thanks, after my last post I started re making the movies with the HD setting, but My computer doesn't like the highest quality setting in imovie for some reason, so I can't get the clearest quality I'd like. I think it's a ram issue.
    Anyway my dad solved the viewing problem. I'm going to post the answer here for anyone that experiences the same problem with their PC and QuickTime. The solution is as follows.
    Quicktime Task (qtask.exe) - Apple Computer
    Some sort of tray icon app that seems to do very little aside from brand your dekstop with Apple’s Quicktime logo. Quicktime will install this in your startup settings every time the Quicktime player launches. To disable simply terminate the exe and search your Program Files folders for the file to rename.
    Is featured in the following:
    Quicktime Task (qtask.exe) - Apple Computer. Some sort of tray icon app that seems to do very little aside from brand your dekstop with Apple’s Quicktime ... www.mathies.com/weblog/?m=200606
    This was preventing my father and a friend from viewing my QT movies and any QT HD movie trailers on the apple site. I don't know why it affected some PCs and not others.
    Anyway, I'd say the solution has been solved, now hopefully Apple can fix the problem.

Maybe you are looking for

  • Back from ALV Grid with multiple refresh

    I have a report that from a selection screen shows an editable ALV Grid, and after I save it, it will refresh the grid. My problem is when I hit the BACK button it returns to the "previous grid" instead of the selection screen I am using the followin

  • H.323 slow start problem

    I work with Cisco AS5350XM GW , version 12.3 (12r)PI6b. I tried to make a call scenario with protocol H.323 only from TS trough Cisco gateway back to same TS. The call scenario with h.323 fast start was successful, but when I switched to slow start,

  • IPhoto library move to external HD | organization

    My laptop is running out of space so I'm moving my large iPhoto library to an external hard drive.  I know how to move the content and adjust iPhoto to route to the new location, but can I do this WITHOUT affecting my organization/events?  I have 200

  • Time Data Integration with peopleSoft

    Hi, Employees enter their time in SAP Portal. Once these times are approved, these need to be moved in to PeopleSoft. Presently there are complex interfaces for the process. Management has decided to redesign the interfaces. Can somebody give me an o

  • Adding rows to a datatable, depending on the array size

    I have a situation like this: In my managed bean, i have an array of size 5. In the faces jsp page, I have a datatable, which refers to this array. I need to display five rows in the datatable. How do I do this? <h:column> <f:facet name="header"> <h: