Dynamic Profile Codes
Would you like to react to this message? Create an account in a few clicks or log in to continue.

POST YOUR JAVA CODES EXAMPLE..

2 posters

Go down

POST YOUR JAVA CODES EXAMPLE.. Empty POST YOUR JAVA CODES EXAMPLE..

Post by jhennyz Mon Mar 08, 2010 9:13 pm

Post here some JAVA CODES you are having..

let's share our knowledge to all the IT ASPIRANTS..^^

who knows...

what u share cud be a big help for sumbody's assignment/project..


Please put the codes you're about to share inside the

[c0de][/c0de]

for an easy CTRL C CTRL V process..

and not in the SPOiLER..


and Lastly..


please SPECiFY the USE of the codes u ARE SHARiNG..
____________

staff's can removed this thread if this is not an acceptable TOPiC..

_____________

1st Code From Me:

- JAVA CODE determining the users input whether the number inputed

is an ODD or an EVEN NUMBER.


Code:
 
import java.io.*;


public class OddEven{
public static void main(String[]args)throws IOException{

BufferedReader br=new
BufferedReader(new InputStreamReader(System.in));


int num;


System.out.println("Enter a value:");
num=Integer.parseInt(br.readLine());


if (num %2==0)
{
System.out.println("the given is a number and it is EVEN");
}

else
{

System.out.println("the given is number and it is ODD");
}

}
}
jhennyz
jhennyz
DPC Addict

Female
Posts : 148
Age : 31
Joined date : 2010-03-04
Location : ~NOWHERETOFiND~
Cash : 26561

Back to top Go down

POST YOUR JAVA CODES EXAMPLE.. Empty Re: POST YOUR JAVA CODES EXAMPLE..

Post by mozaski Wed May 12, 2010 12:11 pm

JFRAME


Code:


import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collections;

import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JTextPane;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

public class NewJFrame extends javax.swing.JFrame {

private static final long serialVersionUID = 1L;
private JTextField jTextField1;
private JTextPane jTextPane1;
private JButton jButton1;
private JTextField jTextField9;
private JTextField jTextField8;
private JTextField jTextField7;
private JTextField jTextField6;
private JTextField jTextField5;
private JTextField jTextField4;
private JTextField jTextField3;
private JTextField jTextField2;

public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
NewJFrame inst = new NewJFrame();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}

public NewJFrame() {
super();
initGUI();
}

private void initGUI() {
try {
this.setPreferredSize(new java.awt.Dimension(1024, 768));
GridBagLayout thisLayout = new GridBagLayout();
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
thisLayout.rowWeights = new double[] {0.1, 0.1, 0.1, 0.1};
thisLayout.rowHeights = new int[] {7, 7, 7, 7};
thisLayout.columnWeights = new double[] {0.1, 0.1, 0.1, 0.1};
thisLayout.columnWidths = new int[] {7, 7, 7, 7};
getContentPane().setLayout(thisLayout);
{
jTextField1 = new JTextField();
getContentPane().add(jTextField1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
jTextField1.setText("1");
}
{
jTextField2 = new JTextField();
getContentPane().add(jTextField2, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
jTextField2.setText("32");
}
{
jTextField3 = new JTextField();
getContentPane().add(jTextField3, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
jTextField3.setText("354");
}
{
jTextField4 = new JTextField();
getContentPane().add(jTextField4, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
jTextField4.setText("4543");
}
{
jTextField5 = new JTextField();
getContentPane().add(jTextField5, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
jTextField5.setText("56546");
}
{
jTextField6 = new JTextField();
getContentPane().add(jTextField6, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
jTextField6.setText("6879");
}
{
jTextField7 = new JTextField();
getContentPane().add(jTextField7, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
jTextField7.setText("789");
}
{
jTextField8 = new JTextField();
getContentPane().add(jTextField8, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
jTextField8.setText("8");
}
{
jTextField9 = new JTextField();
getContentPane().add(jTextField9, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
jTextField9.setText("9");
}
{
jTextPane1 = new JTextPane();
getContentPane().add(jTextPane1, new GridBagConstraints(0, 2, 3, 2, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
jTextPane1.setText("");
}
{
jButton1 = new JButton();
getContentPane().add(jButton1, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
jButton1.setText("Sort");
jButton1.addActionListener(new ActionListener()
{
public void actionPerformed (ActionEvent e)
{

ArrayList <Integer>al = new ArrayList<Integer>();
al.add(new Integer(jTextField1.getText()));
al.add(new Integer(jTextField2.getText()));
al.add(new Integer(jTextField3.getText()));
al.add(new Integer(jTextField4.getText()));
al.add(new Integer(jTextField5.getText()));
al.add(new Integer(jTextField6.getText()));
al.add(new Integer(jTextField7.getText()));
al.add(new Integer(jTextField8.getText()));
al.add(new Integer(jTextField9.getText()));

Collections.sort(al);
java.util.Iterator<Integer> dogsBum = al.iterator();
String s="";
while (dogsBum.hasNext()) {
s+= dogsBum.next().toString()+"\n";
}

jTextPane1.setText(s);
}
});
}
pack();
} catch (Exception e) {
e.printStackTrace();
}
}


}

mozaski
mozaski
Guest

Male
Posts : 7
Joined date : 2010-05-12
Location : C:\windows\system32
Cash : 25566

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum