erenjwz Posted September 30, 2015 Share Posted September 30, 2015 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; }} Quote Link to comment Share on other sites More sharing options...
Joseph Posted September 30, 2015 Share Posted September 30, 2015 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. Quote Link to comment Share on other sites More sharing options...
FrostBug Posted September 30, 2015 Share Posted September 30, 2015 (edited) 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 September 30, 2015 by FrostBug Quote Link to comment Share on other sites More sharing options...
itzDot Posted October 1, 2015 Share Posted October 1, 2015 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 Quote Link to comment Share on other sites More sharing options...
FrostBug Posted October 1, 2015 Share Posted October 1, 2015 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 Quote Link to comment Share on other sites More sharing options...
itzDot Posted October 1, 2015 Share Posted October 1, 2015 Typecasting the selected item should work fineik.. but it looks better Quote Link to comment Share on other sites More sharing options...