Results 1 to 11 of 11
- 11-07-2008, 12:13 PM #1
Member
- Join Date
- Aug 2008
- Posts
- 20
- Rep Power
- 0
passing variables to another frame
Hello Java Forums,
I am making 'calculator' of a sort, and there is need for editing data.
For that purpose I want to create a new small window, which sets itself visible when I click my edit button.
2nd; I need smaller window to be focused, while the main window should be NOT focusable. Only when small window is 'disposed off' the main window gets focused back.
First; how do I pass variables (String and doubles) to small form, and than retrieve new/or-not-new variables back to main form?
Sorry for miscount, kind regards, Grom
- 11-07-2008, 12:32 PM #2
I am sorry ,but nobody here is going to do all the work for you,everybody here are the people who only come to help and not work for somebody.Please provide the code where you are stuck in.Thanks
- 11-07-2008, 02:46 PM #3
That can be done by calling a method that returns a value.do I pass variables (String and doubles) to small form, and than retrieve new/or-not-new variables back to main form?
- 11-07-2008, 03:22 PM #4
Member
- Join Date
- Aug 2008
- Posts
- 20
- Rep Power
- 0
Hello Serjant,
off topics:
Ukraina, ha? Hello brother Slovan! I am from Slovenia
on topics:
Uh, huh, I never meant for others to write a code for me, I 'expected' example, yes, and than I have to do my coding. Anyway, here is what i have:
So I have main frame and EditFrame. I open EditFrame from main frame with click on the button action:
On EditFrame I pre-created two variables, String and double:Java Code:EditFrame ef = new EditFrame(); EditFrame.setVisible(true);
so I can set those two variables from main frame. I send over to EditFrame string and double, from click on the action button on the main frame:Java Code://1 private String _name; public void SetEditingName(String name) { _name= name; } public String GetEditingName() { return _name; } //2 private double _number; public void SetEditingWieght(double number) { _number= number; } public double GetEditingWeight() { return _number; }
On Edit Frame I have a button with action, that sets new value of variables:Java Code:EditFrame ef = new EditFrame(); ef.SetEditingName("myName"); ef.SetEditingWieght(100); EditFrame.setVisible(true);
Java Code:private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: SetEditingName("Java"); SetEditingWieght(101); }
Now, how do I call/get in main frame edited variables, which should be Java, 101, instead of MyName, 100?
If I am not understandable, I can elaborate more.
Kind regards, Grom
- 11-07-2008, 04:06 PM #5
To call/get variables in another class (not all classes are Frames), you need to have a reference to that class object.
One way to pass a reference is via a Constructor.
Another is via a set.... method.
Could you write a small program and post it here with println()s to show what is happening and what you would like to happen. Copy the output from the program and add your comments on where you'd like the results to be different.Last edited by Norm; 11-07-2008 at 04:08 PM.
- 11-08-2008, 01:16 AM #6
Hi,brother from Slovenia.
Everybody here is brother,i live in Ukraine,8 years i lived in Israel and served 3 years in Israeli army,but it doesn't matter.Everybody is brother here.
So,Grom,in EditFrame you have
So paramter you should be also initialized in double so it should be 100.0Java Code://2 private double _number; public void SetEditingWieght(double number) { _number= number; }
Will be much obliged to you if you post all the output error and provide all your code,please,wanna see how you declared your variables.Java Code:EditFrame ef = new EditFrame(); ef.SetEditingName("myName"); ef.SetEditingWieght(100.0); EditFrame.setVisible(true);
- 11-08-2008, 10:09 AM #7
Member
- Join Date
- Aug 2008
- Posts
- 20
- Rep Power
- 0
Hello brothers! Do we have sisters as well?
ok, I am new to Java and this forum, but it seems, statistically, that my every post is not substantial. So, here goes another shoot at my goal:
(Am I allowed to post links yet? No? O, ok)
At this link (MyWebPage) ht tp: //www .beezgetz .com/Tour.aspx
are five videos of myProgram made in C#.
On third video (Truss Calculator) at 1 minute and 28 seconds, Edit Button is being clicked. Selected load (string, doubles) are send to smaller window. The load is changed, and sent back to main frame/window.
On fourth video (Grid calculator) at 1 minute 33 seconds is same thing.
It is this very program that I am trying to 'translate' to Java
So,
Am I now making sense?2nd; I need smaller window to be focused, while the main window should be NOT focusable. Only when small window is 'disposed off' the main window gets focused back.
First; how do I pass variables (String and doubles) to small form, and than retrieve new/or-not-new variables back to main form?
I am not getting any errors. Here is code from main frame Edit Button:
I don't know which part of code you want me to post. I could post link to project, so you can download the whole deal. (440 KB zipped).Java Code:ClassGrid Gr = new ClassGrid(); List<GridLoad> loadList = new ArrayList<GridLoad>(); private DefaultListModel ListIzpis; private void EditLoadButActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: if (jList1.getSelectedIndex() == -1) { statusMessageLabel.setText("Select Load if -1"); } else { try { int i = jList1.getSelectedIndex(); String name = loadList.get(i).GetLoadName(); double weight = loadList.get(i).GetWeight(); // EditGridLoadFrame EGLF = new EditGridLoadFrame(); EGLF.SetEditingName(name); EGLF.SetEditingWieght(weight); EGLF.setVisible(true);//************** // String s = EGLF.GetEditingName(); // double d = EGLF.GetEditingWeight(); //************ // loadList.get(i).SetLoadName(EGLF.GetEditingName()); // loadList.get(i).SetWeight(EGLF.GetEditingWeight()); // loadList.set(i, ); // EGLF.dispose(); ListIzpisBremen(); //populate jList1 with loads } catch (Exception e) { statusMessageLabel.setText("Select Load catch"); } } } private void ListIzpisBremen() { jList1.removeAll(); ListIzpis = new DefaultListModel(); int i = loadList.size(); for (int r = 0; r < i; r++) { String st = loadList.get(r).GetLoadName(); double h = loadList.get(r).GetWeight(); double x = loadList.get(r).GetLoadDistX(); double y = loadList.get(r).GetLoadDistY(); ListIzpis.addElement(st + ", kg: " + String.valueOf(h) + ", X: " + String.valueOf(x) + " Y: " + String.valueOf(y)); } jList1.setModel(ListIzpis); jList1.validate(); }
Thanks for bearing with me. Regards, Grom
- 11-08-2008, 11:24 AM #8
I didn't notice sisters here,lol
Ok,now it is more clear,add to the EditFrame method which will return the needed data for you,as i understood you want to make some calculations also with data which is passed from the main frame,so for example you have MainFrame class and there you have initialized variable called int i=10,and you want to use it in EditFrame so your method should have MainFrame paramter:
Java Code:class EditFrame extends JFrame{ ............................. ............................. public int makeCalc(MainFrame f){ int result =f.i; return result; }Last edited by serjant; 11-08-2008 at 11:26 AM.
- 11-09-2008, 03:37 PM #9
Member
- Join Date
- Aug 2008
- Posts
- 20
- Rep Power
- 0
Hello guys,
Well, we were way off, here is what I needed:
ht tp://ja va.sun.com/docs/books/tut orial/uiswing/components/dialog.html
Thanks for your time! Grom
- 11-09-2008, 03:42 PM #10
Ah,so,then you shouldn't create another class for calling JOptionPane
- 11-09-2008, 05:55 PM #11
Member
- Join Date
- Aug 2008
- Posts
- 20
- Rep Power
- 0
Ola, yes, you are right, I don't need class. It turns out to be quite simple:
Thanks again for bearing with me.Java Code:String s = JOptionPane.showInputDialog(mainPanel, "Replace " + name) ; if ((s != null) && (s.length() > 0)) { loadList.get(i).SetWeight(Double.valueOf(s)); // I change variable return; }
Regards, Grom
Similar Threads
-
Getting internal frame out
By rad in forum New To JavaReplies: 8Last Post: 08-11-2008, 02:33 AM -
Frame to other Frame
By Aswq in forum New To JavaReplies: 2Last Post: 07-19-2008, 04:27 PM -
close a frame..
By tajinvillage in forum New To JavaReplies: 5Last Post: 04-27-2008, 10:22 PM -
is synchronization on method passing local variables as parameters needed
By reddzer in forum Java ServletReplies: 0Last Post: 11-10-2007, 04:47 PM -
Frame Query
By Daniel in forum AWT / SwingReplies: 1Last Post: 07-05-2007, 06:27 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks