Re: Creating a simple visual user interface
 
Danger_Duck wrote:
Right now, I have a program that you run off command prompt by typing:
java progName arg0, arg1, .....
like many homemade programs out there. Fine and terrific for me, but
not for the average joe who doesn't know how to access a file
directory....
So, are there any recommendations of how to make a more user-friendly
graphical interface that can consist of a form and input entries? Like
java.util.form or something?
I also use eclipse, but creating an entire view/plugin takes up a lot
more space/time than I want for simple programs.
So, I'd just like to hear suggestions on your favorite ways to make
simple programs accessible to non-technical users. Til then, I will
continue to use command prompt as I always have...
Thanks
Simple GUIs are very easy to do.  Just create a frame, add your 
components and the code to populate and depopulate the fields.  Learn 
how to use GridBagLayout.  You can make very simple GUI programs that 
way.  I don't use an IDE, I just use vim for an editor.  I'll even write 
you a simple sample.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SimpleGUI extends JFrame implements ActionListener {
     JTextField tf;
     public SimpleGUI() {
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         setLayout(new GridBagLayout());
         GridBagConstraints c = new GridBagConstraints();
         c.gridy = 0;  c.gridwidth = 2;
         tf = new JTextField(20);
         add(tf,c);
         ++c.gridy;  c.gridwidth = 1;  c.weightx = 1.0;
         c.anchor = GridBagConstraints.EAST;
         JButton getButton = new JButton("Get Data");
         getButton.addActionListener(this);
         add(getButton,c);
         c.anchor = GridBagConstraints.WEST;
         JButton processButton = new JButton("Process Data");
         processButton.addActionListener(this);
         add(processButton,c);
         // make the buttons the same size
         Dimension d = processButton.getPreferredSize();
         getButton.setPreferredSize(d);
         pack();
         setVisible(true);
     }
     public void actionPerformed(ActionEvent ae) {
         String ac = ae.getActionCommand();
         if (ac.equals("Get Data")) {
             // get the data from somewhere
             // put it in the JTextField
             tf.setText("New Data");
         } else if (ac.equals("Process Data")) {
             // process data
             String str = tf.getText().toUpperCase();
             // put result in JTextField
             tf.setText(str);
         }
     }
     public static void main(String[] args) {
         // Swing components must be created and accessed on the EDT
         EventQueue.invokeLater(new Runnable() {
             public void run() {
                 new SimpleGUI();
             }
         });
     }
}
-- 
Knute Johnson
email s/nospam/knute2008/
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
      ------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access