Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Set Skill Level inside Gui

Featured Replies

So I read explv's GUI tutorial however It didn't quite cover retrieving integers from JtextField and then setting that input into static Ints

 

  • I want this Public Int to be changed to whatever the user types into the JtextField 
  • I have all the panels and Jframe / Dialogues setup and the GUI is functioning, now Im just trying to get the input data.
	public static int chosenCookingLvl = Gui.thisLevelCook;	 			// This is in another class, This is where I need the users chosen cooking level to be placed


//  GUI CLASS

	public static int thisLevelCook;        

        JTextField cookLvlTxt = new JTextField(7);   						 // This is where you write what level you want
		  cookLvlTxt.addActionListener(cook -> {      						 // This is the action listener attached to the JtextField where you write what level you want.
		        int cookboi = Integer.parseInt(cookLvlTxt.getText().trim());   
		        thisLevelCook = cookboi;                                 			 // THIS IS WHAT I NEED HELP WITH 
              // How do I get this value 
		  });

Any help is appreciated. I have tried to make sense of the JtextField  Swing Documents and looked through multiple cancerous Youtube Videos that had horrendous dubstep music and horrendous talking volumes. :(I have a start button that is functioning, Maybe I need to set the value when the user press's start? not sure how though...

How are you guys making Scripts with a GUI  that let you choose Input for desired Skill levels?
:doge:

 

Edited by Elixar

It's not enough just to copy/paste code, you actually need to read it and try to understand what it's doing.

Here:

 


	// ...
	
	textField.addActionListener(e -> {
	
		String text = ((JTextField) e.getSource()).getText()
		
		int number = -1;
		
		try {
		
			number = Integer.parseInt(text);
			
			someStaticNumber = number; // let's pretend someStaticNumber is a static int
			
		} catch (NumberFormatException e) {
		
			// err you typed something in, but it wasn't a number!
		}
	});
	
	
	// ...

When you hit [enter] after typing in a number, that'll kick-start an "action event" which will go on to kick-start a bunch of routines that deal with that event.

  • Author

SOLVED
Solution

 

Gui class{

	private JSpinner cookLvl;   				// Adding this was part of the solution
 	
	public Gui(){
	// I left out 99% of my actual GUI because obviously you need frames and panels.
	cookLvl = new JSpinner(new SpinnerNumberModel(0, 0, 99, 1));              						 // Adding this was part of the solution
      	JButton startButton = new JButton("Start");
		startButton.addActionListener(e -> startButtonActionPerformed(e));     					 // Adding this was part of the solution
			started = true;  
			close();
		});
}

	private void startButtonActionPerformed(ActionEvent e) {     									 // Adding this was part of the solution
		Task.chosenCookingLvl = (int) cookLvl.getValue();              										// Adding this was part of the solution
		this.close();
	}
}


I appreciate the PMS everyone, However I just did the less complex solution, I also forgot to 

Use Components for what they are intended for.

  • Jtextifled = Text
  • Jspinner = numbers with inbuilt restriction Parameters


Instead of using a Jtextfield and Parsing the Integer + setting up a filter to make sure it only accepts numbers in the text feed that is between 0-99

I just used a Jspinner instead and made sure to set proper variables
problem solved

Edited by Elixar

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.