Results 1 to 4 of 4

Thread: Java + Ubuntu Commands

  1. #1
    Join Date
    Jan 2008
    Location
    UK
    Beans
    34
    Distro
    Hardy Heron (Ubuntu Development)

    Java + Ubuntu Commands

    My first non uni and app. Basically installed php, mysql and apache from the repo's and wanted a gui to stop/start apache/mysql like XAMPP.

    Ok after googling and playing around with netbeans. I have found this method of running commands through Java.

    Code:
        
        private String SHELL = "gnome-terminal";
        private String SHELL_PARAM ="-e";
    
    //Method to execute commands
    public void doAction(String command,String servicename, String actionname){
            ProcessBuilder launcher = new ProcessBuilder();
            Map<String, String> environment = launcher.environment();
            launcher.redirectErrorStream(true);
            launcher.command(SHELL,SHELL_PARAM,command);
            
            Process p;
            String lines;
            try {
                p = launcher.start();
                p.waitFor();
                BufferedReader is = new BufferedReader(
                        new InputStreamReader(p.getInputStream()));
                
                BufferedReader err = new BufferedReader(
                        new InputStreamReader(p.getErrorStream()));
                
                String errMsg = "";
                while ((lines = is.readLine()) != null) {
                    errMsg += lines + "\n";
                }
                
                while ((lines = err.readLine()) != null) {
                    errMsg += lines + "\n";
                }
                setStatusText(errMsg);
                setStatusText(servicename + " " + actionname + "...");
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    
    //method called from action listeners placed by netbeans like e.g.
    // doAction("sudo /etc/init.d/apache2 stop", "apache", "stopped");
    // last 2 params are for a message to be put in a text area,
    // setting text area is a method, not included but a simple .setText()

    The only really things I would like is, is there a way to get the full screen password box like when accessing admin stuff.

    Can Java be themed to match Ubuntu's default human theme, it looks horrible really.
    Dell Inspiron 6400 E1505 Laptop / AMD 2400+ Server Box

  2. #2
    Join Date
    Nov 2006
    Location
    Israel
    Beans
    765
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Java + Ubuntu Commands

    Maybe using gksudo...
    Intel E6300 / MSI P4M890M / 2GB DDR2 677 / 80GB + 1TB SATA2 / GeForce 6200TC / DL DVD+-RW / Dell 24" U2410

  3. #3
    Join Date
    Jan 2008
    Location
    UK
    Beans
    34
    Distro
    Hardy Heron (Ubuntu Development)

    Re: Java + Ubuntu Commands

    That works great, starting to think Java isn't so bad for writing little apps in.

    But how can I make it look pretty like Gnome ?

    edit: after googling

    try{
    UIManager.setLookAndFeel(
    "com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
    }catch(Exception e{
    }

    works great!
    Last edited by midnightray; March 15th, 2008 at 04:14 PM.
    Dell Inspiron 6400 E1505 Laptop / AMD 2400+ Server Box

  4. #4
    Join Date
    Aug 2006
    Location
    Pittsburgh, PA
    Beans
    424
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Java + Ubuntu Commands

    Java does support changing the Theme from Swing to a more native theme.

    I don't like how Swing looks by default, the only benefit it has is that it will be consistent on all platforms. I usually use a native look and feel.

    Here is a Sun article about setting look and feel. http://java.sun.com/docs/books/tutor...feel/plaf.html


    As for the sudo thing. Either rn the program with gksudo java program or maybe run a system command like this:

    gksudo cat /dev/core that will force a gksudo popup. I think generally this is considered a bad thing though, programs aren't usually supposed to elevate themselves.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •