Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • JFrame tutorial?


    Cardozz

    Recommended Posts

    Hi folks,

     

    I don't seem to understand the way JFrame works. I got a GUI set up, and I've watched some tuts on how to handle simple things, but I don't seem to get them to work.

     

    In the preview (ECLIPSE) option of the WindowBuilder GUI design, the GUI shows up nicely and it works like the way I want it to, but then comes the coding to it which seems odd.

     

    A simple thing like:

    if(buttonA.isSelected(){

        buttonB.setEnabled(false);

    }

     

    does not simply work like that, well, in the preview it doesn't work.

     

     

    Is there any simple tutorial I can watch for this, because I don't seem to understand the way this works. (and yes I've watched tuts already for this)

     

     

    Thanks in advance!

    Link to comment
    Share on other sites

    In the constructor:

     

    buttonA.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    				if(buttonA.isSelected(){
                                        buttonB.setEnabled(false);
                                    }
    		});
    
    PS: Use [*code][/*code] tags for readability (No *) :)
    Link to comment
    Share on other sites

    That doesn't work. If I want to test it in the preview mode, it's not working..

    My post was something to follow, not c/p. I don't know what kind of button you're using nor what buttonA/B even are. If you have no idea what I said means, go learn what action listeners are. That's what you're looking for.

     

     

    Where did you put it in the code?

    Link to comment
    Share on other sites

    My post was something to follow, not c/p. I don't know what kind of button you're using nor what buttonA/B even are. If you have no idea what I said means, go learn what action listeners are. That's what you're looking for.

     

     

    Where did you put it in the code?

     

    I did not copy paste that code, im not that dumb lol..

     

    I tried to use the actionlistener at the bottom of the constructor, E.G:

    chckbxUseGE.addActionListener(new ActionListener() {
    	public void actionPerformed(ActionEvent e) {
                if(chckbxUseGE.isSelected()){
                    radioButton.setEnabled(true);
    			} else radioButton.setEnabled(false);
    		});
    

    When i put that at the bottom of the constructor it tells me i need to change the variables to final in order to have them to work, and when i go back to the Design > preview it seems like this code doesnt disable the radiobutton (like it does nothing..)

    Link to comment
    Share on other sites

    I did not copy paste that code, im not that dumb lol..

     

    I tried to use the actionlistener at the bottom of the constructor, E.G:

    chckbxUseGE.addActionListener(new ActionListener() {
    	public void actionPerformed(ActionEvent e) {
                if(chckbxUseGE.isSelected()){
                    radioButton.setEnabled(true);
    			} else radioButton.setEnabled(false);
    		});
    
    When i put that at the bottom of the constructor it tells me i need to change the variables to final in order to have them to work, and when i go back to the Design > preview it seems like this code doesnt disable the radiobutton (like it does nothing..)

     

    Just making sure, I don't know anyone's programming skills and if they're asking about something basic I tend to assume that they are such.

     

    Anyways, didn't mean to offend, but you need to do this...

     

    //OUTSIDE of constructor and any methods, declaring it as a global variable...
    private JCheckBox(lol JK whatever radio button is) radioButton;
    
    constructor() {
        chckbxUseGE.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    				if(chckbxUseGE.isSelected()){
                    radioButton.setEnabled(true);
    			} else radioButton.setEnabled(false);
    		}
             });
    }
    
    Also, make sure to not be declaring radioButton in your constructor anymore.
    Link to comment
    Share on other sites

     

    Just making sure, I don't know anyone's programming skills and if they're asking about something basic I tend to assume that they are such.

    Anyways, didn't mean to offend, but you need to do this...

     

     

     

    I was not offended don't worry :P.

     

    The default windowbuilder puts all variables inside of the constructor, i changed that later on but the code wasn't refreshed. Ill try that now!

     

     

    Well the code seems more stable, but i think the preview manager in windowbuilder does not actually execute the code, which means i got to implement the gui in my script and test it via the clien

     

    Link to comment
    Share on other sites

    I was not offended don't worry :P.

     

    The default windowbuilder puts all variables inside of the constructor, i changed that later on but the code wasn't refreshed. Ill try that now!

     

     

    Well the code seems more stable, but i think the preview manager in windowbuilder does not actually execute the code, which means i got to implement the gui in my script and test it via the clien

    If you're using windowbuilder, you can always just run the GUI class in Eclipse and it'll open. Windowbuilder auto creates a main method.

    Link to comment
    Share on other sites

    If you're using windowbuilder, you can always just run the GUI class in Eclipse and it'll open. Windowbuilder auto creates a main method.

    Yeah but running the GUI gives me errors, i don't know why.  The preview thingy works fine but i don't think that will implement any other code such as the listeners.

     

    I'll wait for computor to release his tutorial on this, or find anyone who will help me out maybe on teamviewer or sometihng lol

    Link to comment
    Share on other sites

    Yeah but running the GUI gives me errors, i don't know why.  The preview thingy works fine but i don't think that will implement any other code such as the listeners.

     

    I'll wait for computor to release his tutorial on this, or find anyone who will help me out maybe on teamviewer or sometihng lol

    Post or PM me your code on pastebin for the GUI and I'll take a look
    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.