Results 1 to 2 of 2
  1. #1
    Lyricid is offline Member
    Join Date
    Nov 2009
    Posts
    28
    Rep Power
    0

    Question Create interface from my code

    I have attached my code as follow i am currently using NetBeans and have asked similar questions on this site and have been very helpful but i just cant get it to work

    if you run the InsertionSort Class you get the console output telling you to enter amount, then enter range, this then shows the unsorted array then sorted array, and the the time take in ns and ms

    I want to create a interface that allows the user to enter the two inputs and then the interface to show the unsorted array and then sorted array and the times taken

    Any ideas?? its been baffling me for a few days
    Attached Files Attached Files

  2. #2
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    6

    Default

    Have you been through the tutorial Learning Swing with the NetBeans IDE ?
    (Hint: Do not respond here until your answer is, "Yes.")

    A key conceptual warp is to switch from a program-driven, prompting, linear interface
    to a user centric, event driven interface.
    Your application will have five JTextFields and two JTextAreas:
    field for entering amount
    field for entering lower range limit
    field for entering upper range limit
    output field for displaying time in msec
    output field for displaying time in nsec
    JList for unsorted list
    JList for sorted list

    By initializing the three data entry fields with reasonable values,
    the application can respond to actionPerformed in any of those fields
    by generating data, sorting it, and reporting the time.

    A better appearance would result from designing the screen layout with NetBeans.
    But given my new fondness for Box, here is a simple screen layout.

    Java Code:
    public class SortToy extends JPanel {
    	Vector<String> unsorted = new Vector<String>();
    	Vector<String> sorted = new Vector<String>();
    	JTextField countBox = new JTextField("10", 5);
    	JTextField lowerBox = new JTextField("0", 5);
    	JTextField upperBox = new JTextField("100", 5);
    	JTextField nanoBox = new JTextField(10);
    	JScrollPane scrollSorted = new JScrollPane(new JList(sorted));
    	JScrollPane scrollUnsorted = new JScrollPane(new JList(unsorted));
    	static Dimension listSize = new Dimension(60, 120);
    
    	public  SortToy()  {
    		scrollUnsorted.setPreferredSize(listSize);
    		scrollSorted.setPreferredSize(listSize);
    
    		Box fieldBox = Box.createVerticalBox();  // four rows of JTextField
    		fieldBox.add(countBox);  // row 1
    		fieldBox.add(lowerBox);
    		fieldBox.add(upperBox);
    		fieldBox.add(nanoBox);   // row 4
    		Box appBox = Box.createHorizontalBox();  // three columns
    		appBox.add(fieldBox);     // fields in column 1
    		appBox.add(scrollUnsorted);   // unsorted in column 2
    		appBox.add(scrollSorted);   // sorted in column 3
    		add(appBox);
    	}
    	public static void main(String args[]) {
    		final JFrame foo = new JFrame();
    		foo.add(new SortToy());
    		foo.pack();
    		EventQueue.invokeLater(new Runnable() {
    			public void run() { foo.setVisible(true); }
    		});
    	}
    }

Similar Threads

  1. code to create a folder in java
    By radhika123 in forum New To Java
    Replies: 7
    Last Post: 07-21-2011, 12:21 PM
  2. Trying to create a code for queue, complex stuff...
    By Mikey_S in forum Threads and Synchronization
    Replies: 3
    Last Post: 09-28-2009, 10:13 PM
  3. How to create directory through Java Code
    By Java Tip in forum java.io
    Replies: 1
    Last Post: 04-14-2009, 04:34 PM
  4. Creating a java gui to create xml code
    By Jman in forum New To Java
    Replies: 3
    Last Post: 04-27-2008, 07:56 PM
  5. Linking code to GUI Interface
    By ai_2007 in forum Advanced Java
    Replies: 1
    Last Post: 07-02-2007, 02:36 PM

Posting Permissions

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