تبليغاتX
خانه ای اینترنتی برای برنامه نویسان
خانه | آرشیو | پست الکترونیک
یک برنامه فرهنگ لغت انگلیسی به فارسی به زبان (java)

import java.awt.*;
import java.io.*;
import java.awt.event.*;
public class MyClass2 extends JFrame implements ActionListener {
  boolean newRecord=false;
  boolean find,show;

  JLabel lbl1=new JLabel("english");
  JLabel lbl2=new JLabel("farsi");
  JLabel lbl3 = new JLabel("");
  JLabel lbl4 = new JLabel("");
  JLabel lbl5 = new JLabel("");
  JTextField tf1=new JTextField();
  JTextField tf2=new JTextField();
  JButton btn1=new JButton("add");
  JButton btn2=new JButton("save");
  JButton btn3=new JButton("next");
  JButton btn4=new JButton("prev");
  JButton btn5=new JButton("exit");
  JButton btn6=new JButton("delete");
  JButton btn7=new JButton("search");

  final int SIZE=300;

  RandomAccessFile f;

  long count;
  long index=0;

  public MyClass2(){
    setLayout(null);

    lbl1.setBounds(10,10,100,20);
    lbl2.setBounds(10,30,100,20);
    lbl3.setBounds(170,130,100,20);
    lbl4.setBounds(100,140,100,20);
    lbl5.setBounds(20,140,100,20);
    tf1.setBounds(110,10,100,20);
    tf2.setBounds(110,30,100,20);
    btn1.setBounds(10,60,80,20);
    btn2.setBounds(100,60,80,20);
    btn3.setBounds(10,85,80,20);
    btn4.setBounds(100,85,80,20);
    btn5.setBounds(10,110,80,20);
    btn6.setBounds(100,110,80,20);
    btn7.setBounds(190,60,80,20);

    add(lbl1);
    add(lbl2);
    add(lbl3);
    add(lbl4);
    add(lbl5);
    add(tf1);
    add(tf2);
    add(btn1);
    add(btn2);
    add(btn3);
    add(btn4);
    add(btn5);
    add(btn6);
    add(btn7);


    btn1.addActionListener(this);
    btn2.addActionListener(this);
    btn3.addActionListener(this);
    btn4.addActionListener(this);
    btn5.addActionListener(this);
    btn6.addActionListener(this);
    btn7.addActionListener(this);

    setVisible(true);
    setSize(300,200);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    try{
      f=new RandomAccessFile("test.txt","rw");
      count=f.readLong();
    }
    catch(Exception exc){
    }
    index=1;
    if(count>0) readRecord();
      else newRecord=true;
        validate();
    }

    public void actionPerformed(ActionEvent event){
      if(event.getSource()==btn1){
        index=count+1;
        newRecord=true;
        tf1.setText("") ;
        tf2.setText("");
      }
      if(event.getSource()==btn2){
        if(tf2.getText().length()>50){
          JOptionPane.showMessageDialog(null,"english is not found.");
          return;
        }
        if(tf2.getText().length()>50){
          JOptionPane.showMessageDialog(null,"farsi is not found.");
          return;
        }
        writeRecord();
        if(newRecord)count+=1;
        newRecord=false;
      }
        if(event.getSource()==btn3){
          if (index < count) {
            index = index + 1;
            readRecord();
          }
          else
           JOptionPane.showMessageDialog(null,"Last Record");
        }
        if(event.getSource()==btn4){
          if(index>1){
            index=index - 1;
            readRecord();
         }
         else
           JOptionPane.showMessageDialog(null,"First Record");
        }
        if(event.getSource()==btn5){
          exit();
        }
       if(event.getSource()==btn6){
         delete();
       }

   if(event.getSource()==btn7){
     search();
   }
 }

   public void exit(){
         try{
           f.seek(0);
           f.writeLong(count);
           f.close();
           System.exit(0);
         }
         catch(IOException exc){
           System.out.println(exc.getMessage());
         }
       }

       public void writeRecord(){
         try{
           String english,farsi;
           english=tf1.getText();
           farsi=tf2.getText();
           long loc=index * SIZE;
           f.seek(loc);
           f.writeUTF(english);
           f.writeUTF(farsi);
           f.writeBoolean(true);
           f.seek(0);
           f.writeLong(count+1) ;
         }
         catch(Exception exc){
         }
        }

        public void search(){
          String temp=JOptionPane.showInputDialog("Enter word to search");
          try {
            f.seek(0);
            long len =f.readLong() ;
            find=false;
            index=1;
          while ((index<=len)&&(find==false)){
             readRecord();
              if (tf1.getText().equalsIgnoreCase(temp) &&(show==true)){
                 find=true;
              }else{
                index = index + 1;
          }

            }
          } catch(Exception exc){}
        }
        public void readRecord(){
          try{
            long loc;
            loc=index*SIZE;
            f.seek(loc);
            String english,farsi;
            english=f.readUTF();
            farsi=f.readUTF();
            show=f.readBoolean() ;
            tf1.setText(english);
            tf2.setText(farsi);
          }
          catch (Exception exc){
          }
        }
        public void delete(){
          try {
            f.seek(index * SIZE);
            f.writeUTF("   ");
            f.writeUTF("    ");
            f.writeBoolean(false);
          }
          catch (IOException ex) {
          }

        }
        public static void main(String[] args){
          MyClass2 app=new MyClass2();
        }
        }

|+| نوشته شده توسط محمد رضا ابراهیمی در دوشنبه بیست و سوم بهمن 1385 و ساعت 22:45 | 
برنامه رسم شکل های گرافیکی (java)

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.Color;
public class MainClass extends JFrame implements ActionListener {
  String[] names={"blue","black","red","yellow"};
  String[] paint={"Rect","Oval","Line","Arc"};
  Color[] colors={Color.blue,Color.black,Color.red,Color.yellow};

  JCheckBox ch1=new JCheckBox();
  JLabel lbl1=new JLabel("width");
  JLabel lbl2=new JLabel("height");
  JLabel lbl3=new JLabel("color");
  JLabel lbl4=new JLabel("start");
  JLabel lbl5=new JLabel("zaviye");
  JLabel lbl6=new JLabel("paint");
  JLabel lbl7= new JLabel("fill");
  JLabel lbl8 = new JLabel(" :");
  JLabel lbl9 = new JLabel("");
  JLabel lbl10 = new JLabel("");
  JTextField tf1=new JTextField();
  JTextField tf2=new JTextField();
  JTextField tf3=new JTextField();
  JTextField tf4=new JTextField();
  JComboBox cb1=new JComboBox(names);
  JComboBox cb2=new JComboBox(paint);
  JButton btn1=new JButton("draw");
  JButton btn2=new JButton("exit");
  JButton btn3=new JButton("clear");
  JPanel pnl=new JPanel();
  int width,height;
Graphics g;
  public MainClass(){

    setLayout(null);
    ch1.setBounds(100,100,100,20);
    lbl1.setBounds(10,10,100,20);
    lbl2.setBounds(10,30,100,20);
    lbl3.setBounds(10,50,100,20);
    lbl4.setBounds(200,10,100,20);
    lbl5.setBounds(200,30,100,20);
    lbl6.setBounds(10,75,100,20);
    lbl7.setBounds(75,100,100,20);
    lbl8.setBounds(450,10,100,20);
    lbl9.setBounds(350,20,100,20);
    lbl10.setBounds(270,30,100,20);
    tf1.setBounds(100,10,100,20);
    tf2.setBounds(100,30,100,20);
    tf3.setBounds(250,10,100,20);
    tf4.setBounds(250,30,100,20);
    cb1.setBounds(100,50,100,20);
    cb2.setBounds(100,75,100,20);
    btn1.setBounds(30,130,100,20);
    btn3.setBounds(30,150,100,20);
    btn2.setBounds(30,170,100,20);

    add(ch1);
    add(lbl1);
    add(lbl2);
    add(lbl3);
    add(lbl4);
    add(lbl5);
    add(lbl6);
    add(lbl7);
    add(lbl8);
    add(lbl9);
    add(lbl10);
    add(tf1);
    add(tf2);
    add(tf3);
    add(tf4);
    add(cb1);
    add(cb2);
    add(btn1);
    add(btn2);
    add(btn3);

    lbl4.setVisible(false);
    lbl5.setVisible(false);
    tf3.setVisible(false);
    tf4.setVisible(false);

    btn1.addActionListener(this);
    btn2.addActionListener(this);
    btn3.addActionListener(this);

    pnl.setBounds(250,60,400,400);
    add(pnl);
    pnl.setBackground(Color.CYAN);

    setSize(700,500);
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }

 public void Rect(){
    Graphics g;
    g=pnl.getGraphics();
    lbl4.setVisible(false);
    lbl5.setVisible(false);
    tf3.setVisible(false);
    tf4.setVisible(false);

  if(cb2.getSelectedIndex() ==0){
    if (ch1.isSelected()) {
        g.fillRect(20,30, width, height);
     }
     else {
        g.drawRect(20,30, width, height);
     }
   }
 }
 public void Oval(){
    Graphics g;
    g=pnl.getGraphics();
    lbl4.setVisible(false);
    lbl5.setVisible(false);
    tf3.setVisible(false);
    tf4.setVisible(false);

   if(ch1.isSelected()){
      g.fillOval(20,30,width,height);
   }
   else{
     g.drawOval(20,30,width,height) ;
   }
 }
 public void Line(){
    Graphics g;
    g=pnl.getGraphics();
    lbl4.setVisible(false);
    lbl5.setVisible(false);
    tf3.setVisible(false);
    tf4.setVisible(false);

    g.drawLine(20,30,width,height);
 }
 public void Arc(){
    int start,zaviye;
    lbl4.setVisible(true);
    lbl5.setVisible(true);
    tf3.setVisible(true);
    tf4.setVisible(true);
    start=Integer.parseInt(tf3.getText());
    zaviye=Integer.parseInt(tf4.getText());
    Graphics g;
    g=pnl.getGraphics();
    g.drawArc(20,30,width,height,start,zaviye) ;
 }
  public void draw(){
    Graphics g;
    g=pnl.getGraphics();
    width=Integer.parseInt(tf1.getText());
    height=Integer.parseInt(tf2.getText());
    Color c;
    c=colors[cb1.getSelectedIndex()];
    g.setColor(c);

   if (cb2.getSelectedIndex() ==0){
       Rect();
      }
   if(cb2.getSelectedIndex() ==1){
      Oval();
   }
   if(cb2.getSelectedIndex() ==2){
      Line();
   }
   if(cb2.getSelectedIndex() ==3){
     JOptionPane.showMessageDialog(null,"مختصات نقطه شروع و زاويه را نيز وارد كنيد");
        Arc();
          }
  }//draw

  public void clear(){
     pnl.repaint();
  }

  public void actionPerformed(ActionEvent event){
    if(event.getSource()==btn1){
      draw();
    }
    if(event.getSource()==btn2){
      System.exit(0);
    }
    if(event.getSource()==btn3){
      clear();
    }
  }

  public static void main(String args[]){
    MainClass app=new MainClass();
  }
 }

|+| نوشته شده توسط محمد رضا ابراهیمی در دوشنبه بیست و سوم بهمن 1385 و ساعت 22:44 | 
سورس نرم افزار دیکشنری به زبان ++c
برنامه زیر دارای یک سری اشکالات می باشد ابتدا سعی کنید خودتان متوجه شوید و ایردات آنرا رفع نمائید در صورتی که نتوانستید در قسمت نظر بدهید پیام بگذارید تا کامل آنرا برایتان ارسال کنم.

#include
#include
#include
#include
#include
struct dictionary {
   char english[30] ;
   char farsi[30] ;
   struct dictionary *next ;
} list_entry ;

struct dictionary *start ;
struct dictionary *last ;

void enter() , display() , search() ;
void save()  , load()    , list() , del();
void display(struct dictionary *info, int *row);

int menu_select();
struct dictionary *store(struct dictionary *, struct dictionary *);

int main ()
{
   start = last = NULL ;
   for(;;) {
   switch(menu_select()) {
    case 1:  enter();  break ;
    case 2 : del();    break ;
    case 3:  list() ;  break ;
    case 4:  search(); break ;
    case 5:  save();   break ;
    case 6:  load();   break ;
    case 7:  exit(0) ;
   }
   }
}
//****************
int menu_select()
{
  char s[5];
  clrscr() ;
  gotoxy(10,2);
  gotoxy(25, 4) ;
  printf("1. add a word ");
  gotoxy(25, 6) ;
  printf("2. delete a word  ") ;
  gotoxy(25, 8) ;
  printf("3. list all files ") ;
  gotoxy(25, 10) ;
  printf("4. search a  word ") ;
  gotoxy(25, 12) ;
  printf("5. save the file  ") ;
  gotoxy(25, 14) ;
  printf("6. load the file  ") ;
  gotoxy(25, 16) ;
  printf("7. quit ") ;
  do {
   gotoxy(20, 18) ;
   printf("enter your select(1-7):");
   gets(s);
  } while (atoi(s) < 0 || atoi(s) > 7) ;
  return atoi(s) ;
}
//*********************
void enter ()
{
 struct dictionary *info ;
 int i ;
 char ch ;
 clrscr() ;
 gotoxy(3, 2) ;
 printf("   english        farsi     ");
 gotoxy(3, 3) ;
 printf(" ------------ -------- ");
 i = 4 ;
 for (;;) {
   info = (struct dictionary *)malloc(sizeof(list_entry)) ;
   if(!info) {
 printf("\n out of memory. press a key ") ;
 getch();
 return ;
   }
   gotoxy(3, i) ;
    gotoxy(15, i + 1) ;
   printf("press a key to continue");
   getch() ;
   break ;
   }
   gotoxy(18, i);
   gets(info -> farsi) ;
   i++ ;
   start = store(info, start) ;
   }
 }
//**************
struct dictionary *store(struct dictionary *i, struct dictionary *top)
{
 struct dictionary *old, *p ;
 if(last == NULL) {
 i -> next = NULL ;
 i -> prior = NULL ;
 start = i;
 last = i ;
 return i ;
 }
 p = top ;
 old = NULL ;
 while (p != NULL) {
   if(strcmp(p -> english, i -> english) < 0) {
   old = p ;
   p = p -> next ;
   }
   else {
    if (p -> prior) {
    p -> prior -> next=i ;
    i -> next=p ;
    p -> prior=i ;
    return top ;
    }
    i -> next = p ;
    i -> prior = NULL ;
    p -> prior = i ;
    return i ;
   }
 }
 old -> next = i ;
 i -> next = NULL ;
 i -> prior = old ;
 last = i ;
 return start ;
}
//******************
void del()
{
 struct dictionary *info;
 char english[80];
 gotoxy(20, 20) ;
 printf(" enter word for delete : ") ;
 gets(english) ;
 info = find(english) ;
 if(info == NULL) {
   gotoxy(10, 20) ;
   printf(" word not found! press a key ");
   getch() ;
 }
 if (info)
   if (start == info)
 {
   start = info -> next ;
   if(start)
    start -> prior = NULL ;
   else
    last = NULL ;
 }
   else  {
  info -> prior -> next = info -> next;
  if(info != last)
   info -> next -> prior = info -> prior;
  else
  last = info -> prior ;
   }
   free(info) ;
   gotoxy(10,20) ;
   printf("word deleted, press a key ");
   getch() ;
}
//*******************************
struct dictionary *find(char *english)
{
   struct dictionary *info ;
   info = start ;
   while(info != NULL) {
 if (strcmp(english, info -> english) == 0)
  return info;
 info = info -> next ;
   }
   return NULL ;
}
//*****************
void list ()
{
  struct dictionary *info ;
  int i ;
  info = start ;
  clrscr() ;
  gotoxy(3, 2) ;
  printf("   english       farsi ");
  gotoxy(3, 3) ;
  printf(" ------------ --------  -");
  i = 4 ;
  while(info != NULL) {
 display(info, &i) ;
 info = info -> next ;
  }
  gotoxy(15, i + 2) ;
  printf("press a key ");
  getch() ;
}
//*******************
void display(struct dictionary *info, int *row)
{
   gotoxy(3, *row) ;
   printf("%s", info -> english) ;
   gotoxy(18, *row) ;
   printf("%s", info -> farsi) ;
   *row = *row + 1 ;
}
//**************************
void search()
{
   char english[40];
   int i ;
   struct dictionary  *info;
   gotoxy(20, 20) ;
   printf(" enter word to find : ");
   gets(english) ;
   info  = find(english) ;
   if(info == NULL) {
   gotoxy(10, 20) ;
   printf(" word not found! press a key ");
   getch() ;
   }
    else  {
   clrscr() ;
   gotoxy(3, 2) ;
   printf("   english       farsi   ");
   gotoxy(3, 3) ;
   printf(" ------------ -------");
   i = 4 ;
   display(info ,&i) ;
   gotoxy(15, i + 2) ;
   printf("press a key ");
   getch() ;
   }
}
//*********************
void save()
{
  struct dictionary *info ;
  FILE *fp ;
  if((fp = fopen("d.dat","wb")) == NULL)  {
  printf("\n cannot open file. ") ;
  getch();
  exit(1) ;
  }
  gotoxy(20, 20) ;
  printf("<< saving file >>") ;
  info = start ;
  while(info) {
  fwrite(info, sizeof(struct dictionary), 1, fp);
  info = info -> next ;
  }
  fclose(fp) ;
  gotoxy(15, 22) ;
  printf("file saved press a key") ;
  getch() ;
}
//********************
void load ()
{
  struct dictionary *info , *temp = NULL;
  FILE *fp ;
  fp = fopen("d.dat","rb") ;
  if(fp == NULL)  {
 printf("\n cannot open file.");
 getch();
 exit(1) ;
  }
  while(start) {
  info = start -> next ;
  free(info) ;
  start = info ;
  }
  gotoxy(20,20) ;
  printf(" << loading file  >> ") ;
  start = NULL ;
  while (!feof(fp)) {
   info = (struct dictionary *)
  malloc(sizeof(struct dictionary)) ;
   if(1 != fread(info, sizeof(struct dictionary), 1, fp))
   break ;
   if(start == NULL)  {
   temp = start = info ;
   info -> prior = NULL ;
   
   }
   else  {
   info -> next = NULL ;
   temp -> next = info ;
   temp = info;
   }
  }
  last = temp ;
  fclose(fp) ;
  gotoxy(15,22) ;
  printf("file loaded press a key ") ;
  getch();
}


|+| نوشته شده توسط محمد رضا ابراهیمی در دوشنبه بیست و سوم بهمن 1385 و ساعت 22:24 | 
آشنایی با ویژوال بیسیک 6
تاریخچه ویژال بیسیک.
با شناختی که از تاریخچه ویژوال بیسیک بدست می آورید راحت تر می توانید از آن استفاده کنید.
شرکت مایکروسافت ویژوال بیسیک را براساس یک زبان برنامه نویسی به نام بیسیک که برای مبتدیان نوشته شده است ساخت.
زبان ویژوال بیسیک بیشتر از 35 سال به اشکال مختلف رایج بوده. در واقع طراحان این زبان می خواستند یک زبان برنامه نویسی برای استفاده مبتدیان طراحی کنند.برنامه نویسان جدید می توانند با استفاده ازبیسیک به سرعت به شرع برنامه نویسی های حرفه ای با زبان های cobol .fortran . assembler
در مقایسه به بیسیک کار بیشتری نیاز داشت.
طبیعت بصری ویژوال بیسیک
دیدید که ویژال بیسیک 6 چیزی بیشتر از یک زبان برنامه نویسی است. از ویژوال بیسیک در نام آن visualبه معنای بصری یا محیط نمایشی . است.
کار با ویژال بیسیک 6
در اولین بار که برنامه را باز می کنید با پنجره new project روبه رو می شوید در این قسمت
نوع فورم خود را انتخاب کرده ماننده activex|standardو....
این پنجره شامل 3 قسمت بوده
New:در این پنجره امکان انتخاب فورم مورد نظر شما امکان پذیر می باشد.
Existing:در این پنجره امکان انتخاب project های مختلف که در مکانهای مختلف ذخیره یا... امکان انتخاب می باشد.
Recent:در این قسمت هر projectرا که ذخیره می کنید به صورت دسته ای جمع می شود حالا یک فایلی
در درایو Dباشد حالا چه در درایو c.
DON.T SHOW THIS DIALOG IN THE FUTURE
این قسمت جلو گیری از باز شدن پینجره NEW PRIJECT می باشد.
HELP:از این قسمت وقتی امکان استفاده می باشد که نرم افزار MSDN را نصب کرده باشید.
معرفی قسمت های بیسیک.
نوار ابزار:TOOLBAR:نوار ابزار VB زیر منو قرار دارد. ویژال بیسیک کلا چهار نوار ابزار دارد:
STANDARD:این نوار ابزار زیر منو ظارهر است و پیش فرض است.
DEBUG:وقتی از ابزارهای رفع اشکال برای ردیابی و اصلاح اشکالات استفاده می کنید. این نوار ابزار ظاهر می شود.
EDIT:این نوار ابزار برای تنظیم کردن اشیاء بر روی فرم می باشد
FORM EDITOR:این نوار ابزار برای تنظیم کردن اشیاء بر روی فرم می باشد.
جعبه ابزار:TOOLBOX:
در این پنجره تمامی شئعی های مختلف برای کار بر روی فرم هستند و حتا امکان اضافه کردن به این پنجره ها می باشد.
پنجرهPROJECT:در این پنجره فرم های انتخبی شما با هر گروه و هر فرم مشخص شده است.
پنجرهPROPERTISE:
این پنجره امکان تنضیمات لازم برای هر شیئی را مشخص می کنید
|+| نوشته شده توسط محمد رضا ابراهیمی در یکشنبه هشتم بهمن 1385 و ساعت 7:33 | 
Powered By Blogfa - Designing & Supporting Tools By WebGozar