لعبة المزرعة السعيدة لعبة الفراخ
‏إظهار الرسائل ذات التسميات امثلة جافا. إظهار كافة الرسائل

جافا : GUI من ابداعات الطالبة الاء غانم .. برنامج للتحويل من النظام العشري الى الثنائي

import java.awt.GridLayout;
import java.awt.event.*;
import javax.swing.*;

public class MyDecimalToBinary extends JFrame implements ActionListener{
JPanel myPanel ;
JTextField number ; 
JLabel r ;
JLabel result ;
JButton bin ;

public MyDecimalToBinary(){
myPanel = new JPanel(new GridLayout(4 ,2, 20 ,0 ));
number = new JTextField(10);
bin = new JButton("bin");

r = new JLabel(" Enter a number : ");
result = new JLabel("decimal to bin = ");
bin.addActionListener(this);
myPanel.add(r);
myPanel.add(number);
myPanel.add(result);
myPanel.add(bin);
this.add(myPanel);

}
public static void main(String[] args) {
MyDecimalToBinary first=new MyDecimalToBinary();
first.setTitle("Decimal to Binary");
first.setSize(300,200);
first.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
first.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent event) {
if( event.getSource() == bin){
int decimal =Integer.parseInt(number.getText()) ;
String bin="";
while(decimal!=0){
bin=decimal%2+bin;
decimal/=2;
}
result.setText(""+bin);
}
}

}
شاهد الموضوع

java : two dimentional multiple choice check

public class Shosmo{
public static void score(char [ ] [ ] in){
char [] key ={'A','B','C','D','E','F'};
int count =0;
for (int i=0;i<in.length;i++){
for (int j=0;j<in[i].length;j++)
if (in[i][j]==key[j])count++;
System.out.println("for student "+i+" = "+count);
count=0;
}
}
public static void main (String [ ] إمتحان){
char [][] ans={{'A','C','A','C','B','D'},
    {'E','A','F','A','B','F'},
    {'F','F','F','F','C','A'},
    {'A','B','A','F','B','A'},
    {'E','F','E','A','B','C'},
    {'A','A','A','A','A','A'}
              };
    score(ans);
}
}
شاهد الموضوع

جافا: GUI برنامج للتحويل من ثنائي الى عشري من ابداعات الطالبة المتميزة الاء غانم

import java.awt.GridLayout;
import java.awt.event.*;
import javax.swing.*;

public class Binarytodecimal {
public static class MyBinaryToDecimal extends JFrame implements ActionListener{
JPanel myPanel ;
JTextField number ; 
JLabel r ;
JLabel result ;
JButton decimal ;

public MyBinaryToDecimal(){
myPanel = new JPanel(new GridLayout(4 ,2, 20 ,0 ));
number = new JTextField(10);
decimal = new JButton("dicemal");

r = new JLabel(" Enter a number : ");
result = new JLabel("binary to decimal = ");
decimal.addActionListener(this);
myPanel.add(r);
myPanel.add(number);
myPanel.add(result);
myPanel.add(decimal);
this.add(myPanel);

}
public static void main(String[] args) {
MyBinaryToDecimal first=new MyBinaryToDecimal();
first.setTitle("binary to decimal");
first.setSize(300,200);
first.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
first.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent event) {
if( event.getSource() == decimal){
int n = Integer.parseInt(number.getText()) ;
String decimal=""; int p=1; int s=0;
while(n > 0){
s=s+((n%10)*p);

p=p*2;
n/=10;
}
result.setText(""+s);
}
}
}
}

شاهد الموضوع

جافا : GUI برنامج لحساب الجمع والطرح والضرب من اعداد الطالبة المبدعة داليا قلالوة

import java.awt.GridLayout;

import java.awt.event.*;
import javax.swing.*;

public class MyGUI {
public static class GUI extends JFrame implements ActionListener{
JPanel myPanel;
JTextField number1 ; 
JTextField number2 ;
JLabel n1 ;
JLabel n2 ;

JLabel result ;
JLabel r ;
JButton add ;
JButton sub ;
JButton Mul;



public GUI(){

myPanel = new JPanel(new GridLayout(5 ,2, 20 ,20 ));
number1 = new JTextField(10);
number2 = new JTextField(10);
sub = new JButton("-");
add = new JButton("+");
Mul=new JButton("*");
result = new JLabel();
n1 = new JLabel("First number : ");
n2 = new JLabel("Second Number : ");
r = new JLabel("Result = ");
add.addActionListener(this);
sub.addActionListener(this);
Mul.addActionListener(this);

myPanel.add(n1);
myPanel.add(number1);
myPanel.add(n2);
myPanel.add(number2);
myPanel.add(r);
myPanel.add(result);

myPanel.add(add);
myPanel.add(sub);
myPanel.add(Mul);
this.add(myPanel);

}

public static void main(String[] args) {
GUI frame=new GUI();
frame.setTitle("Calculate");
frame.setSize(300,200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

@Override
public void actionPerformed(ActionEvent event) {
if(event.getSource()==add){
int num1=Integer.parseInt(number1.getText());
int num2=Integer.parseInt(number2.getText());
int sum=num1+num2;
result.setText(""+sum);
}
if(event.getSource()==sub){
int num1=Integer.parseInt(number1.getText());
int num2=Integer.parseInt(number2.getText());
int sub=num1-num2;
result.setText(""+sub);
}
if(event.getSource()==Mul){
int num1=Integer.parseInt(number1.getText());
int num2=Integer.parseInt(number2.getText());
int Mul=num1*num2;

result.setText(""+Mul);
}

}
}
}

شاهد الموضوع

جافا : GUI برنامج للتحويل من سلسيوس لفهرنهايت اعداد الطالبة المبدعة سارة الغول

import java.awt.GridLayout;
import java.awt.event.*;
import javax.swing.*;
/**
*
* @author hp
*/
public class CtoF {
int num1 = 0;
JFrame frame;
JPanel panel;
JTextField text;
JLabel label;
JButton conv;
CtoF (){
frame = new JFrame();
GridLayout a = new GridLayout(3 ,2,10,10);
panel = new JPanel(a);
text = new JTextField();
conv = new JButton("convert");
label = new JLabel();

conv.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e)
{
num1=Integer.parseInt(text.getText());
label.setText(Integer.toString((int) (num1*1.8 +32)));
}}
);
panel.add(text);
panel.add(conv);
panel.add(label);
frame.setTitle("Converting from C to F");
frame.add(panel);
frame.setSize(300,200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setVisible(true);
}
public static void main(String[] args) {
new CtoF ();
}
}

شاهد الموضوع

جافا : GUI برنامج ايجاد مساحة الدائرة ... اعداد الطالبة آلاء غانم

import java.awt.GridLayout;
import java.awt.event.*;

import javax.swing.*;
public class Areacircle {

public static class MyareaCircle extends JFrame implements ActionListener{
JPanel myPanel ;
JTextField radius ; 
JLabel r ;
JLabel area ;

JLabel result ;
JButton click ;

public MyareaCircle(){
myPanel = new JPanel(new GridLayout(4 ,2, 20 ,0 ));
radius = new JTextField(10);
click = new JButton("click");
area = new JLabel();
r = new JLabel(" Enter radius : ");
result = new JLabel(" Area = ");
click.addActionListener(this);

myPanel.add(r);
myPanel.add(radius);
myPanel.add(result);
myPanel.add(area);
myPanel.add(click);
this.add(myPanel);

}

public static void main(String[] args) {
MyareaCircle first=new MyareaCircle();
first.setTitle("areaCircle");
first.setSize(300,200);
first.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
first.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent event) {
if( event.getSource() == click){
double r1 = Double.parseDouble(radius.getText()) ;
double a = r1 * r1 * 3.14;
area.setText(""+a);
}
}
}
}
شاهد الموضوع

JAVA GUI : برنامج لايجاد ناتج الطرح او الضرب لعددين (اعداد الطالبة نغم عبده ^^)


____________________________________________________________
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
*
* @author Abdo
*/
public class NewClass {
int num1 = 0;
int num2 = 0;
JFrame frame;
JPanel panel;
JTextField text;
JTextField text1;
JLabel label;
JButton sub;
JButton mult;

NewClass (){
frame = new JFrame();
GridLayout a = new GridLayout(3 ,2,18,18);
panel = new JPanel(a);
text = new JTextField();
text1 = new JTextField();
sub = new JButton("-");
mult = new JButton("X");
label = new JLabel();
label.setText(Integer.toString(num1-num2));

sub.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
num1=Integer.parseInt(text.getText());
num2=Integer.parseInt(text1.getText());

label.setText(Integer.toString(num1-num2));
}}
);

mult.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
num1=Integer.parseInt(text.getText());
num2=Integer.parseInt(text1.getText());

label.setText(Integer.toString(num1*num2));
}}
);

panel.add(text);
panel.add(text1);

panel.add(sub);
panel.add(mult);
panel.add(label);
frame.setTitle("sub & multi");
frame.add(panel);
frame.setSize(300,200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setVisible(true);

}
public static void main(String[] args) {

new NewClass ();
}
}
شاهد الموضوع

JAVA GUI : برنامج لحساب المضروب


_______________________________________________


import java.awt.GridLayout;
import java.awt.event.*;
import javax.swing.*;

public class Factorial extends JFrame implements ActionListener{
JTextField number;
JButton press;
JLabel Result;
JPanel myPanel;

public Factorial(){
myPanel = new JPanel(new GridLayout(3 ,1, 20 ,0 ));
number = new JTextField(10);

myPanel=new JPanel();
number=new JTextField(10);
press=new JButton("press");
Result=new JLabel(" ");

press.addActionListener(this);
myPanel.add(number);
myPanel.add(press);
myPanel.add(Result);
this.add(myPanel);

public static void main(String[]args){
Factorial fact=new Factorial();
fact.setTitle("Factorial");
fact.setSize(300,100);
fact.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fact.setVisible(true);
}

@Override
public void actionPerformed(ActionEvent event) {
if(event.getSource()==press){
int num = Integer.parseInt(number.getText()) ; 
int fact=1;
for(int i=1;i<=num;i++)
fact*=i;
Result.setText(""+fact);
}

}

}

شاهد الموضوع

جافا : طريقة بسيطة للطباعة في ملف txt

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

public class BN {
public static void main (String []a ){
File file ;
FileWriter writer;   
BufferedWriter output;
try {
         file= new File("text.txt");
         writer= new FileWriter(file);
         output = new BufferedWriter(writer);
         output.write("Welcome to Enjaz Blog ");         
         output.newLine();
         output.write("Enjoy with Enjaz ;) ");
         output.close();
       } catch (Exception e ) {
       }

}
}
ملاحظة
بامكانك انشاء ملف في الموقع الذي تريده مكان text.txt  وفي حال كان هنالك ملف مطابق له يقوم بمسح البيانات السابقة في ذلك الملف وطباعة النص الذي تريده مكان البيانات السابقة

شاهد الموضوع

جافا : طريقة بسيطة لطباعة محتويات ملف txt

import java.io.File;
import java.util.Scanner;


public class BN {
public static void main (String []a ){
File in =new File("text.txt");
Scanner x ;
try{
x = new Scanner (in);
while(x.hasNextLine()){
System.out.println(x.nextLine());
}
}catch (Exception z){
}
}
}

شاهد الموضوع

جافا : GUI simple calc


import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.border.Border;


public class Ca extends JPanel implements ActionListener {
    double q ;
    double w ; 
    double e ;
JFrame a;
JPanel ma;
    JPanel but;
    JPanel win;
    JPanel in;
    JButton add;
    JButton min;
    JButton mul;
    JButton div;
    JTextField in1;
    JTextField in2;
    JTextField out;
    Ca(){
Border border = BorderFactory.createLineBorder(Color.GRAY);
a = new JFrame();
ma = new JPanel(new BorderLayout());
but = new JPanel( );
win = new JPanel(new GridLayout(2,1));
add=new JButton("add");
min=new JButton("min");
mul=new JButton("mul");
div=new JButton("div");
in1 = new JTextField();
in2 = new JTextField();
out = new JTextField();
in= new JPanel(new GridLayout(2,2));
JLabel s = new JLabel("first");
JLabel d = new JLabel("second");
in1.setHorizontalAlignment(SwingConstants.CENTER);
in2.setHorizontalAlignment(SwingConstants.CENTER);
out.setHorizontalAlignment(SwingConstants.CENTER);
out.setFont(new Font("serif",Font.BOLD,20));
s.setHorizontalAlignment(SwingConstants.CENTER);
d.setHorizontalAlignment(SwingConstants.CENTER);
      s.setBorder(border);
      d.setBorder(border);
add.addActionListener(this);
min.addActionListener(this);
mul.addActionListener(this);
div.addActionListener(this);
but.add(add);
but.add(min);
but.add(mul);
but.add(div);
but.setBackground(Color.BLUE);
        in.add(s);
in.add(d);
in.add(in1);
in.add(in2);
in.setBackground(Color.CYAN);
win.add(in);
win.add(out,FlowLayout.CENTER);
ma.add(but,BorderLayout.SOUTH);
ma.add(win,BorderLayout.NORTH);
   ma.setBackground(Color.BLACK);
a.add(ma);
        a.setTitle("Simple Calc");
a.setSize(400,150);
a.setLocationRelativeTo(a);
a.setResizable(false);
a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
a.setVisible(true);
}
public static void main (String [ ] st){
new Ca();
}
public void actionPerformed(ActionEvent at) {
try{ q=Integer.parseInt(in1.getText());
w=Integer.parseInt(in2.getText());
if (at.getSource()==add)e = q+w;
else if (at.getSource()==min)e= q-w;
else if (at.getSource()==mul)e=q*w;
else if(at.getSource()==div)if(w!=0)e=q/w;else e=0;
out.setText(Double.toString(e));
}catch(Exception e){
JOptionPane.showMessageDialog(a, "Error","Error",0);
}
}}

شاهد الموضوع

java : two dimentional

اكتب برنامج بلغة جافا يقوم بانشاء مصفوفة متساوية البعدين يحدد حجمها المستخدم
ويقوم بطباعة  اعلى قيمة في الصف الاول
وطباعة اصغر قيمة في العمود الثاني 
وطباعة المصفوفة كل صف بسطر
وطباعة المصفوفة بعد استبدال الصفوف بالاعمدة والاعمدة بالصفوفة transpose 

import java.util.Scanner;


public class Transpose {
public static void main (String [] args ){
    Scanner in = new Scanner (System.in);
System.out.println("Enter the size of the array : ");
int size = in.nextInt();
int [][] a = new int [size][size];
System.out.println("Enter the elements  ");

for (int i=0;i<size;i++){
for (int j=0;j<size;j++){
a[i][j]=in.nextInt();
}
}
printMax1(a);
printMin2(a);
printMatrix(a);
printTrans(a);

}







private static void printMax1(int[][] a) {
int max = a[0][0];
for (int i=0;i<a.length;i++){
if (a[0][i]>max)max = a[0][i];
}
System.out.println("The max of the first row is  " + max);
}

private static void printMin2(int[][] a) {
int min = a[0][1];
for (int i=0;i<a.length;i++){
if (a[i][1]<min)min = a[i][1];
}
System.out.println("The min of the second column is  " + min);
}

private static void printMatrix(int[][] a) {
for (int i =0;i<a.length;i++){
for (int j =0;j<a[i].length;j++)
System.out.print(a[i][j]+" ");
System.out.println();
}
}
private static void printTrans(int[][] a) {
int r= a.length;
int c =a[0].length;
int [][] trans= new int [r][c];
for (int i=0;i<r;i++){
for (int j =0;j<c;j++)
trans[i][j]=a[j][i];
}
printMatrix(trans);
}

}


شاهد الموضوع

java : all digits odd

اكتب ميثود بلغة جافا يقوم بارجاع true اذا كان كافة خانات الرقم المدخل فردية
و false اذا كانت زوجية
مثلا 1975 true
19423 false

public static boolean check (int x ){
while (x>0){
int slice = x%10;
   if (slice%2==0)return false;
   x/=10;
}
return true;
}
شاهد الموضوع

جافا : برنامج يقارن بين مصفوفتين اذا كانتا متماثلتين ام لا

import java.util.Scanner;


public class Tryb {
public static void main (String [ ]aht){
Scanner in = new Scanner (System.in);
System.out.println("Enter the elements of the first Array");
int lengtha=in.nextInt();
int [] a = new int [lengtha];
a[0]=lengtha;
for (int i=1;i<lengtha;i++)a[i]=in.nextInt();
System.out.println("Enter the elements of the second Array");
int lengthb=in.nextInt();
int [] b = new int [lengthb];
b[0]=lengthb;
for (int i=1;i<lengthb;i++)b[i]=in.nextInt();
System.out.println("Are the the same ? " + check(lengtha,lengthb,a,b));
}

private static boolean check(int lengtha, int lengthb, int[] a, int[] b) {
if (lengtha!=lengthb)return false ;
for (int i=0;i<lengtha;i++)
if (a[i]!=b[i])return false ;
return true;
}

}

شاهد الموضوع

جافا : برنامج يولد عددين اقل من 100 بشكل عشوائي ويقارن الناتج الفعلي من الناتج من المستخدم

import java.util.Scanner;
public class Try {
public static void main (String [] ag){
Scanner in = new Scanner (System.in);
int a =method1();
int b = method1();
System.out.println("Enter the result of  " +a+"+"+b );
int input = in.nextInt();
System.out.println("Your Answer is "+method2(a,b,input));
}
private static int method1() {
int m = (int)(Math.random()*100);
return m;
}
private static boolean method2(int a , int b , int input) {
int sum = a+b;
if (input==sum)return true;
return false ;
}
}

شاهد الموضوع

جافا: مثال جافا


اكتب برنامج بلغة جافا يقوم بادخال 5 ارقام صحيحة من قبل المستخدم ويخزنها في مصفوفة 

ويقوم بنسخ عناصر المصفوفة الاصلية الى مصفوفة ثانية 
ويقوم بالعمليات التالية على المصفوفتين 
المصفوفة الاولى :- اضافة 5 على كل عنصر ثم ضربه ب2
ثم ايجاد اكبر عنصر 
المصفوفة الثانية :- طرح 3 من كل عنصر ثم ضربه بـ3 ثم ايجاد اكبر عنصر
ثم ايجاد اكبر عنصر بين المصفوفتين 

....




import java.util.Scanner;


public class Copy {
public static void main (String [] args ){
Scanner in = new Scanner (System.in);
int [ ] a= new int [5];
int [] b= new int [5];
for (int i = 0 ; i <a.length;i++)
a[i]= in.nextInt();
for (int i=0;i<a.length;i++)
   b[i]=a[i];
printArr(a);
printArr(b);
arrayFirstOp(a,5,2);
arrayFirstOp(b,-3,3);
printArr(a);
printArr(b);
int max1 = MaxArr(a);
int max2 = MaxArr(b);
int maximum=max(max1,max2);
System.out.println("max of first array : "+ max1+
"\nmax of second:  "+max2+
"\nmax of both : "+maximum);
}
/*
 * هاد الميثود عشان يطبع عناصر المصفوفة
 * **/

private static void printArr(int[] array) {
for (int x:array )System.out.print(x+" ");
System.out.println();

}

/*
 * هاد الميثود لحتى يعمل العمليات على المصفوفة
 * بستقبل المصفوفة 
 * بستقبل العدد اللي بدو يضيفو 
 * بستقبل العدد اللي بدو يضرب عناصرها فيه
 * ومن خلال فور لوب بعمل العمليات
 * **/
public static void arrayFirstOp(int [ ]a,int plus , int multiple ){
for (int i = 0 ; i< a.length;i++)
a[i]=(a[i]+plus)*multiple;
}
/*
 * يخرج قيمة اكبر عنصر بالمصفوفة
 * **/
public static int MaxArr(int [] a){
int max =a[0];
for (int x: a)
if (x>max)max=x;
return max;
}
/**
 *ايجاد اكبر قيمة بين عددين 
 * */
public static int max (int a , int b ){
if (a>b)return a;
else return b;
}

}

شاهد الموضوع

java : a method to determine whether an integer is prime or not

public static boolean isPrime(int x ){
int i=2;
while (i<=Math.sqrt(x)){
if (x%i++==0)return false;
}
return true;
}
شاهد الموضوع

java : triangle of numbers (pattern)

public static void displayPattern(int x ){
char a =' ';
for (int i=1;i<=x;i++){
for (int j=x-i;j>0;j--){
System.out.printf("%2c",a);
}
for (int k=i;k>=1;k--){
System.out.printf("%2d",k);

}0
System.out.println();
}
}
شاهد الموضوع

java : Display Reverse number

 static void  reverse (int number){
String s1=Integer.toString(number);
    String s2="";
    for (int i=s1.length()-1;i>=0;i--){
    s2+=s1.charAt(i);
    }
System.out.println(Integer.parseInt(s2));

}

شاهد الموضوع

جافا : Palindrom numbers

using two methods determine whether a number is palindrom or not
the first to find the reverse 
the second to determin is it palindrom or not


public static int reverse (int number){
String s1=Integer.toString(number);
   String s2="";
   for (int i=s1.length()-1;i>=0;i--){
    s2+=s1.charAt(i);
   }
   return Integer.parseInt(s2);

}
public static boolean isPalindrome(int number){
if (number==reverse (number))return true;
else return false ;
}

شاهد الموضوع
لعبة من سيربح المليون لعبة زوما