sick_runesguy 0 Share Posted September 23, 2020 Hello I am having troube working with JTextField when making a sample GUI. For some reason its not reading any input the user feeds into it. I have attatched a snippet of my code, any suggestions would be greatly appreciated thanks :). Quote import java.util.List; import javax.swing.*; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.FlowLayout; import org.dreambot.api.script.AbstractScript; import org.dreambot.api.script.Category; public class testing extends AbstractScript { private boolean is_running; private int buy_amount=0; private String test=""; public void onStart() { log("-----------------"); log("STARTING SCRIPT"); log("-----------------"); SwingUtilities.invokeLater(()-> { createGUI(); } public void createGUI() { JFrame frame= new JFrame(); frame.setTitle("TESTING); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setLocationRelativeTo(Client.getInstance().getCanvas()); frame.setPreferredSize(new Dimension(400,200)); frame.getContentPane().setLayout(new BorderLayout()); JPanel settingPanel=new JPanel(); settingPanel.setLayout(new GridLayout(0,2)); // AMOUNT JLabel buy_amount_label =new JLabel(); buy_amount_label.setText("BUY AMOUNT:"); settingPanel.add(buy_amount_label); JTextField buy_amount_field=new JTextField(); settingPanel.add(buy_amount_field); //LOWER PANNEL JPanel buttonPanel=new JPanel(); buttonPanel.setLayout(new FlowLayout()); JButton button = new JButton(); button.setText("START"); buttonPanel.add(button); button.addActionListener(l-> { is_running=true; buy_amount=Integer.parseInt(buy_amount_field.getText()); test=buy_amount_field.getText(); }); frame.getContentPane().add(buttonPanel,BorderLayout.SOUTH); frame.getContentPane().add(settingPanel,BorderLayout.CENTER); frame.pack(); frame.setVisible(true) } public int onLoop() { if(is_running) { log("BUY AMOUNT = "+ buy_amount); log(test) } return Calculations.random(1500,2300); } } For some reason the program ignores the users input and the variables (buy_amount and test) retain their default values. Any suggestions as to why this is occurring? Link to comment Share on other sites More sharing options...
LordJashin32 54 Share Posted September 23, 2020 Might be your layout stuff you are using. Good luck. Cheers. Read some tutorials and make sure u get every detail right. I tend to put the gui in its own class to seperate logic more but up to u. EDIT: OH you are also missing a @ScriptManifest . Without that ur script won't run. frame.setTitle("TESTING); should be frame.setTitle("TESTING"); Here's the kind of code I use: panel1.setLayout(null); //---- label1 ---- label1.setText("Port:"); panel1.add(label1); label1.setBounds(15, 20, 50, 20); Link to comment Share on other sites More sharing options...
sick_runesguy 0 Author Share Posted September 23, 2020 Hi thanks for the feedback, even the @ScriptManifest, it wont read the input from JTextField, I have tried with components such as JButton and JComboBox and those seem to work, its just mainly having issues with reading input from JTextField. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.