A very simple program to find whether a number is odd or even. As we have taken 4 to check whether it is even or not. It is even because when we divide it by 2 then the reminder will be 0.
class Evenodd
{
public static void main(String args[])
{
int a = 4;
if((a % 2) == 0)
System.out.print("Number is even");
else
System.out.println("Number is odd");
}
}
Thursday, February 7, 2008
Tuesday, January 15, 2008
Java Swing Example
It is very interesting part of Java programming. It is the favorite topic of all the java programmers. We can customize the components and use it according to our requirements. Lets start with first program :
This program explain you how to create text area using Java swing. Here we are using javax.swing package to create GUI component. The text area will be created on panel in the frame :
import javax.swing.*;
public class TextAreaCode {
public static void main(String[] args){
JFrame frame= new JFrame("TextArea-Frame Program");
JPanel panel=new JPanel();
JTextArea jt= new JTextArea("TextArea Example",4,20);
frame.add(panel);
panel.add(jt);
frame.setSize(250,250);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Click Here for More example on Java Swing
Subscribe to:
Posts (Atom)