6 Replies - 423 Views - Last Post: 05 December 2012 - 09:02 PM Rate Topic: -----

#1 samaha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 27-November 12

java GUI line graph graphs line the wrong way

Posted 05 December 2012 - 08:12 PM

I have a program that asks the user for 2 points and creates a graph based on the equation of the line from the 2 points. however my line graphs weird, the x's graph in the right spot but the y points graph negative for some reason. can someone help me get my graph to work the right way? Also, i want my labels (-10,-5,0,5,10) to change based on the scale of points so if someone enters 100,100 as a point, i already scale the line when drawn but i want to update the numbers on the click calculate, right now the axis updates if i hit calculate then clear the graph.

		import java.awt.BasicStroke;
		import java.awt.Color;
		import java.awt.Graphics2D;
		import java.awt.Stroke;
		import java.awt.event.ActionEvent;
		import java.awt.event.ActionListener;
		import java.awt.image.BufferedImage;
		
		import javax.swing.ImageIcon;
		import javax.swing.JFrame;
		import javax.swing.JOptionPane;
		
		
		public class Main 
		extends JFrame
		{
				
			static LineCalculator lineCalculator = new LineCalculator();
			int xMax;
			int xMin;
			int xMid;
			int yMid;
			int yMin;
			int yMax;
			int x1Pixel;
			int x2Pixel;
			int y1Pixel;
			int y2Pixel;
			int xUnit=1;
			int yUnit=1;
			Graphics2D graphics;
			BufferedImage image;
			Stroke stroke5 = new BasicStroke(5);
			Stroke stroke2 = new BasicStroke(2);
			Stroke stroke4 = new BasicStroke(4);
			
			public String CLEAR = "clear";
			public String CALCULATE = "calculate";
			
			
			public static void main(String[] args)
			{
				
				Main main = new Main();
				main.show(lineCalculator);
			}
			
			public void show(LineCalculator lineCalculator) {
				
				ActionListner listener = new ActionListner(lineCalculator);
				
				lineCalculator.getCalculateBtn().setActionCommand(CALCULATE);
				lineCalculator.getCalculateBtn().addActionListener(listener);
				
				lineCalculator.getClearBtn().setActionCommand(CLEAR);
				lineCalculator.getClearBtn().addActionListener(listener);
				
				xMax = 400;
				xMin = 0;
				xMid = 200;
				yMax = 400;
				yMin = 0;
				yMid = 200;
				x1Pixel = 0;
				y1Pixel = 0;
				x2Pixel = 0;
				y2Pixel = 0;
				
				initializeFormGraphic();
				lineCalculator.getXunitTxt().setEditable(false);
				lineCalculator.getYunitTxt().setEditable(false);
				lineCalculator.getXInterceptTxt().setEditable(false);
				lineCalculator.getYInterceptTxt().setEditable(false);
				lineCalculator.getDistanceTxt().setEditable(false);
				lineCalculator.getScopeTxt().setEditable(false);
				lineCalculator.getAngleRTxt().setEditable(false);
				lineCalculator.getAngleTxt().setEditable(false);
				lineCalculator.getEqnTxt().setEditable(false);
				
				add(lineCalculator);
				setTitle("Line Graph Generator");
				pack();
				setVisible(true);
				
			}
			
			
			class ActionListner implements ActionListener {
				
				LineCalculator linecalculator;
				
				public ActionListner(LineCalculator linecalculator)
				{
					
					this.linecalculator = linecalculator;
				}
				
		
				@Override
				public void actionPerformed(ActionEvent e)
				{
					
					
					if (e.getActionCommand().equalsIgnoreCase(CALCULATE)) {
						
						double x1;
						double x2;
						double y1;
						double y2;
						double length_of_x;
						double length_of_y;
						double slope;
						double opposite;
						double angle_degrees;
						double angle_radians;
						double y_intercept;
						double distance_between_2_points;
						
						if ("".equalsIgnoreCase(linecalculator.getX1Txt().getText())
								|| "".equalsIgnoreCase(linecalculator.getX2Txt().getText())
								|| "".equalsIgnoreCase(linecalculator.getY1Txt().getText())
								|| "".equalsIgnoreCase(linecalculator.getY2Txt().getText())) {
							JOptionPane.showMessageDialog(null, "The Values X1, X2, Y1, Y2 can not be blank.");
							
						}
						
						
						x1 = (double) (Double.parseDouble(linecalculator.getX1Txt().getText()));
						x2 = (double) (Double.parseDouble(linecalculator.getX2Txt().getText()));
						y1 = (double) (Double.parseDouble(linecalculator.getY1Txt().getText()));
						y2 = (double) (Double.parseDouble(linecalculator.getY2Txt().getText()));
						length_of_x = x2 - x1;
						length_of_y = y2 - y1;
					
						slope = length_of_y / length_of_x;
						slope = (double) Round(slope, 2);
						
						opposite = y2 - y1;
						distance_between_2_points = Math.sqrt((length_of_x * length_of_x)
								+ (length_of_y * length_of_y));
						distance_between_2_points = (double) Round(distance_between_2_points, 2);
						y_intercept = y1 - (slope * x1);
						y_intercept = (double) Round(y_intercept, 2);
						angle_degrees = Math.atan(length_of_y / length_of_x) * (180 / Math.PI);
						angle_degrees = (double) Round(angle_degrees, 2);
						angle_radians = angle_degrees * (Math.PI / 180);
						angle_radians = (double) Round(angle_radians, 2);
						linecalculator.getScopeTxt().setText(slope + "");
						linecalculator.getDistanceTxt().setText(distance_between_2_points + "");
						linecalculator.getAngleRTxt().setText(angle_radians + "");
						linecalculator.getAngleTxt().setText(angle_degrees + "");
						linecalculator.getEqnTxt().setText("Y = " + slope + "" + "X + " + y_intercept + "");
						
						scaleDraw(linecalculator.getX1Txt().getText(), linecalculator.getY1Txt().getText(), linecalculator.getX2Txt().getText(), linecalculator.getY2Txt().getText());
						linecalculator.getDrawspace().repaint();
		
					} else if (e.getActionCommand().equalsIgnoreCase(CLEAR)) {
						
						lineCalculator.getX1Txt().setText("");
						lineCalculator.getX2Txt().setText("");
						
						lineCalculator.getY1Txt().setText("");
						lineCalculator.getY2Txt().setText("");
						
						lineCalculator.getScopeTxt().setText("");
						lineCalculator.getDistanceTxt().setText("");
						lineCalculator.getXunitTxt().setText("");
						lineCalculator.getYunitTxt().setText("");
						
						lineCalculator.getAngleRTxt().setText("");
						lineCalculator.getAngleTxt().setText("");
						lineCalculator.getEqnTxt().setText("");
						
						lineCalculator.getXInterceptTxt().setText("");
						lineCalculator.getYInterceptTxt().setText("");
						
						
						initializeFormGraphic();
					}
								
				}
		
			}
			
			public double Round(double val, int plc)
			{
				double pwr = Math.pow(10, plc);
				val = val * pwr;
				double tmp = (int) val;
				if(((int) (val + .5)) == (int) val)
					return (tmp / pwr);
				else
					return ((tmp + 1.0) / pwr);
			}
			
			
			private static void repaintImage(BufferedImage image)
			{
				lineCalculator.getDrawspace().setIcon(new ImageIcon(image));
				lineCalculator.getDrawspace().repaint();
			}
		
			private void initializeFormGraphic()
			{
				image = new BufferedImage(400, 400, BufferedImage.TYPE_INT_RGB);
				lineCalculator.getDrawspace().setIcon(new ImageIcon(image));
				fillImage(image, 255, 255, 255);
				graphics = (java.awt.Graphics2D) image.getGraphics();
				graphics.setColor(new java.awt.Color(0, 0, 0));
				// yaxis
				graphics.drawLine(xMid, yMin, xMid, yMax);
				// xaxis
				graphics.drawLine(xMin, yMid, xMax, yMid);
				// draw tix
				// y axis
				for (int y = 0; y <= 400; y += 20)
				{
					if((y % (5 * 20)) == 0)
					{
						graphics.setStroke(stroke4);
						graphics.drawLine(xMid - 10, y, xMid + 10, y);
					}
					else
					{
						graphics.setStroke(stroke2);
						graphics.drawLine(xMid - 5, y, xMid + 5, y);
					}
				}
				// x axis
				for (int x = 0; x <= 400; x += 20)
				{
					if((x % (5 * 20)) == 0)
					{
						graphics.setStroke(stroke4);
						graphics.drawLine(x, yMid - 10, x, yMid + 10);
					}
					else
					{
						graphics.setStroke(stroke2);
						graphics.drawLine(x, yMid - 5, x, yMid + 5);
					}
				}
				graphics.setStroke(stroke2);
				repaintImage(image);
				drawLabels();
			}
		
			private static void fillImage(BufferedImage image, int red, int green,
					int blue)
			{
				int packedRGB = packRgb(255, 255, 255);// white
				for (int y = 0; y < image.getHeight(null); y++)
				{
					for (int x = 0; x < image.getWidth(null); x++)
						image.setRGB(x, y, packedRGB);
				}
			}
		
			public static int packRgb(int r, int g, int B)/>
			{
				return (r * 256 + g) * 256 + b;
			}
		
			private void scaleDraw(String xlStr, String y1Str, String x2Str,
					String y2Str)
			{
				// parse to integer values
				int px1 = Integer.parseInt(xlStr);
				int py1 = Integer.parseInt(y1Str);
				int px2 = Integer.parseInt(x2Str);
				int py2 = Integer.parseInt(y2Str);
				// get # of digits for each integer value
				int digx1 = xlStr.length() - 1;
				int digy1 = y1Str.length() - 1;
				int digx2 = x2Str.length() - 1;
				int digy2 = y2Str.length() - 1;
				if(px1 < 0)
				{
					digx1--;
				}
				if(py1 < 0)
				{
					digy1--;
				}
				if(px2 < 0)
				{
					digx2--;
				}
				if(py2 < 0)
				{
					digy2--;
				}
				// get x axis unit
				if(digx1 >= digx2)
				{
					xUnit = (int) Math.pow(10, digx1);
				}
				else
				{
					xUnit = (int) Math.pow(10, digx2);
				}
				// y axis
				if(digy1 >= digy2)
				{
					yUnit = (int) Math.pow(10, digy1);
				}
				else
				{
					yUnit = (int) Math.pow(10, digy2);
				}
				
				lineCalculator.getXunitTxt().setText(xUnit + "");
				lineCalculator.getYunitTxt().setText(yUnit + "");
		
				// Get X,Y Scale Values
				double x1Scale;
				double y1Scale;
				double x2Scale;
				double y2Scale;
		
				if(xUnit >= 10)
				{
					x1Scale = (px1 / (double) (xUnit * 10));
					x2Scale = (px2 / (double) (xUnit * 10));
				}
				else
				{
					x1Scale = px1 * .1;
					x2Scale = px2 * .1;
				}
		
				if(yUnit >= 10)
				{
					y1Scale = (py1 / (double) (yUnit * 10));
					y2Scale = (py2 / (double) (yUnit * 10));
				}
				else
				{
					y1Scale = py1 * .1;
					y2Scale = py2 * .1;
				}
				x1Pixel = 0;
				y1Pixel = 0;
				x2Pixel = 0;
				y2Pixel = 0;
				int xInc;
				int yInc;
				// xaxis pixel points
				x1Pixel = xMid + (int) (x1Scale * 200);
				x2Pixel = xMid + (int) (x2Scale * 200);
				// yaxis pixel points
				y1Pixel = yMid + (int) (y1Scale * 200);
				y2Pixel = yMid + (int) (y2Scale * 200);

				y1Pixel = -1 * y1Pixel;
				y2Pixel = -1 * y2Pixel;
				// xInc = Math.abs(GraphHelpers.getAxisDist(x1Pixel, x2Pixel));
				// yInc = Math.abs(GraphHelpers.getAxisDist(y1Pixel, y2Pixel));
				// reduce();
				graphics.setColor(new Color(255, 0, 0));
				y1Pixel = -1 * y1Pixel;
				y2Pixel = -1 * y2Pixel;
				graphics.drawLine(x1Pixel, y1Pixel, x2Pixel, y2Pixel);
				graphics.setStroke(new BasicStroke(5));
				graphics.setColor(new Color(0, 0, 255));
				graphics.drawLine(x1Pixel, y1Pixel, x1Pixel, y1Pixel);
				graphics.drawLine(x2Pixel, y2Pixel, x2Pixel, y2Pixel);
				graphics.setStroke(new BasicStroke(2));
			}
		
			private void drawLabels()
			{
				int temp;
				for (int y = 0; y <= 400; y += 20)
				{
					if((y % (5 * 20)) == 0)
					{
						if(y > yMid || y < yMid)
						{
							if(y < yMid / 2)
							{
								temp = 10*yUnit;
								graphics.drawString(temp + "", xMid - 30, y + 10);
								repaintImage(image);
		
							}
							else if(y == yMid / 2)
							{
								temp = 5*yUnit;
								graphics.drawString(temp + "", xMid - 30, y + 5);
								repaintImage(image);
							}
							else if(y == yMid + yMid / 2)
							{
								temp = -5*yUnit;
								graphics.drawString(temp + "", xMid - 30, y + 5);
								repaintImage(image);
							}
							else if(y == yMax)
							{
								temp = -10*yUnit;
								graphics.drawString(temp + "", xMid - 30, y);
								repaintImage(image);
							}
						}
					}
				}
		
				for (int x = 0; x <= 400; x += 20)
				{
					if((x % (5 * 20)) == 0)
					{
						if(x > yMid || x < yMid)
						{
							if(x < xMid / 2)
							{
								temp = -10*xUnit;
								graphics.drawString(temp + "", x, yMid + 20);
								repaintImage(image);
		
							}
							else if(x == xMid / 2)
							{
								temp = -5*xUnit;
								graphics.drawString(temp + "", x - 5, yMid + 20);
								repaintImage(image);
							}
							else if(x == xMid + xMid / 2)
							{
								temp = 5*xUnit;
								graphics.drawString(temp + "", x - 5, yMid + 20);
								repaintImage(image);
							}
							else if(x == xMax)
							{
								temp = 10*xUnit;
								graphics.drawString(temp + "", x - 15, yMid + 20);
								repaintImage(image);
							}
						}
					}
				}
				repaintImage(image);
			}
			
		}



here is the other class


		public class LineCalculator extends javax.swing.JPanel {
		
		    /** Creates new form Line_Calculator */
		    public LineCalculator() {
		        initComponents();
		    }

		    @SuppressWarnings("unchecked")
		    private void initComponents() {
		
		        xunitLbl1 = new javax.swing.JLabel();
		        xunitTxt1 = new javax.swing.JTextField();
		        yunitLbl1 = new javax.swing.JLabel();
		        yunitTxt1 = new javax.swing.JTextField();
		        jPanel1 = new javax.swing.JPanel();
		        xunitLbl = new javax.swing.JLabel();
		        xunitTxt = new javax.swing.JTextField();
		        yunitLbl = new javax.swing.JLabel();
		        yunitTxt = new javax.swing.JTextField();
		        drawspace = new javax.swing.JLabel();
		        x1Lbl = new javax.swing.JLabel();
		        x1Txt = new javax.swing.JTextField();
		        y1Lbl = new javax.swing.JLabel();
		        y1Txt = new javax.swing.JTextField();
		        x2Lbl = new javax.swing.JLabel();
		        x2Txt = new javax.swing.JTextField();
		        y2Lbl = new javax.swing.JLabel();
		        y2Txt = new javax.swing.JTextField();
		        jLabel1 = new javax.swing.JLabel();
		        scopeTxt = new javax.swing.JTextField();
		        jLabel2 = new javax.swing.JLabel();
		        distanceTxt = new javax.swing.JTextField();
		        jLabel3 = new javax.swing.JLabel();
		        angleTxt = new javax.swing.JTextField();
		        jLabel4 = new javax.swing.JLabel();
		        angleRTxt = new javax.swing.JTextField();
		        jLabel5 = new javax.swing.JLabel();
		        eqnTxt = new javax.swing.JTextField();
		        calculateBtn = new javax.swing.JButton();
		        x1Lbl1 = new javax.swing.JLabel();
		        xInterceptTxt = new javax.swing.JTextField();
		        y1Lbl1 = new javax.swing.JLabel();
		        yInterceptTxt = new javax.swing.JTextField();
		        clearBtn = new javax.swing.JButton();
		
		        xunitLbl1.setText("X-Unit");
		
		        yunitLbl1.setText("Y-Unit");
		
		        xunitLbl.setText("X-Unit");
		
		        yunitLbl.setText("Y-Unit");
		
		        drawspace.setBackground(new java.awt.Color(255, 255, 255));
		        drawspace.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
		
		        x1Lbl.setText("X1");
		
		        y1Lbl.setText("Y1");
		
		        x2Lbl.setText("x2");
		
		        y2Lbl.setText("Y2");
		
		        jLabel1.setText("Slope");
		
		        jLabel2.setText("Distance");
		
		        jLabel3.setText("Angle(D)");
		
		        jLabel4.setText("Angle(Rad)");
		
		        angleRTxt.addActionListener(new java.awt.event.ActionListener() {
		            public void actionPerformed(java.awt.event.ActionEvent evt) {
		                angleRTxtActionPerformed(evt);
		            }
		        });
		
		        jLabel5.setText("Equation");
		
		        calculateBtn.setText("Calculate");
		
		        x1Lbl1.setText("X-Intercept");
		
		        y1Lbl1.setText("Y-Intercept");
		
		        clearBtn.setText("Clear All");
		
		        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
		        jPanel1.setLayout(jPanel1Layout);
		        jPanel1Layout.setHorizontalGroup(
		            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
		            .addGroup(jPanel1Layout.createSequentialGroup()
		                .addContainerGap()
		                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
		                    .addGroup(jPanel1Layout.createSequentialGroup()
		                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
		                            .addGroup(jPanel1Layout.createSequentialGroup()
		                                .addComponent(xunitLbl)
		                                .addGap(18, 18, 18)
		                                .addComponent(xunitTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
		                                .addGap(18, 18, 18)
		                                .addComponent(yunitLbl)
		                                .addGap(18, 18, 18)
		                                .addComponent(yunitTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE))
		                            .addComponent(drawspace, javax.swing.GroupLayout.DEFAULT_SIZE, 284, Short.MAX_VALUE))
		                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
		                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
		                            .addGroup(jPanel1Layout.createSequentialGroup()
		                                .addComponent(x1Lbl)
		                                .addGap(18, 18, 18)
		                                .addComponent(x1Txt, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
		                                .addGap(18, 18, 18)
		                                .addComponent(y1Lbl)
		                                .addGap(18, 18, 18)
		                                .addComponent(y1Txt, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE))
		                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
		                                .addGroup(jPanel1Layout.createSequentialGroup()
		                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
		                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
		                                            .addComponent(x2Lbl)
		                                            .addGap(18, 18, 18)
		                                            .addComponent(x2Txt, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
		                                            .addGap(18, 18, 18)
		                                            .addComponent(y2Lbl))
		                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
		                                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
		                                                .addComponent(jLabel1)
		                                                .addComponent(jLabel2)
		                                                .addComponent(jLabel3)
		                                                .addComponent(jLabel4)
		                                                .addComponent(jLabel5))
		                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
		                                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
		                                                .addComponent(angleRTxt, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE)
		                                                .addComponent(angleTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
		                                                .addComponent(distanceTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
		                                                .addComponent(scopeTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
		                                                .addComponent(eqnTxt, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE))))
		                                    .addGap(18, 18, 18)
		                                    .addComponent(y2Txt, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE))
		                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
		                                    .addComponent(clearBtn, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
		                                    .addComponent(calculateBtn, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
		                        .addGap(9, 9, 9))
		                    .addGroup(jPanel1Layout.createSequentialGroup()
		                        .addComponent(x1Lbl1)
		                        .addGap(18, 18, 18)
		                        .addComponent(xInterceptTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
		                        .addGap(18, 18, 18)
		                        .addComponent(y1Lbl1)
		                        .addGap(18, 18, 18)
		                        .addComponent(yInterceptTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)))
		                .addContainerGap())
		        );
		        jPanel1Layout.setVerticalGroup(
		            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
		            .addGroup(jPanel1Layout.createSequentialGroup()
		                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
		                    .addGroup(jPanel1Layout.createSequentialGroup()
		                        .addContainerGap()
		                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
		                            .addComponent(xunitLbl)
		                            .addComponent(xunitTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
		                            .addComponent(yunitLbl)
		                            .addComponent(yunitTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
		                        .addGap(18, 18, 18)
		                        .addComponent(drawspace, javax.swing.GroupLayout.PREFERRED_SIZE, 543, javax.swing.GroupLayout.PREFERRED_SIZE))
		                    .addGroup(jPanel1Layout.createSequentialGroup()
		                        .addGap(80, 80, 80)
		                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
		                            .addComponent(x1Lbl)
		                            .addComponent(x1Txt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
		                            .addComponent(y1Lbl)
		                            .addComponent(y1Txt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
		                        .addGap(18, 18, 18)
		                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
		                            .addComponent(x2Lbl)
		                            .addComponent(x2Txt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
		                            .addComponent(y2Lbl)
		                            .addComponent(y2Txt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
		                        .addGap(18, 18, 18)
		                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
		                            .addComponent(jLabel1)
		                            .addComponent(scopeTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
		                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
		                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
		                            .addComponent(jLabel2)
		                            .addComponent(distanceTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
		                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
		                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
		                            .addComponent(jLabel3)
		                            .addComponent(angleTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
		                        .addGap(18, 18, 18)
		                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
		                            .addComponent(jLabel4)
		                            .addComponent(angleRTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
		                        .addGap(18, 18, 18)
		                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
		                            .addComponent(jLabel5)
		                            .addComponent(eqnTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
		                        .addGap(25, 25, 25)
		                        .addComponent(calculateBtn)
		                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
		                        .addComponent(clearBtn)))
		                .addGap(18, 18, 18)
		                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
		                    .addComponent(x1Lbl1)
		                    .addComponent(xInterceptTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
		                    .addComponent(y1Lbl1)
		                    .addComponent(yInterceptTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
		                .addContainerGap(43, Short.MAX_VALUE))
		        );
		
		        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		        this.setLayout(layout);
		        layout.setHorizontalGroup(
		            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
		            .addGroup(layout.createSequentialGroup()
		                .addContainerGap()
		                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
		                .addContainerGap(49, Short.MAX_VALUE))
		        );
		        layout.setVerticalGroup(
		            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
		            .addGroup(layout.createSequentialGroup()
		                .addContainerGap()
		                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
		                .addContainerGap())
		        );
		    }// </editor-fold>//GEN-END:initComponents
		
		    public javax.swing.JButton getClearBtn()
			{
				return clearBtn;
			}
		
			public void setClearBtn(javax.swing.JButton clearBtn)
			{
				this.clearBtn = clearBtn;
			}
		
			public javax.swing.JTextField getXInterceptTxt()
			{
				return xInterceptTxt;
			}
		
			public void setXInterceptTxt(javax.swing.JTextField interceptTxt)
			{
				xInterceptTxt = interceptTxt;
			}
		
			public javax.swing.JTextField getYInterceptTxt()
			{
				return yInterceptTxt;
			}
		
			public void setYInterceptTxt(javax.swing.JTextField interceptTxt)
			{
				yInterceptTxt = interceptTxt;
			}
		
			public javax.swing.JTextField getAngleRTxt()
			{
				return angleRTxt;
			}
		
			public void setAngleRTxt(javax.swing.JTextField angleRTxt)
			{
				this.angleRTxt = angleRTxt;
			}
		
			public javax.swing.JTextField getAngleTxt()
			{
				return angleTxt;
			}
		
			public void setAngleTxt(javax.swing.JTextField angleTxt)
			{
				this.angleTxt = angleTxt;
			}
		
			public javax.swing.JButton getCalculateBtn()
			{
				return calculateBtn;
			}
		
			public void setCalculateBtn(javax.swing.JButton calculateBtn)
			{
				this.calculateBtn = calculateBtn;
			}
		
			public javax.swing.JTextField getDistanceTxt()
			{
				return distanceTxt;
			}
		
			public void setDistanceTxt(javax.swing.JTextField distanceTxt)
			{
				this.distanceTxt = distanceTxt;
			}
		
			public javax.swing.JLabel getDrawspace()
			{
				return drawspace;
			}
		
			public void setDrawspace(javax.swing.JLabel drawspace)
			{
				this.drawspace = drawspace;
			}
		
			public javax.swing.JTextField getEqnTxt()
			{
				return eqnTxt;
			}
		
			public void setEqnTxt(javax.swing.JTextField eqnTxt)
			{
				this.eqnTxt = eqnTxt;
			}
		
			public javax.swing.JLabel getJLabel1()
			{
				return jLabel1;
			}
		
			public void setJLabel1(javax.swing.JLabel label1)
			{
				jLabel1 = label1;
			}
		
			public javax.swing.JLabel getJLabel2()
			{
				return jLabel2;
			}
		
			public void setJLabel2(javax.swing.JLabel label2)
			{
				jLabel2 = label2;
			}
		
			public javax.swing.JLabel getJLabel3()
			{
				return jLabel3;
			}
		
			public void setJLabel3(javax.swing.JLabel label3)
			{
				jLabel3 = label3;
			}
		
			public javax.swing.JLabel getJLabel4()
			{
				return jLabel4;
			}
		
			public void setJLabel4(javax.swing.JLabel label4)
			{
				jLabel4 = label4;
			}
		
			public javax.swing.JLabel getJLabel5()
			{
				return jLabel5;
			}
		
			public void setJLabel5(javax.swing.JLabel label5)
			{
				jLabel5 = label5;
			}
		
			public javax.swing.JPanel getJPanel1()
			{
				return jPanel1;
			}
		
			public void setJPanel1(javax.swing.JPanel panel1)
			{
				jPanel1 = panel1;
			}
		
			public javax.swing.JTextField getScopeTxt()
			{
				return scopeTxt;
			}
		
			public void setScopeTxt(javax.swing.JTextField scopeTxt)
			{
				this.scopeTxt = scopeTxt;
			}
		
			public javax.swing.JLabel getX1Lbl()
			{
				return x1Lbl;
			}
		
			public void setX1Lbl(javax.swing.JLabel lbl)
			{
				x1Lbl = lbl;
			}
		
			public javax.swing.JTextField getX1Txt()
			{
				return x1Txt;
			}
		
			public void setX1Txt(javax.swing.JTextField txt)
			{
				x1Txt = txt;
			}
		
			public javax.swing.JLabel getX2Lbl()
			{
				return x2Lbl;
			}
		
			public void setX2Lbl(javax.swing.JLabel lbl)
			{
				x2Lbl = lbl;
			}
		
			public javax.swing.JTextField getX2Txt()
			{
				return x2Txt;
			}
		
			public void setX2Txt(javax.swing.JTextField txt)
			{
				x2Txt = txt;
			}
		
			public javax.swing.JLabel getXunitLbl()
			{
				return xunitLbl;
			}
		
			public void setXunitLbl(javax.swing.JLabel xunitLbl)
			{
				this.xunitLbl = xunitLbl;
			}
		
			public javax.swing.JLabel getXunitLbl1()
			{
				return xunitLbl1;
			}
		
			public void setXunitLbl1(javax.swing.JLabel xunitLbl1)
			{
				this.xunitLbl1 = xunitLbl1;
			}
		
			public javax.swing.JTextField getXunitTxt()
			{
				return xunitTxt;
			}
		
			public void setXunitTxt(javax.swing.JTextField xunitTxt)
			{
				this.xunitTxt = xunitTxt;
			}
		
			public javax.swing.JTextField getXunitTxt1()
			{
				return xunitTxt1;
			}
		
			public void setXunitTxt1(javax.swing.JTextField xunitTxt1)
			{
				this.xunitTxt1 = xunitTxt1;
			}
		
			public javax.swing.JLabel getY1Lbl()
			{
				return y1Lbl;
			}
		
			public void setY1Lbl(javax.swing.JLabel lbl)
			{
				y1Lbl = lbl;
			}
		
			public javax.swing.JTextField getY1Txt()
			{
				return y1Txt;
			}
		
			public void setY1Txt(javax.swing.JTextField txt)
			{
				y1Txt = txt;
			}
		
			public javax.swing.JLabel getY2Lbl()
			{
				return y2Lbl;
			}
		
			public void setY2Lbl(javax.swing.JLabel lbl)
			{
				y2Lbl = lbl;
			}
		
			public javax.swing.JTextField getY2Txt()
			{
				return y2Txt;
			}
		
			public void setY2Txt(javax.swing.JTextField txt)
			{
				y2Txt = txt;
			}
		
			public javax.swing.JLabel getYunitLbl()
			{
				return yunitLbl;
			}
		
			public void setYunitLbl(javax.swing.JLabel yunitLbl)
			{
				this.yunitLbl = yunitLbl;
			}
		
			public javax.swing.JLabel getYunitLbl1()
			{
				return yunitLbl1;
			}
		
			public void setYunitLbl1(javax.swing.JLabel yunitLbl1)
			{
				this.yunitLbl1 = yunitLbl1;
			}
		
			public javax.swing.JTextField getYunitTxt()
			{
				return yunitTxt;
			}
		
			public void setYunitTxt(javax.swing.JTextField yunitTxt)
			{
				this.yunitTxt = yunitTxt;
			}
		
			public javax.swing.JTextField getYunitTxt1()
			{
				return yunitTxt1;
			}
		
			public void setYunitTxt1(javax.swing.JTextField yunitTxt1)
			{
				this.yunitTxt1 = yunitTxt1;
			}
		
			private void angleRTxtActionPerformed(java.awt.event.ActionEvent evt) {
		    }
		
		
		    private javax.swing.JTextField angleRTxt;
		    private javax.swing.JTextField angleTxt;
		    private javax.swing.JButton calculateBtn;
		    private javax.swing.JButton clearBtn;
		    private javax.swing.JTextField distanceTxt;
		    private javax.swing.JLabel drawspace;
		    private javax.swing.JTextField eqnTxt;
		    private javax.swing.JLabel jLabel1;
		    private javax.swing.JLabel jLabel2;
		    private javax.swing.JLabel jLabel3;
		    private javax.swing.JLabel jLabel4;
		    private javax.swing.JLabel jLabel5;
		    private javax.swing.JPanel jPanel1;
		    private javax.swing.JTextField scopeTxt;
		    private javax.swing.JLabel x1Lbl;
		    private javax.swing.JLabel x1Lbl1;
		    private javax.swing.JTextField x1Txt;
		    private javax.swing.JLabel x2Lbl;
		    private javax.swing.JTextField x2Txt;
		    private javax.swing.JTextField xInterceptTxt;
		    private javax.swing.JLabel xunitLbl;
		    private javax.swing.JLabel xunitLbl1;
		    private javax.swing.JTextField xunitTxt;
		    private javax.swing.JTextField xunitTxt1;
		    private javax.swing.JLabel y1Lbl;
		    private javax.swing.JLabel y1Lbl1;
		    private javax.swing.JTextField y1Txt;
		    private javax.swing.JLabel y2Lbl;
		    private javax.swing.JTextField y2Txt;
		    private javax.swing.JTextField yInterceptTxt;
		    private javax.swing.JLabel yunitLbl;
		    private javax.swing.JLabel yunitLbl1;
		    private javax.swing.JTextField yunitTxt;
		    private javax.swing.JTextField yunitTxt1;		
		}



Is This A Good Question/Topic? 0
  • +

Replies To: java GUI line graph graphs line the wrong way

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: java GUI line graph graphs line the wrong way

Posted 05 December 2012 - 08:38 PM

Nobody here, will try to debug code written by a GUI generator
Your problem, most probably, comes from the instructions YOU gave to the GUI generator.

Write your own GUI and we will be happry to help.
Was This Post Helpful? 0
  • +
  • -

#3 samaha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 27-November 12

Re: java GUI line graph graphs line the wrong way

Posted 05 December 2012 - 08:41 PM

ok well when I debug my program, after the yPixel and y2Pixels get initialized they automatically become negative without me initializing it. and I dont know why. is it because the origin of the graph is up at the top of the screen somehow? so when the line shows up on the graph, its mirrored across the x axis. sorry if that doesnt make sense.
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: java GUI line graph graphs line the wrong way

Posted 05 December 2012 - 08:52 PM

View Postsamaha, on 05 December 2012 - 11:41 PM, said:

ok well when I debug my program, after the yPixel and y2Pixels get initialized they automatically become negative without me initializing it.

What do you rhink that does ?
       y1Pixel = -1 * y1Pixel;  
       y2Pixel = -1 * y2Pixel;  


Was This Post Helpful? 0
  • +
  • -

#5 samaha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 27-November 12

Re: java GUI line graph graphs line the wrong way

Posted 05 December 2012 - 08:55 PM

i should have commented that out but I tried putting that line of code to fix the negative number being generated. it still doesnt work. ignoring that interaction the y values are still negative for some reason.
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: java GUI line graph graphs line the wrong way

Posted 05 December 2012 - 08:58 PM

May be somebody will help you, but I won't waste more time trying to fix horrible generated GUI code.
Was This Post Helpful? 0
  • +
  • -

#7 samaha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 27-November 12

Re: java GUI line graph graphs line the wrong way

Posted 05 December 2012 - 09:02 PM

...thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1