Results 1 to 2 of 2
  1. #1
    MapleLeafRag is offline Member
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

    Default Graphs and if else statement

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.applet.*;
    import java.text.*; // For formatting numbers
    import javax.swing.*;
    import javax.swing.JOptionPane;
    import javax.swing.JApplet;
    import java.awt.Graphics;

    public class Finals extends JApplet{

    double input;

    public void init(){

    String firstNumber;
    String secondNumber;
    String thirdNumber;
    String fourthNumber;
    String fifthNumber;
    String sixthNumber;
    String seventhNumber;


    double number1;
    double number2;
    double number3;
    double number4;
    double number5;
    double number6;
    double number7;


    firstNumber = JOptionPane.showInputDialog("What is the value of the price floor");
    secondNumber = JOptionPane.showInputDialog("What is the equilbrium price?");
    thirdNumber = JOptionPane.showInputDialog("What is the equilbrium quantity?");
    fourthNumber = JOptionPane.showInputDialog("We now need another point along the demand curve, what is the price of this point?");
    fifthNumber = JOptionPane.showInputDialog("What is the corresponding quantity?");
    sixthNumber = JOptionPane.showInputDialog("We now need another point on the supply schedule, what is the price of the this point?");
    seventhNumber = JOptionPane.showInputDialog("What is the corresponding quantity?");


    number1 = Double.parseDouble(firstNumber);
    number2 = Double.parseDouble(secondNumber);
    number3 = Double.parseDouble(thirdNumber);
    number4 = Double.parseDouble(fourthNumber);
    number5 = Double.parseDouble(fifthNumber);
    number6 = Double.parseDouble(sixthNumber);
    number7 = Double.parseDouble(seventhNumber);


    input = number1;
    }

    if(number1==0)
    public void paint(Graphics g){

    super.paint(g);

    g.drawRect(15, 10, 270, 20);

    g.drawString("The price floor is " + input, 25, 25);

    String xlabel = "Quantity";
    String ylabel = "Price";
    String xlabel1 = "Q*";
    String ylabel1 = "P";
    String ldemand = "D*";
    Font font;
    int xbeg = 50;
    int ybeg = 50;
    int xend = 350;
    int yend = 350;
    int xmiddle = ((xend-xbeg)/2)+xbeg;
    int ymiddle = ((yend-xbeg)/2)+ybeg;

    BasicStroke stroke = new BasicStroke(2.0f);
    BasicStroke wide = new BasicStroke(4.0f);

    float dash1[] = {6.0f};

    BasicStroke dashed = new BasicStroke(2.0f,
    BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
    2.0f, dash1, 3.0f);

    {
    font = new Font("Helvetica", Font.BOLD, 14);
    }


    {
    Graphics2D g2 = (Graphics2D) g;
    g2.setColor(Color.black);

    g2.setStroke(wide);
    g2.draw(new Line2D.Double(xbeg, yend , xend, yend));
    g2.draw(new Line2D.Double(xbeg, ybeg , xbeg, yend));

    //Demand
    g2.setStroke(stroke);
    g2.setColor(Color.green);
    g2.draw(new Line2D.Double(xbeg + 20, ybeg + 20, xend - 20, yend - 20));

    //Supply
    g2.setStroke(stroke);
    g2.setColor(Color.red);
    g2.draw(new Line2D.Double (xbeg + 20, yend - 20, xend - 20, ybeg +20 ));

    g2.setStroke(dashed);
    g2.setColor(Color.red);
    g2.draw(new Line2D.Double(xbeg, ymiddle, xmiddle, ymiddle));
    g2.draw(new Line2D.Double(xmiddle, yend, xmiddle, ymiddle));

    g2.setColor(Color.black);
    g2.setFont(font);
    g2.drawString(xlabel, xend-50, yend+15);
    g2.drawString(ylabel, xbeg-40, ybeg+15);
    g2.drawString(xlabel1, xmiddle-5, yend+15);
    g2.drawString(ylabel1, xbeg-20, ymiddle+2);
    g2.drawString(ldemand, xend-25, yend-30);


    }
    }

    else{
    public void paint1(Graphics g){
    g.drawRect(15, 10, 270, 20);

    }
    }


    Does anybody know whats wrong with my if/else statement? I'm just tinkering around. Basically, if the user enters 0 in the first box, I would like a graph to appear, otherwise, I just want a rectangle. Any helps is greatly appreciated!

  2. #2
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    Post code tags around code please. It's nearly impossible to check for matching brackets and such when there's no indentation.
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

Similar Threads

  1. Creating 3D graphs
    By idanfast in forum Advanced Java
    Replies: 1
    Last Post: 09-06-2009, 04:42 PM
  2. [SOLVED] Graphs?
    By deepthought015 in forum Eclipse
    Replies: 3
    Last Post: 05-09-2009, 12:33 PM
  3. Graphs
    By siddharth_s_b in forum NetBeans
    Replies: 1
    Last Post: 05-22-2008, 04:12 AM
  4. Graphs
    By javaplus in forum Advanced Java
    Replies: 1
    Last Post: 12-07-2007, 09:17 PM
  5. Graphs with Ireport
    By Marcus in forum Advanced Java
    Replies: 1
    Last Post: 07-05-2007, 06:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •