June 11, 20187 yr hi im noob and just learned how to make a GUI with eclipse window builder and move it into main.java (so theres no need for another .java file) current main.java code @ScriptManifest(author = "gay", info = "gay", name = "gay", version = 69, logo = "") public class Main extends Script { private JPanel ScriptName; public String chat; public void JFrame() { JFrame ScriptName; ScriptName = new JFrame(); ScriptName.setResizable(false); ScriptName.setTitle("AIO FIGHTER"); //your own title ScriptName.setBounds(100, 100, 250, 250); ScriptName.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ScriptName.getContentPane(); ScriptName.setLayout(null); //START BUTTON JButton btnNewButton = new JButton("START!"); btnNewButton.setBounds(10, 177, 214, 23); ScriptName.add(btnNewButton); ScriptName.getContentPane().add(btnNewButton); ScriptName.setVisible(true); //TEXTFIELD JTextField txtnameOfNpc = new JTextField(); txtnameOfNpc.setHorizontalAlignment(SwingConstants.CENTER); txtnameOfNpc.setText("(name of npc to kill)"); txtnameOfNpc.setBounds(10, 11, 214, 20); ScriptName.add(txtnameOfNpc); txtnameOfNpc.setColumns(10); ScriptName.getContentPane().add(btnNewButton); ScriptName.setVisible(true); //makes the button appearing when the script start txtnameOfNpc.addActionListener(e -> chat = (String) txtnameOfNpc.getSelectedText().toString()); } @Override public void onStart() { //log("Let's get started!"); JFrame(); } @Override public int onLoop() throws InterruptedException { return (random(50, 150)); } @Override public void onExit() { //log("Thanks for running my Tea Thiever!"); ScriptName.setVisible(false); } @Override public void onPaint(Graphics2D g) { ///hhhhhhhh nothing } } so now my problem is that i cant get the string "chat" to work for some reason, i tried some ActionListener things from the post below but couldnt get them to work either and i dont know whats wrong with this one txtnameOfNpc.addActionListener(e -> chat = (String) txtnameOfNpc.getSelectedText().toString()); ? help pls! ty!
June 11, 20187 yr Are you sure you are supposed to be using "getSelectedText()"? What happens if you just use getText()? Edited June 11, 20187 yr by ProjectPact
June 11, 20187 yr Author 22 minutes ago, ProjectPact said: Are you sure you are supposed to be using "getSelectedText()"? What happens if you just use getText()? doesnt work, tried another post too and all my code here (GUI.JAVA)))))))) public class gui { public void run(main Main) { JFrame jFrame = new JFrame("joujouou"); jFrame.setSize(300, 500); jFrame.setResizable(false); JPanel settingsPanel = new JPanel(); TitledBorder leftBorder = BorderFactory.createTitledBorder("Settings"); leftBorder.setTitleJustification(TitledBorder.LEFT); settingsPanel.setBorder(leftBorder); settingsPanel.setLayout(null); settingsPanel.setBounds(5, 200, 280, 180); jFrame.add(settingsPanel); JPanel startPanel = new JPanel(); startPanel.setLayout(null); startPanel.setBounds(5, 350, 70, 20); jFrame.add(startPanel); JTextField txtnameOfNpc = new JTextField(); txtnameOfNpc.setHorizontalAlignment(SwingConstants.CENTER); txtnameOfNpc.setText("(name of npc to kill)"); txtnameOfNpc.setBounds(10, 11, 214, 20); settingsPanel.add(txtnameOfNpc); txtnameOfNpc.setColumns(10); txtnameOfNpc.addActionListener(e -> Main.hide = (String) txtnameOfNpc.getText().toString()); JButton startButton = new JButton("Start"); startButton.addActionListener(e -> { synchronized (Main.lock) { Main.lock.notify(); } jFrame.setVisible(false); }); startButton.setBounds(5, 390, 70, 20); startPanel.add(startButton); jFrame.setVisible(true); } } (MAIN.JAVAAAAAAAAAAAA) @ScriptManifest(author = "hh", info = "hh", name = "hh", version = 0, logo = "") public class main extends Script { Object lock = new Object(); private gui gui = new gui(); public String hide = ""; @Override public void onStart() { gui.run(this); } @Override public int onLoop() throws InterruptedException { return (random(50, 100)); } @Override public void onExit() { } @Override public void onPaint(Graphics2D g) { g.drawString(hide, 50, 50); <------------ TRYING TO PRINT IT OUT ON SCREEN (if this would work i would start writing aio killer ofc) } }
June 11, 20187 yr Adding an ActionListener to a text field isn't going to work (you would need to use a DocumentListener, but that would be ugly as hell and unnecessary) The better way to approach it would be to get the text from the text field when the user clicks start. startButton.addActionListener(e -> chat = txtnameOfNpc.getText()); Your GUI code all kinds of fucked up though Edited June 11, 20187 yr by Explv
June 11, 20187 yr Author 34 minutes ago, Explv said: Adding an ActionListener to a text field isn't going to work (you would need to use a DocumentListener, but that would be ugly as hell and unnecessary) The better way to approach it would be to get the text from the text field when the user clicks start. startButton.addActionListener(e -> chat = txtnameOfNpc.getText()); Your GUI code all kinds of fucked up though ty so much you always helping us noobs out! much love
June 12, 20187 yr 15 hours ago, alkku15 said: hi im noob and just learned how to make a GUI with eclipse window builder and move it into main.java (so theres no need for another .java file) current main.java code @ScriptManifest(author = "gay", info = "gay", name = "gay", version = 69, logo = "") public class Main extends Script { private JPanel ScriptName; public String chat; public void JFrame() { JFrame ScriptName; ScriptName = new JFrame(); ScriptName.setResizable(false); ScriptName.setTitle("AIO FIGHTER"); //your own title ScriptName.setBounds(100, 100, 250, 250); ScriptName.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ScriptName.getContentPane(); ScriptName.setLayout(null); //START BUTTON JButton btnNewButton = new JButton("START!"); btnNewButton.setBounds(10, 177, 214, 23); ScriptName.add(btnNewButton); ScriptName.getContentPane().add(btnNewButton); ScriptName.setVisible(true); //TEXTFIELD JTextField txtnameOfNpc = new JTextField(); txtnameOfNpc.setHorizontalAlignment(SwingConstants.CENTER); txtnameOfNpc.setText("(name of npc to kill)"); txtnameOfNpc.setBounds(10, 11, 214, 20); ScriptName.add(txtnameOfNpc); txtnameOfNpc.setColumns(10); ScriptName.getContentPane().add(btnNewButton); ScriptName.setVisible(true); //makes the button appearing when the script start txtnameOfNpc.addActionListener(e -> chat = (String) txtnameOfNpc.getSelectedText().toString()); } @Override public void onStart() { //log("Let's get started!"); JFrame(); } @Override public int onLoop() throws InterruptedException { return (random(50, 150)); } @Override public void onExit() { //log("Thanks for running my Tea Thiever!"); ScriptName.setVisible(false); } @Override public void onPaint(Graphics2D g) { ///hhhhhhhh nothing } } Careful, the variable you reference in onExit is uninitialized and will throw a nullpointerexception.
June 12, 20187 yr Just to let the world know you're gay, right? @ScriptManifest(author = "gay", info = "gay", name = "gay", version = 69, logo = "")
Create an account or sign in to comment