JComboBox problem

Discussion in 'Java' started by Allan Mullan, Apr 18, 2004.

  1. Allan Mullan

    Allan Mullan Guest

    Hey all :)

    I've got a program i'm working on which has a JComboBox and I need to
    get the results from it - the code is:

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.*;


    public class rDesktopGui extends JFrame {
    ServerConfig servers = new ServerConfig("/etc/rDesktopGui.conf"); //
    Starts working the ServerConfig class
    String[] listOfServers = servers.read(); // Creates a local copy of
    the read() method from the ServerConfig class
    String externalCommand = "rdesktop ";
    int fullTicked = 0;
    String server = null;


    // Setup components for 1st row
    private JPanel row1 = new JPanel();
    private JComboBox serverName = new JComboBox();
    private JButton goButton = new JButton("Go");
    private JButton exitButton = new JButton("Exit");


    // Setup components for 2nd row
    private JPanel row2 = new JPanel();
    private JCheckBox fullScreen = new JCheckBox("Fullscrreen", false);


    private Runnable systemCommand = new Runnable() {
    public void run() {
    System.out.println(externalCommand + ((fullTicked == 0) ? "" : "-f
    ") + server);
    try{
    Runtime runtime = Runtime.getRuntime(); // Creates a runtime
    environment for the external process
    // Spawn a shell sub-process
    Process process = runtime.exec(externalCommand); //
    serverName.getText() to get string from JTextBox
    BufferedReader buffer = new BufferedReader(new
    InputStreamReader(process.getInputStream()));
    String line;


    while((line = buffer.readLine()) != null)
    System.out.println(line);
    } catch(IOException ex) {
    System.out.println("Error running command - Invalid command!");
    }
    }
    };


    private ActionListener goListener = new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
    runSystemCommand();
    }
    };


    private ActionListener exitListener = new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
    System.exit(0);
    }
    };

    public ItemListener fullScreenListener = new ItemListener() {
    public void itemStateChanged(ItemEvent e) {
    int status = e.getStateChange();
    if(status == e.SELECTED)
    fullTicked = 1;
    else
    fullTicked = 0;
    }
    };

    public ItemListener serverNameListener = new ItemListener() {
    public void itemStateChanged(ItemEvent ie) {
    Object nameOfServer = ie.getItem();
    server = nameOfServer.toString();
    System.out.println(server);
    }
    };

    public rDesktopGui() {
    super("rDesktopGui Connection GUI");
    setLocation(10, 10);
    setSize(310,100);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Setup graphics
    Container contentPane = getContentPane();
    FlowLayout layout = new FlowLayout();
    contentPane.setLayout(layout);

    FlowLayout layout1 = new FlowLayout();
    for(int i = 0; i < listOfServers.length; i++)
    serverName.addItem(listOfServers);
    row1.setLayout(layout1);
    row1.add(serverName);
    row1.add(goButton);
    row1.add(exitButton);
    contentPane.add(row1);

    FlowLayout layout2 = new FlowLayout();
    row2.setLayout(layout2);
    row2.add(fullScreen);
    contentPane.add(row2);

    goButton.addActionListener(goListener);
    exitButton.addActionListener(exitListener);
    fullScreen.addItemListener(fullScreenListener);
    serverName.addItemListener(serverNameListener);

    setVisible(true);
    }

    private void runSystemCommand(){
    new Thread(systemCommand).start();
    }

    public static void main(String args[]){
    rDesktopGui frame = new rDesktopGui();
    }
    }


    When I run this it displays the current and the next selected, i.e if
    FOO is selected and you select OFF it' print both, I only want the
    desktination one....

    Any ideas?
     
    Allan Mullan, Apr 18, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tobi Krausl

    JComboBox problem, pse help!

    Tobi Krausl, Nov 27, 2003, in forum: Java
    Replies:
    6
    Views:
    4,376
    Tobi Krausl
    Dec 1, 2003
  2. Derek

    Problem with JComboBox

    Derek, May 9, 2005, in forum: Java
    Replies:
    3
    Views:
    861
  3. Genevieve
    Replies:
    13
    Views:
    3,763
    Genevieve
    Jul 6, 2005
  4. Replies:
    0
    Views:
    615
  5. timinganalyzer
    Replies:
    4
    Views:
    1,016
    timinganalyzer
    Oct 27, 2008
Loading...

Share This Page