java - Drawing functions, JFrame wrong results -


I have a problem, I tried to create a code to visualize the function.

  Package main; Import java.awt. *; Import java.awt.Graphics; Import javax.swing.JPanel; Public category MyPanel JPanel Extended {Private Fixed Last Long Serial VERSIONUID = 6649271997955423098L; @ Override Public Empty Paint Comonant (Graphics G) {// Superparent Components (G); Only show the code how it works //g.setColor(Color.cyan); //g.fillRect (10, 20, 35, 78); PaintStuff (g); PaintBackgroundComponents (g); // Navigation crossfunction in background color (g); // Both paintline functions (g); // The correct pictureline function with test; (g); } / ** * Your method for drawing lines. Need graphics! * @ Param G * / Private Zero Paint Stuff (Graphics G) {G. Coloring (color black); G.drawString ("Integral Venuschualichung", (Main Lamp) - (Main.line / 3), (Men Wide) - (Men Wide / 12)); } Private Zero Paintback Ground Components (Graphics G) {g.drawline ((Main Length) / 2, Main Wide, (Main Lamp) / 2, 0); G.drawline (0, (Main Wide) / 2, Main.line, (Main Wide) / 2); G.setColor (Color.red); G.drawString ("X", (Main Length - (Mainline / 8)), ((Men with / 2) - (Main Wide / 80)); G.drawString ("Y", ((Main Length / 2) + (Main.line / 80)), ((Main Wide) - (Main Wide / 8)); } Private zero color function (graphics g) {g.setColor (Color.blue); (Int x = (0 - main.length); x & lt; main.length; x ++) // fills all possible values ​​(limited through length) {g.draw oval (x) + (Main.length / 2-1), functions. SolveTestFunction (x) + (Main.width / 2-1), 3, 3); }} // left and right side private zeros require different methods Paintline function (Graphics G) {int [] pointOneX = New Int [Main. Height * 2]; Int [] pointOneY = new int [Main.length * 2]; For (int x = 0; x & lt; main.length; x ++) {pointOneX [x] = (((x) * (- 1)) + (mainline / 2-1)); Point at [x] = (function. SolveTestFunction (x) + (Main.width / 2-1)); System.out.print (pointOneX [x] + ""); System.out.print (pointOneY [x]); } G.drawPolyline (pointOneX, pointOneY, 100); } Private zero-less paintline work (graphics g) {int [] pointOneX = new int [Main.length * 2]; Int [] pointOneY = new int [Main.length * 2]; For (int x = 0; x & lt; main.length; x ++) {pointOneX [x] = ((x) + (mainline / 2 + 2)); // Why do some clues? Point at [x] = (function. SolveTestFunction (x) + (Main.width / 2)); System.out.print (pointOneX [x] + ""); System.out.print (pointOneY [x]); } G.drawPolyline (pointOneX, pointOneY, 100); }}  

I have another class:

  package main; Public class work {int x = 0; Public static int solutionestfunction (int x) // simple test function {int y = 0; Y = (x ^ 2) * (- 1); // - 1 Reason for changing the use of GUI y; }}  

And my main method is:

  package main; Import javax.swing.JFrame; Public class main {static int length = 1000; // Fixed int width = 1000 in playgrounds; Public Stable Zero Main (string [] Args) {JFrame Frame = New JFrame ("My Picture"); MyPanel Panel = New MyPanel (); Frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); Frame.setSize (length, width); // playground frame.add (panel); Frame.setVisible (true); }}  

I divided the left and right method rightpaintLineFUnctions (I) because they were the only way to work them when I used my testFunction Trying X * X for left everything good. But since I write it in this form x ^ 2, it did not do the right thing. Some help would be great


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -