Ok so basically im struggling to perform some actions with Java Swing JButtons. I have a feeling that my problem is an ease for skilled programmers so bare with my "elementary" problems:
What i'd like to do is modify content of other JComponent and possibly modify some variables on button click. It seems relatively easy but i would like to perform it on "already declared" variables (or already created JComponents)
Wherever i search i always get examples of cases where everything is declared from scratch inside implementation of ActionPerformed function related to specific JButton, just like here:
http://zetcode.com/tutorials/javaswingtutorial/swingevents/ //above you can observe that in "actionPerformed" function they define new variables such as: string/date/locale/stringbuffer
Such solution does not satisfy my needs by any means. I want to modify/show variable that was previously defined due to user click with use of function that belongs to different class.
Ok maybe it will be more clear if i'll show you what i'd like to do on a exemplary sourcecode:
class Number_String {
public String change_add_MOD (String sss){
String str_modified = sss + "_modified";
return str_modified;
}
public int change_plus1 (int z){
int z_modified = z + 1;
return z_modified;
}
public static void main(String[] args) {
// TODO code application logic here
}
}
public class probTESTswing extends javax.swing.JFrame {
public probTESTswing() {
initComponents();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
jLabel1.setText("done");
jLabel2.setText(mystring2);
jLabel3.setText(ns.change_add_MOD(mystring3));
}
public static void main(String args[]) {
Number_String ns=null;
String first_str="myFIRSTstring";
String mystring2 = ns.change_add_MOD(first_str);
String mystring3 = "third_str";
probTESTswing testing= new probTESTswing();
testing.setVisible(true);
}
}
Greetings to everyone who made effort to get here;)
So lemme briefly explain:
Main class is the "swing gui" where in main() function i initialize some variables using second class, now i want to show result of "processing" those variables with my Number_String class, however Java refuses to cooperate as my programming skills lack some fundamental knowledge as you probably noticed.
You can observe that i want to do "it" in both ways: where inside jButton1ActionPerformed i want to access function from my Number_String class (with use of 'mystring3'), and also the other way where i'd like to access just previously defined variable(mystring2)
ANY HELP GREATLY APPRECIATED.
shall i "overload" jButton1ActionPerformed function (in order to take variables as a parameter)? (yes i know its private -> I created it with Netbeans Swing designer) --shall i design my GUI by hand and then overload them? (dunno whether such overload is possible thou)
or maybe i should define some "buffer" (field for integer and field for string) for variables that i want modify with use of my Jbutton and then put them inside "probTESTswing" class? (+ write appropriate functions to handle the other class in such way that i use its functions?)
or maybe (since my Number_String does not possess any variables - just functions) move those functions to GUI class (probTESTswing)
OR maybe i should use some pointers/references? (yea it seems that this is what i need here, unfortunetely pointers/references are something i know nothing about :(, however i'd like to learn it a lot, as it seems mandatory as i discovered now - hard to find tutorials thou, since as far as i know there is no pointers, and i have no clue how to use references in such way so that desired functionality would be achieved - as you can see from my problem)
OR maybe there is totally different way to deal with exactly such problems/cases?
please enlight me, i'd like to solve my problem "efficiently" in a good programming manner, in order to learn on efficient, optimal, proper and fast solutions, however im desperate for help so any advice is greatly appreciated.
Greetings