Results 1 to 6 of 6
  1. #1
    TallOne is offline Member
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Default How do I make lines and graphs in java?

    I already made a frame window, but now I need to know how to make a graph within that window. The next step is creating the x and y axis. In short, the output needs to look like a graph paper. Here is what I have so far...

    import java.awt.*;
    import java.util.*;
    import javax.swing.JFrame;
    import javax.swing.JButton;
    import java.awt.GridLayout;

    package grid;

    public class HomeworkStar {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    JFrame frame = new JFrame ();
    frame.setSize(400, 500);
    frame.setTitle("Star");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);

    frame.setVisible(true);
    }

    }

    Maybe I imported more than I needed to, but whatever. And I have an error on package; it says syantax error on token "package"; import expected

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: How do I make lines and graphs in java?

    The best solution that I know of is to download a graphics library such as JFreeChart. If you must create your own, you'll want to draw in a JPanel or JComponent's paintComponent method using its Graphics/Graphics2D object that is passed in as a parameter. You will find decent tutorials on this at the Oracle Java tutorial site, and many examples of this on this and other forums.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,578
    Rep Power
    25

    Default Re: How do I make lines and graphs in java?

    Your source syntax error is that the package statement should go before the import statements

  4. #4
    TallOne is offline Member
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Default Re: How do I make lines and graphs in java?

    THANKS NORM. you fixed one of my problems...

    And futarable, I would take your advice into consideration, but i didnt understand what JPanel or JComponent was. I was actually wondering if anybody on this site could modify it for me

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: How do I make lines and graphs in java?

    Quote Originally Posted by TallOne View Post
    And futarable, I would take your advice into consideration, but i didnt understand what JPanel or JComponent was. I was actually wondering if anybody on this site could modify it for me
    We don't do other people's homework for them or support folks who do. I suggest that you read the tutorials to learn what those components are and how to use them. Please come back if you have specific questions about them.

  6. #6
    TallOne is offline Member
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

Similar Threads

  1. Replies: 11
    Last Post: 01-14-2012, 06:46 PM
  2. Replies: 3
    Last Post: 10-25-2011, 06:29 PM
  3. eliminating new lines in java
    By javajames in forum New To Java
    Replies: 5
    Last Post: 05-13-2011, 10:55 PM
  4. graphs in java
    By divyan in forum Advanced Java
    Replies: 3
    Last Post: 03-04-2011, 01:35 PM
  5. JAVA graphs & charts libraries
    By acornel in forum AWT / Swing
    Replies: 1
    Last Post: 10-24-2010, 07:11 PM

Tags for this Thread

Posting Permissions

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