Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6069443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:49:23+00:00 2026-05-23T09:49:23+00:00

Ok so basically im struggling to perform some actions with Java Swing JButtons. I

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:49:24+00:00Added an answer on May 23, 2026 at 9:49 am

    One approach is to separate the data model from the view using the Model–View–Controller pattern, discussed here.

    Addendum: More simply, you may just need to give class ProbTestSwing a suitable member variable:

    private Number_String ns = new Number_String();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I'm struggling with some regex I've got a string like this: a:b||c:{d:e||f:g}||h:i basically
Basically I have some code to check a specific directory to see if an
I'm struggling with some validation using jQuery's validator plugin. Basically I'm checking if username
Struggling with command line again, I have figure out that I can store the
I'm struggling with correct procedure for executing SQL query. Basically, I have text field
I have been struggling with this all day (and yesterday as well). Basically, I
That's probably part one of my question. Basically I'm struggling with the actual injection
Quite new to Linq, and I'm struggling with this one. Basically I have a
I've be struggling for a while trying to make it work. Basically I have
So basically i am struggling with the need of optimizing my code for some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.