Results 1 to 2 of 2
Thread: Create interface from my code
- 11-18-2009, 08:59 AM #1
Member
- Join Date
- Nov 2009
- Posts
- 28
- Rep Power
- 0
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
- 11-18-2009, 05:39 PM #2
Senior Member
- Join Date
- Aug 2009
- Location
- Pittsburgh, PA
- Posts
- 284
- Rep Power
- 4
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
-
code to create a folder in java
By radhika123 in forum New To JavaReplies: 7Last Post: 07-21-2011, 11:21 AM -
Trying to create a code for queue, complex stuff...
By Mikey_S in forum Threads and SynchronizationReplies: 3Last Post: 09-28-2009, 09:13 PM -
How to create directory through Java Code
By Java Tip in forum java.ioReplies: 1Last Post: 04-14-2009, 03:34 PM -
Creating a java gui to create xml code
By Jman in forum New To JavaReplies: 3Last Post: 04-27-2008, 06:56 PM -
Linking code to GUI Interface
By ai_2007 in forum Advanced JavaReplies: 1Last Post: 07-02-2007, 01:36 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks