Go Back   Talk Root - PC Hardware, Software and Web Development forums > Internet & Website Management > Programming Discussion > DotNet



Reply
 
LinkBack Thread Tools Rate Thread
  #1  
Old 04-18-2004, 06:42 AM
Allan Mullan
Guest
 
Posts: n/a
Default JComboBox problem

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[i]);
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?
Reply With Quote
Reply

Bookmarks
Sponsored Links
FatCow $88 Plan for $66 only Host Unlimited Domains on 1 Account Professional Hosting from Just Host


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Download Problem Richlife Vista 1 06-18-2008 06:45 AM
whats the source of the problem? Zemfik Hardware 0 02-26-2008 02:02 PM
Wireless network @ work problem foro Networking 0 09-19-2007 07:12 AM
Online updation problem arppt01 Advocacy 0 03-31-2007 08:43 AM
Scanner problem arppt01 Advocacy 0 03-31-2007 08:23 AM


All times are GMT -7. The time now is 01:02 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0
© 2008 TalkRoot.com