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.

Jframe class not working properly

Featured Replies

I have 2 classes: one "main.java" and the other "Gui.java".

 

i want to start running the code from Gui when main.java starts but I'm getting errors (it's probably one line of code that's wrong).

Tried everything also is this my first JFrame code if somone could advise me on how i could approach it better;

 

(main.java)

 

public class main extends Script {
    
    private Gui Kies = new Gui();

    ...
    Kies.getKeuze();

 

 

(Jfarme.java)

 

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;

public class Gui extends JFrame implements ActionListener {
    
    private static final long serialVersionUID = 1L;
    private String[] fish = {"Trout", "Tuna", "Lobster"};
    private String Keuze;
    
    private JComboBox<String> Dropdown = new JComboBox<String>();

    public static void main(String[] args) {
        new Gui().setVisible(true);
    }
    
    public Gui() {
        super("Hylian selector");
        setSize(380, 250);
        setResizable(false);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setLayout(new FlowLayout());
        
        JButton button = new JButton("Select");
        button.addActionListener(this);
        
        for(int i = 0; i < 3; i++){
            Dropdown.addItem(fish);
        }
        add(button);
        add(Dropdown);
    }
    
    void Derp(){
        System.out.println("Derp");
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        this.Keuze = (String) (Dropdown.getSelectedItem());
        System.out.println(this.Keuze);
        dispose();
    }

    public String getKeuze() {
        return this.Keuze;
    }
}
 

It's better if you create the private field and initialI've it in the onstart. Then do kies.setVisible(true)

Also remove that main void method in the gui class. Since you have to do it in the main class.

Giving us the error code would of help me explain what's going wrong with the script.

J combo box has a parameter of an array and or enums.

Meaning you can do something like new JComboxBox <string>(array);

Also just use a method that grabs the value of the JComboxBox instead setting the value in a sepreate private field.

If you are only using one option I suggest you use a jOptionPane.

You never set the JFrame to be visible

 

Also, EXIT_ON_CLOSE is probably not the default action you want, since this will close the entire osbot client as well

Edited by FrostBug

 this.Keuze = (String) (Dropdown.getSelectedItem());
        System.out.println(this.Keuze);
        dispose();

 

Keuze = Dropdown.getSelectedItem().toString();

dispose()

 

also.. instead of EXIT_ON_CLOSE use DISPOSE_ON_CLOSE

 this.Keuze = (String) (Dropdown.getSelectedItem());

        System.out.println(this.Keuze);

        dispose();

 

Keuze = Dropdown.getSelectedItem().toString();

dispose()

 

also.. instead of EXIT_ON_CLOSE use DISPOSE_ON_CLOSE

 

Typecasting the selected item should work fine

 

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.