Results 1 to 20 of 24
Thread: Need help please!
- 06-11-2010, 12:08 AM #1
Member
- Join Date
- Jun 2010
- Posts
- 9
- Rep Power
- 0
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!
- 06-11-2010, 01:31 AM #2
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
Is this meant to be on the web?
- 06-11-2010, 01:32 AM #3
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
And have you ever made a basic GUI app?
- 06-11-2010, 01:37 AM #4
Member
- Join Date
- Jun 2010
- Posts
- 9
- Rep Power
- 0
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)
- 06-11-2010, 01:45 AM #5
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
no, that is ok, does this need to be on the web? u mentioned applets
- 06-11-2010, 01:46 AM #6
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
- 06-11-2010, 01:48 AM #7
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
Can I ask you one more quick question first before we begin... how many classes have you ever written that rely on each other?
- 06-11-2010, 01:59 AM #8
Member
- Join Date
- Jun 2010
- Posts
- 9
- Rep Power
- 0
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
- 06-11-2010, 02:15 AM #9
Senior Member
- Join Date
- May 2010
- Posts
- 436
- Rep Power
- 4
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.
- 06-11-2010, 02:16 AM #10
Not sure what this says. doesn't fit? Please explain a bit more.how do you add buttons so it doesn't fit the orientation it has right now
See the Gridlayout layout manager. It will allow you to put objects in a columnmade like a column of text boxes
- 06-11-2010, 02:21 AM #11
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
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
- 06-11-2010, 03:41 PM #12
Member
- Join Date
- Jun 2010
- Posts
- 9
- Rep Power
- 0
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 03:44 PM.
- 06-14-2010, 02:21 AM #13
Member
- Join Date
- Jun 2010
- Posts
- 9
- Rep Power
- 0
Please guys, any help is appreciated! :) I am kinda stumped:confused:
- 06-14-2010, 02:26 AM #14
What do you have now? What does it do or not do?
- 06-14-2010, 04:16 PM #15
Member
- Join Date
- Jun 2010
- Posts
- 9
- Rep Power
- 0
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?
- 06-14-2010, 04:25 PM #16
Do you have any specific questions or problems?
Asking: Ideas please? is pretty general.
- 06-14-2010, 04:42 PM #17
Member
- Join Date
- Jun 2010
- Posts
- 9
- Rep Power
- 0
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.
- 06-14-2010, 04:47 PM #18
I'm having trouble going from the above tohow to create a line graph that corresponds directly to points
Points have two parts: the x value and the y value.If I put in 5,8,9,1
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.
- 06-14-2010, 04:53 PM #19
Member
- Join Date
- Jun 2010
- Posts
- 9
- Rep Power
- 0
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.
- 06-14-2010, 05:46 PM #20


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks