java - Returning object name with object values -


I really do not know how to say the word to this question. But I'm going to try my best here to stay with me, if you can :) :)

I have a database with three tables (I'm dealing with it now). Fortunately they all have the same amount of columns. Trying to input values ​​into them using a "popup" form I (to make sure how to do this, but IM is using it as a guideline, and hopefully this work )

Even for that method I have written for that method so far.

  Public form (int option, string val 1, string val 2, string val 3, string val 4, string val 5) {val1 = null; Val2 = null; Val3 = null; Val4 = null; Val5 = null; JTextField val1Field = new JTextField (20); JTextField val2Field = new JTextField (20); JTextField val3Field = new JTextField (20); JTextField val4Field = new JTextField (20); JTextField val5Field = new JTextField (20); String name; String lbl1 = null; String lbl2 = null; String lbl3 = faucet; String lbl4 = null; String lbl5 = null; Switch (Option) {Case 1: // Customer Name = "Customer Information"; Lbl1 = "Customer Number:"; Lbl2 = "Customer name:"; Lbl3 = "Company Name:"; Lbl4 = "Contact Number:"; Lbl5 = "Discount Rate:"; Case 2: // if the item name = "item information"; Lbl1 = "item number:"; Lbl2 = "Item Name:"; Lbl3 = "Cost Price:"; Lbl4 = "Selling price:"; Lbl5 = "stock:"; Case 3: // if user name = "staff notice"; Lbl1 = "Staff ID:"; Lbl2 = "Full name:"; Lbl3 = "Username:"; Lbl4 = "Password:"; Lbl5 = "adminusercheck:"; Default: Joppenpen. Show Messagedig (Alpha POS, "Something went wrong! Try again!", "Error", Joppenpen. ARROOM_MMSEG); } JPNL formpanel = new zpn (); FormPanel.add (New JLabel (lbl1)); FormPanel.add (val1Field); FormPanel.add (Box.createHorizontalStrut (15)); // a spacer formpanel.ed (new jlab2 (llb2)); FormPanel.add (val2Field); FormPanel.add (Box.createHorizontalStrut (15)); // a spacer formpanel.ed (new jlabal (lll3)); FormPanel.add (val3Field); FormPanel.add (Box.createHorizontalStrut (15)); // A Spacer FormPanel.ed (New JLabel (LBL4)); FormPanel.add (val4Field); FormPanel.add (Box.createHorizontalStrut (15)); // a spacer formpanel.ed (new jlabal (lbl5)); FormPanel.add (val5Field); FormPanel.add (Box.createHorizontalStrut (15)); // A spacer int result = springpan. Show configured Diallog (empty, formpennel, name, joptionpain.Occankel_OPTN); If (result == joppenpane.OK_OPTN) {val1 = val1Field.getText (); Val2 = val2Field.getText (); Val3 = val3Field.getText (); Val4 = val4Field.getText (); Val5 = val5Field.getText (); } Return (Option, Val 1, Val 2, Val 3, Val 4, Well 5); }  

Now .. I took some time to understand that I can not return such values, and instead I can change the object instead to change. I have a class for each of these "tables" (item, customer, and employee). But .. this is in the above method, so I have to use a switch so that I can make the label according to the type of table.

So my question is, is the object and its name in the law? Or is this all wrong?

Any help is greatly appreciated.

It looks like you do not actually need to return options Because you do not change it anyway, it seems that you were trying to keep the caller pass variable in method and fill the method in the values ​​of those variables. But in Java the "output" or "reference" parameter is not like C ++ and PHP, so it does not work. (You can pass in the context of mutual objects and set a field in that method, but you can not do this with the string because it is irreversible.)

< P> If this is the case, since 5 things you want to return, they are all the same type, you just have your own one string [] :

  Public can string [] form (int option) {string [] value = new string C [] (5); // value [0] = null; // is not necessary because the array element will already be zero // value [1] = null; ... ... if (result == joppenpane.OK_OPTN) {values ​​[0] = val1Field.getText (); Value [1] = val2Field.getText (); Value [2] = val3Field.getText (); Value [3] = val4Field.getText (); Value [4] = val5Field.getText (); } Return value; }  

P.S. I recommend using arrays or ArrayList instead of different variables such as val1field , val2field , etc., so that you need to repeat the code Do not be it.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -