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
  • The client is currently being updated for the latest game update!
    Due to the size of the changes the downtime may be extended!

    GUI is minuscule and empty.


    Guest

    Recommended Posts

    Guest

    I'm trying to create a GUI for my main script.

    Here is my main script file:

    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.methods.skills.Skill;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.wrappers.interactive.GameObject;
    
    import java.lang.reflect.Array;
    import java.util.Random;
    public class Main extends AbstractScript {
    	private MainGUI gui;
    
    	@Override
    	public void onstart(){
    	gui = new MainGUI(this);
    	gui.setVisible(true);
    	}
    }

    And here is my GUI:

    import java.awt.*;
    import java.awt.event.*;
    import java.beans.PropertyChangeEvent;
    import java.beans.PropertyChangeListener;
    import javax.swing.*;
    import javax.swing.border.CompoundBorder;
    import javax.swing.border.EmptyBorder;
    import javax.swing.border.TitledBorder;
    
    
    public class MainGUI extends JFrame {
        public MainGUI() {
            initComponents();
        }
    
        private Main context;
        public MainGUI(Main main){
            this.context = main;
        }
    
        private void startButtonActionPerformed(ActionEvent e) { //Start Button
            context.setStartScript(true);
        }
    
        private void initComponents() {
            // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
            startButton = new JButton();
            tabbedPane1 = new JTabbedPane();
            homeTab = new JPanel();
            skillComboBox = new JComboBox<>();
            chooseYourSkillsLabel = new JLabel();
            woodCuttingTab = new JPanel();
            woodCuttingMode = new JComboBox<>();
            woodCuttingModeLabel = new JLabel();
            woodCuttingLocationLabel = new JLabel();
            woodCuttingLocation = new JComboBox<>();
            woodCuttingRandomLocationWarningLabel = new JLabel();
            woodCuttingBreakLabel = new JLabel();
            woodCuttingBreakTimer = new JComboBox<>();
            woodCuttingBreakInMinsLabel = new JLabel();
            miningTab = new JPanel();
            fishingTab = new JPanel();
    
            //======== this ========
            setTitle("ProjectLevel");
            Container contentPane = getContentPane();
            contentPane.setLayout(null);
    
            //---- startButton ----
            startButton.setText("Start");
            startButton.addActionListener(e -> startButtonActionPerformed(e));
            contentPane.add(startButton);
            startButton.setBounds(155, 215, 103, 45);
    
            //======== tabbedPane1 ========
            {
    
                //======== homeTab ========
                {
    
                    // JFormDesigner evaluation mark
                    homeTab.setBorder(new CompoundBorder(
                            new TitledBorder(new EmptyBorder(0, 0, 0, 0),
                                    "JFormDesigner Evaluation", TitledBorder.CENTER,
                                    TitledBorder.BOTTOM, new Font("Dialog", Font.BOLD, 12),
                                    Color.red), homeTab.getBorder())); homeTab.addPropertyChangeListener(new PropertyChangeListener(){public void propertyChange(PropertyChangeEvent e){if("border".equals(e.getPropertyName()))throw new RuntimeException();}});
    
                    homeTab.setLayout(null);
    
                    //---- skillComboBox ----
                    skillComboBox.setAction(null);
                    skillComboBox.setModel(new DefaultComboBoxModel<>(new String[] {
                            "WoodCutting",
                            "Mining",
                            "Fishing",
                            "Randomized"
                    }));
                    homeTab.add(skillComboBox);
                    skillComboBox.setBounds(145, 25, 145, skillComboBox.getPreferredSize().height);
    
                    //---- chooseYourSkillsLabel ----
                    chooseYourSkillsLabel.setText("Choose Your Skills:");
                    homeTab.add(chooseYourSkillsLabel);
                    chooseYourSkillsLabel.setBounds(new Rectangle(new Point(40, 30), chooseYourSkillsLabel.getPreferredSize()));
    
                    { // compute preferred size
                        Dimension preferredSize = new Dimension();
                        for(int i = 0; i < homeTab.getComponentCount(); i++) {
                            Rectangle bounds = homeTab.getComponent(i).getBounds();
                            preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                            preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                        }
                        Insets insets = homeTab.getInsets();
                        preferredSize.width += insets.right;
                        preferredSize.height += insets.bottom;
                        homeTab.setMinimumSize(preferredSize);
                        homeTab.setPreferredSize(preferredSize);
                    }
                }
                tabbedPane1.addTab("Home", null, homeTab, "Home Tab");
    
                //======== woodCuttingTab ========
                {
                    woodCuttingTab.setLayout(null);
    
                    //---- woodCuttingMode ----
                    woodCuttingMode.setModel(new DefaultComboBoxModel<>(new String[] {
                            "Bank",
                            "Drop"
                    }));
                    woodCuttingTab.add(woodCuttingMode);
                    woodCuttingMode.setBounds(new Rectangle(new Point(140, 20), woodCuttingMode.getPreferredSize()));
    
                    //---- woodCuttingModeLabel ----
                    woodCuttingModeLabel.setText("Mode:");
                    woodCuttingTab.add(woodCuttingModeLabel);
                    woodCuttingModeLabel.setBounds(85, 25, 40, woodCuttingModeLabel.getPreferredSize().height);
    
                    //---- woodCuttingLocationLabel ----
                    woodCuttingLocationLabel.setText("Location:");
                    woodCuttingTab.add(woodCuttingLocationLabel);
                    woodCuttingLocationLabel.setBounds(new Rectangle(new Point(85, 60), woodCuttingLocationLabel.getPreferredSize()));
    
                    //---- woodCuttingLocation ----
                    woodCuttingLocation.setModel(new DefaultComboBoxModel<>(new String[] {
                            "Yews - Grand Exchange",
                            "Willows - Dragnor",
                            "Oaks - Varrock West",
                            "Randomize",
                            "Level Specific"
                    }));
                    woodCuttingTab.add(woodCuttingLocation);
                    woodCuttingLocation.setBounds(new Rectangle(new Point(140, 55), woodCuttingLocation.getPreferredSize()));
    
                    //---- woodCuttingRandomLocationWarningLabel ----
                    woodCuttingRandomLocationWarningLabel.setText("(Only use Randomize if you're over level 60 Woodcutting)");
                    woodCuttingTab.add(woodCuttingRandomLocationWarningLabel);
                    woodCuttingRandomLocationWarningLabel.setBounds(new Rectangle(new Point(35, 85), woodCuttingRandomLocationWarningLabel.getPreferredSize()));
    
                    //---- woodCuttingBreakLabel ----
                    woodCuttingBreakLabel.setText("Break Every:");
                    woodCuttingTab.add(woodCuttingBreakLabel);
                    woodCuttingBreakLabel.setBounds(new Rectangle(new Point(75, 110), woodCuttingBreakLabel.getPreferredSize()));
    
                    //---- woodCuttingBreakTimer ----
                    woodCuttingBreakTimer.setModel(new DefaultComboBoxModel<>(new String[] {
                            "45",
                            "60",
                            "90",
                            "120",
                            "180",
                            "240",
                            "Never Break"
                    }));
                    woodCuttingTab.add(woodCuttingBreakTimer);
                    woodCuttingBreakTimer.setBounds(new Rectangle(new Point(145, 105), woodCuttingBreakTimer.getPreferredSize()));
    
                    //---- woodCuttingBreakInMinsLabel ----
                    woodCuttingBreakInMinsLabel.setText("(In Mins)");
                    woodCuttingTab.add(woodCuttingBreakInMinsLabel);
                    woodCuttingBreakInMinsLabel.setBounds(260, 110, 55, 16);
    
                    { // compute preferred size
                        Dimension preferredSize = new Dimension();
                        for(int i = 0; i < woodCuttingTab.getComponentCount(); i++) {
                            Rectangle bounds = woodCuttingTab.getComponent(i).getBounds();
                            preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                            preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                        }
                        Insets insets = woodCuttingTab.getInsets();
                        preferredSize.width += insets.right;
                        preferredSize.height += insets.bottom;
                        woodCuttingTab.setMinimumSize(preferredSize);
                        woodCuttingTab.setPreferredSize(preferredSize);
                    }
                }
                tabbedPane1.addTab("WoodCutting", null, woodCuttingTab, "WoodCutting Tab");
    
                //======== miningTab ========
                {
                    miningTab.setLayout(null);
    
                    { // compute preferred size
                        Dimension preferredSize = new Dimension();
                        for(int i = 0; i < miningTab.getComponentCount(); i++) {
                            Rectangle bounds = miningTab.getComponent(i).getBounds();
                            preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                            preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                        }
                        Insets insets = miningTab.getInsets();
                        preferredSize.width += insets.right;
                        preferredSize.height += insets.bottom;
                        miningTab.setMinimumSize(preferredSize);
                        miningTab.setPreferredSize(preferredSize);
                    }
                }
                tabbedPane1.addTab("Mining", null, miningTab, "Mining Tab");
    
                //======== fishingTab ========
                {
                    fishingTab.setLayout(null);
    
                    { // compute preferred size
                        Dimension preferredSize = new Dimension();
                        for(int i = 0; i < fishingTab.getComponentCount(); i++) {
                            Rectangle bounds = fishingTab.getComponent(i).getBounds();
                            preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                            preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                        }
                        Insets insets = fishingTab.getInsets();
                        preferredSize.width += insets.right;
                        preferredSize.height += insets.bottom;
                        fishingTab.setMinimumSize(preferredSize);
                        fishingTab.setPreferredSize(preferredSize);
                    }
                }
                tabbedPane1.addTab("Fishing", null, fishingTab, "Fishing Tab");
            }
            contentPane.add(tabbedPane1);
            tabbedPane1.setBounds(0, 5, 395, 205);
    
            { // compute preferred size
                Dimension preferredSize = new Dimension();
                for(int i = 0; i < contentPane.getComponentCount(); i++) {
                    Rectangle bounds = contentPane.getComponent(i).getBounds();
                    preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                    preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                }
                Insets insets = contentPane.getInsets();
                preferredSize.width += insets.right;
                preferredSize.height += insets.bottom;
                contentPane.setMinimumSize(preferredSize);
                contentPane.setPreferredSize(preferredSize);
            }
            pack();
            setLocationRelativeTo(getOwner());
            // JFormDesigner - End of component initialization  //GEN-END:initComponents
        }
    
    
    
        // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
        private JButton startButton;
        private JTabbedPane tabbedPane1;
        private JPanel homeTab;
        private JComboBox<String> skillComboBox;
        private JLabel chooseYourSkillsLabel;
        private JPanel woodCuttingTab;
        private JComboBox<String> woodCuttingMode;
        private JLabel woodCuttingModeLabel;
        private JLabel woodCuttingLocationLabel;
        private JComboBox<String> woodCuttingLocation;
        private JLabel woodCuttingRandomLocationWarningLabel;
        private JLabel woodCuttingBreakLabel;
        private JComboBox<String> woodCuttingBreakTimer;
        private JLabel woodCuttingBreakInMinsLabel;
        private JPanel miningTab;
        private JPanel fishingTab;
        // JFormDesigner - End of variables declaration  //GEN-END:variables
    
    
        public String getSkillComboBox() {
            return skillComboBox.getSelectedItem().toString();
        }
    
        public String getWoodCuttingMode() {
            return woodCuttingMode.getSelectedItem().toString();
        }
    
        public String getWoodCuttingLocation() {
            return woodCuttingLocation.getSelectedItem().toString();
        }
    }

    This is what my GUI looks like when I run the script through dreambot: https://gyazo.com/ded6cd2c630d3c97d4ac63495db9a9d4

    I'm using JFormDesigner to create the GUI.

     

    Thanks for any help in advance.

    Link to comment
    Share on other sites

    Guest

    I seem to have fixed it by setting all of the panels to visible.  Thanks!

    Link to comment
    Share on other sites

    I made a generic script UI for this kind of thing to tidy up my own script code if you're interested.

    The source code is here if you wanna steal some ideas:

     

    Good luck :)

    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.