 |
| Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

October 9th, 2007, 06:19 PM
|
|
Authorized User
|
|
Join Date: Oct 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Research about JAVA
Hello geeks,
do anyone have a research about JAVA?

Please help!!!
~*Cuty*~
__________________
~*Cuty*~
|
|

October 30th, 2007, 05:09 AM
|
|
Registered User
|
|
Join Date: Oct 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
help me plz solve this problem?!?!!!
Project
This project consists of writing a Java application that sorts input data.
The program will perform the following steps:
Step 1. Read input from a screen â using GUI
Step 2. Sort the input. For example, if the input is a sequence (11,44,33,55,22), and descending order is selected then the sorted sequence will be (55,44,33,22,11). The user can choose either to sort in descending or ascending order.
For example, if the input sequence is
4 2 9 3 5 6 7 8 10 11 1 12 14 13
then the screen will display the following information:
Data Structure: Array / Linked Chain
Sorting Algorithm: (whatever algorithm â taught in class)
Order : Ascending / Descending
Numbers Read In: 14
Input Sequence:
4 2 9 3 5 6 7 8 10 11
1 12 14 13
Sorted Sequence:
14 13 12 11 10 9 8 7 6 5
4 3 2 1
|
|

November 1st, 2007, 07:54 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Sounds like your homework! I don't think anyone will want to do it for you and if they did you wouldn't learn much. So, lets have a look at what code you've written, or tell us how you think the program should work.
--
Charlie Harvey's website - linux, perl, java, anarchism and punk rock: http://charlieharvey.org.uk
|
|

November 2nd, 2007, 04:06 AM
|
|
Registered User
|
|
Join Date: Oct 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
yup,my homework..i'm sorry.i can't think anymore..
this is what i'm doing...can you suggest some better program?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*; public class Insertion extends JFrame implements ActionListener
{
JLabel lb1,lb2,lb3,lb4,lb5,lb6;
static JTextField txt1,txt2,txt3,txt4,txt5,txt6,txt7,txt8,txt9,txt10 ,txt11,txt12,txt13,txt14,txtNo;
static JTextArea ta;
JButton btnAsc, btnDes;
public Insertion()
{
super("Insertion");
Container contain = getContentPane();
JPanel topPanel = new JPanel();
contain.add(topPanel,BorderLayout.NORTH);
topPanel.setLayout(new GridLayout(7,1));
JPanel middlePanel = new JPanel();
contain.add(middlePanel,BorderLayout.CENTER);
middlePanel.setLayout(new GridLayout(3,5));
JPanel bottomPanel = new JPanel();
contain.add(bottomPanel,BorderLayout.SOUTH);
bottomPanel.setLayout(new GridLayout(2,1));
lb1 = new JLabel("Data Structure: Array");
lb2 = new JLabel("Sorting Algorithm: Insertion Sort");
lb3 = new JLabel("Order :");
lb4 = new JLabel("Numbers Read In:");
lb5= new JLabel("Input Sequence:");
lb6 = new JLabel("Sorted Sequence:");
txt1 = new JTextField(3);
txt2 = new JTextField(3);
txt3 = new JTextField(3);
txt4 = new JTextField(3);
txt5 = new JTextField(3);
txt6 = new JTextField(3);
txt7 = new JTextField(3);
txt8 = new JTextField(3);
txt9 = new JTextField(3);
txt10 = new JTextField(3);
txt11 = new JTextField(3);
txt12 = new JTextField(3);
txt13 = new JTextField(3);
txt14 = new JTextField(3);
ta = new JTextArea(3,20);
txtNo = new JTextField(2);
txtNo.setEditable(false);
btnAsc = new JButton("Ascending");
btnAsc.setPreferredSize(new Dimension(100,35));
btnAsc.addActionListener(this);
btnDes = new JButton("Descending");
btnDes.addActionListener(this);
topPanel.add(lb1);
topPanel.add(lb2);
topPanel.add(lb3);
topPanel.add(btnAsc);
topPanel.add(btnDes);
topPanel.add(lb4);
topPanel.add(txtNo);
middlePanel.add(lb5);
middlePanel.add(txt1);
middlePanel.add(txt2);
middlePanel.add(txt3);
middlePanel.add(txt4);
middlePanel.add(txt5);
middlePanel.add(txt6);
middlePanel.add(txt7);
middlePanel.add(txt8);
middlePanel.add(txt9);
middlePanel.add(txt10);
middlePanel.add(txt11);
middlePanel.add(txt12);
middlePanel.add(txt13);
middlePanel.add(txt14);
bottomPanel.add(lb6);
bottomPanel.add(ta);
setSize(700,500);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
int a=new Integer(txt1.getText()).intValue();
int b=new Integer(txt2.getText()).intValue();
int c=new Integer(txt3.getText()).intValue();
int d=new Integer(txt4.getText()).intValue();
int o=new Integer(txt5.getText()).intValue();
int f=new Integer(txt6.getText()).intValue();
int g=new Integer(txt7.getText()).intValue();
int h=new Integer(txt8.getText()).intValue();
int i=new Integer(txt9.getText()).intValue();
int j=new Integer(txt10.getText()).intValue();
int k=new Integer(txt11.getText()).intValue();
int l=new Integer(txt12.getText()).intValue();
int m=new Integer(txt13.getText()).intValue();
int n=new Integer(txt14.getText()).intValue();
int [] tsnom = {a,b,c,d,o,f,g,h,i,j,k,l,m,n};
if(e.getSource()==btnAsc)
{
insertionSort(tsnom);
ta.setText(toString(tsnom));
}
if(e.getSource()==btnDes)
{
insertionSort1(tsnom);
ta.setText(toString(tsnom));
}
}
public static void insertionSort (int[] ts){
for (int x=1; x < ts.length; x++)
{
int temp=ts[x];
int y=x;
while(y>0 && temp<ts[y-1]){
ts[y]=ts[y-1];
y--;
}
ts[y]=temp;
}
System.out.println(ts.length);
txtNo.setText(""+ts.length+"");
}
public static void insertionSort1 (int[] ts){
for (int x=1; x < ts.length; x++)
{
int temp=ts[x];
int y=x;
while(y>0 && temp>ts[y-1]){
ts[y]=ts[y-1];
y--;
}
ts[y]=temp;
}
System.out.println(ts.length);
txtNo.setText(""+ts.length+"");
}
public String toString(int[] ts)
{
String str="";
for(int i=0;i<ts.length;i++)
{
str=str+ts[i]+"\t";
}
return str;
}
public static void main(String[] args)
{
Insertion Lab = new Insertion();
Lab.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;
}
}
|
|

November 7th, 2007, 04:25 AM
|
|
Authorized User
|
|
Join Date: May 2007
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Research....
can u try to tell more abt ur qn?
http://studyjava.org/forums/
|
|

November 8th, 2007, 09:02 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
It looks good to me!
You could use a single text field for the number input.
Alternatively you could use an array to hold the input text fields (which would save some typing) You also probably want to catch Numberformatexceptions and do something about them.
If you didn't want to write your own sort you could use Arrays sort http://java.sun.com/j2se/1.4.2/docs/api/java/util/Arrays.html#sort(int[])
--
Charlie Harvey's website - linux, perl, java, anarchism and punk rock: http://charlieharvey.org.uk
|
|
 |