Page 1 of 2 12 LastLast
Results 1 to 20 of 24
  1. #1
    nightfan101 is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default Need help please!

    Hi guys,

    So I wouldn't consider myself a beginner in Java (I took it in 11th grade in HS, but now I'm a rising sophomore), but I do need some help, some guidelines.

    I'm supposed to program some code that pops up a couple of windows. One has a couple of textfields used to input data, and the other one is a graph that is linked to the data that you input into the textfields in the other box. So lets say I put in for X: 2,3,4 and for Y: 1,2,3. It should display a line graph of the coordinates in an XY plane.

    Is this hard? It sounds hard to me. I might need to use applets, but I'm not too familiar with those. Any advice? I've created one box that has some buttons and some text fields, but that's it. I'm also trying to create just text to be put above the textfields, so it says like "Put blah blah here [in the text box]".

    Thank you so much guys!

  2. #2
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Is this meant to be on the web?

  3. #3
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    And have you ever made a basic GUI app?

  4. #4
    nightfan101 is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default

    Hi thanks for replying

    I've made a basic GUI that has some buttons and some textFields. I need to know how to make the text above the box to specify what goes in each text box, and I also need to know how to figure out the orientation of the buttons. I have an example, if you want to see the code (actually, it's pretty similar to an example I found online)

  5. #5
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    no, that is ok, does this need to be on the web? u mentioned applets

  6. #6
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Quote Originally Posted by nightfan101 View Post
    Hi thanks for replying

    I've made a basic GUI that has some buttons and some textFields. I need to know how to make the text above the box to specify what goes in each text box, and I also need to know how to figure out the orientation of the buttons. I have an example, if you want to see the code (actually, it's pretty similar to an example I found online)
    sure post the code anyway, I will see what you are doing currently

  7. #7
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Can I ask you one more quick question first before we begin... how many classes have you ever written that rely on each other?

  8. #8
    nightfan101 is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default

    Once again, thank you sooooo much!

    No, it doesn't need to be online. I guess that rules out applet?

    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;

    public class IRGA{
    private JFrame f = new JFrame("IRGA"); //create Frame
    private JPanel pnlNorth = new JPanel(); // North quadrant
    private JPanel pnlSouth = new JPanel(); // South quadrant
    private JPanel pnlEast = new JPanel(); // East quadrant
    private JPanel pnlWest = new JPanel(); // West quadrant
    private JPanel pnlCenter = new JPanel(); // Center quadrant

    private JButton btnNorth = new JButton("Add gas");
    private JButton btnSouth = new JButton("Stop adding gas");
    private JButton btnEast = new JButton("Save");
    private JButton btnWest = new JButton("Move to graph");
    private JButton btnCenter = new JButton("Begin");

    private JMenuBar mb = new JMenuBar();
    private JMenu mnuFile = new JMenu("File");
    private JMenuItem mnuItemQuit = new JMenuItem("Quit");
    private JMenu mnuHelp = new JMenu("Help");
    private JMenuItem mnuItemAbout = new JMenuItem("About");

    public IRGA(){
    f.setJMenuBar(mb);

    mnuFile.add(mnuItemQuit);
    mnuHelp.add(mnuItemAbout);
    mb.add(mnuFile);
    mb.add(mnuHelp);

    pnlNorth.add(btnNorth);
    pnlSouth.add(btnSouth);
    pnlEast.add(btnEast);
    pnlWest.add(btnWest);
    pnlCenter.add(btnCenter);

    f.getContentPane().setLayout(new BorderLayout());
    f.getContentPane().add(pnlNorth, BorderLayout.NORTH);
    f.getContentPane().add(pnlSouth, BorderLayout.SOUTH);
    f.getContentPane().add(pnlEast, BorderLayout.EAST);
    f.getContentPane().add(pnlWest, BorderLayout.WEST);
    f.getContentPane().add(pnlCenter, BorderLayout.CENTER);

    f.addWindowListener(new ListenCloseWdw());

    mnuItemQuit.addActionListener(new ListenMenuQuit());

    TextField plaintext = new TextField("Put CO2 concentration here:");
    f.add(plaintext);

    }

    public class ListenMenuQuit implements ActionListener{
    public void actionPerformed(ActionEvent e){
    System.exit(0);
    }
    }

    public class ListenCloseWdw extends WindowAdapter{
    public void windowClosing(WindowEvent e){
    System.exit(0);
    }
    }

    public void launchFrame(){
    // Display Frame
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setVisible(true);
    }

    public static void main(String args[]){
    IRGA gui = new IRGA();
    gui.launchFrame();


    }
    }

    Obviously, not the most original code. It works, though. As you can prob tell, I got a lot of help (most of it is from this online source, but I made a few minor tweaks). The big issue right now is how do you add buttons so it doesn't fit the orientation it has right now? That is, how can I made like a column of text boxes?

    As for the classes, right now I have just the IRGA class.

    Thanks again, I owe you one

  9. #9
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    Please read: Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    It will explain the more user-friendly layout managers for these are what you need to use in order to have your components placed correctly on your GUI.

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

    Default

    how do you add buttons so it doesn't fit the orientation it has right now
    Not sure what this says. doesn't fit? Please explain a bit more.
    made like a column of text boxes
    See the Gridlayout layout manager. It will allow you to put objects in a column

  11. #11
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Quote Originally Posted by nightfan101 View Post
    Once again, thank you sooooo much!

    No, it doesn't need to be online. I guess that rules out applet?

    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;

    public class IRGA{
    private JFrame f = new JFrame("IRGA"); //create Frame
    private JPanel pnlNorth = new JPanel(); // North quadrant
    private JPanel pnlSouth = new JPanel(); // South quadrant
    private JPanel pnlEast = new JPanel(); // East quadrant
    private JPanel pnlWest = new JPanel(); // West quadrant
    private JPanel pnlCenter = new JPanel(); // Center quadrant

    private JButton btnNorth = new JButton("Add gas");
    private JButton btnSouth = new JButton("Stop adding gas");
    private JButton btnEast = new JButton("Save");
    private JButton btnWest = new JButton("Move to graph");
    private JButton btnCenter = new JButton("Begin");

    private JMenuBar mb = new JMenuBar();
    private JMenu mnuFile = new JMenu("File");
    private JMenuItem mnuItemQuit = new JMenuItem("Quit");
    private JMenu mnuHelp = new JMenu("Help");
    private JMenuItem mnuItemAbout = new JMenuItem("About");

    public IRGA(){
    f.setJMenuBar(mb);

    mnuFile.add(mnuItemQuit);
    mnuHelp.add(mnuItemAbout);
    mb.add(mnuFile);
    mb.add(mnuHelp);

    pnlNorth.add(btnNorth);
    pnlSouth.add(btnSouth);
    pnlEast.add(btnEast);
    pnlWest.add(btnWest);
    pnlCenter.add(btnCenter);

    f.getContentPane().setLayout(new BorderLayout());
    f.getContentPane().add(pnlNorth, BorderLayout.NORTH);
    f.getContentPane().add(pnlSouth, BorderLayout.SOUTH);
    f.getContentPane().add(pnlEast, BorderLayout.EAST);
    f.getContentPane().add(pnlWest, BorderLayout.WEST);
    f.getContentPane().add(pnlCenter, BorderLayout.CENTER);

    f.addWindowListener(new ListenCloseWdw());

    mnuItemQuit.addActionListener(new ListenMenuQuit());

    TextField plaintext = new TextField("Put CO2 concentration here:");
    f.add(plaintext);

    }

    public class ListenMenuQuit implements ActionListener{
    public void actionPerformed(ActionEvent e){
    System.exit(0);
    }
    }

    public class ListenCloseWdw extends WindowAdapter{
    public void windowClosing(WindowEvent e){
    System.exit(0);
    }
    }

    public void launchFrame(){
    // Display Frame
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setVisible(true);
    }

    public static void main(String args[]){
    IRGA gui = new IRGA();
    gui.launchFrame();


    }
    }

    Obviously, not the most original code. It works, though. As you can prob tell, I got a lot of help (most of it is from this online source, but I made a few minor tweaks). The big issue right now is how do you add buttons so it doesn't fit the orientation it has right now? That is, how can I made like a column of text boxes?

    As for the classes, right now I have just the IRGA class.

    Thanks again, I owe you one
    Okay I think I know what you are after, but it is hard to visualise for sure could you post a crude drawing of what you what

    e.g (and obvioulsy wrong)

    [Add Gas] [put Co2 here..]
    [save] etc

    or is the original code ok and you want extra gui elements after this, can you please expand on your already good description

  12. #12
    nightfan101 is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default

    WINDOW 1

    INPUT [CO2] (ppm)
    _______________________________
    | 4 | 5 | 8 | 5 | 3 | 4 | 3 | 2|
    ------------------------------------
    Above (this is just to make sure the graph works), you would put in random numbers (that I've already filled in)

    WINDOW 2
    would simply display a graph of these ppm values vs. time, so like a basic line graph would be fine.

    Thank you! I know the buttons seem unnecessary right now, but I was just experimenting.

    Eventually, I want to connect an IRGA board that will replace the first window, and will simply collect data that the second window will graph. I also should be able to save the graph.

    Again, thank you guys so much!
    Last edited by nightfan101; 06-11-2010 at 04:44 PM.

  13. #13
    nightfan101 is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default

    Please guys, any help is appreciated! :) I am kinda stumped:confused:

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

    Default

    What do you have now? What does it do or not do?

  15. #15
    nightfan101 is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default

    Right now I just have that code, which is a couple of buttons and a textfield. I would like to make 2 windows, connect them, and create a line graph that is directly correlated with the numbers I input into the first window. I understand I have to use Swing (though I'm still a little unfamiliar with it) and my friend recommended Buoy as well. Ideas please?

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

    Default

    Do you have any specific questions or problems?
    Asking: Ideas please? is pretty general.

  17. #17
    nightfan101 is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default

    I need to know how to create a line graph that corresponds directly to points you input into one window.

    If I put in 5,8,9,1 into each box in Window 1, I would get a line graph with these points (on the Y axis, each X axis point would be evenly spaced). So it would have points (1,5), (2,8), (3,9), (4,1) with lines connecting them. Also, if you change the numbers, the graph would change. This is what I'm trying to achieve now.

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

    Default

    how to create a line graph that corresponds directly to points
    I'm having trouble going from the above to
    If I put in 5,8,9,1
    Points have two parts: the x value and the y value.

    Given a list of points (x,y) do you want to draw a line from the first point to the second to the third etc until the end of the list?
    If so you could use a JPanel, override its paintComponent() method and use the Graphics class drawLine() method to draw the lines connecting the points.

  19. #19
    nightfan101 is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default

    As in, if I put in y values into Window-1, it'll automatically evenly space out onto Window-2 because it'll be a time graph (ie the intervals would be in seconds, for example. 1 second apart.). It should connect the dots immediately.

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

    Default

    So the x values are related to the time the y value was received?
    From that x and y you create and add a new Point, add it to the end of the list and do as I suggested before.

Page 1 of 2 12 LastLast

Posting Permissions

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