الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

كود جافا لعمل ساعة ايقاف

مغلق
بدأه حسام محمد في 20 أبريل 2003 · 8 رد · 2,223 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

هذا الكود لعمل ساعة ايقاف وهو تطبيق مباشر على استخدام threads فى الجافا

اتمنى ان يكون به فائدة للاخوة وه ا الكوا من تطوير مجموعة طلاب من هندسة شبرا بمصر نسال الله ان يعلمنا ما ينفعنا وينفعنا بما علمنا انه ولى ذلك والقادر عليه

import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.util.*;
public class stopwatch extends JFrame implements Runnable
{
  int second,minute,hour;
  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  JButton jButton3 = new JButton();
  JTextField jTextField2 = new JTextField();
  JTextField jTextField3 = new JTextField();
  Thread t=new Thread(this);
  boolean Threadsuspend;
  JTextField jTextField1 = new JTextField();
  TitledBorder titledBorder1;
  public void run()
  {
  while(true)
  {
    try
   {

   while(Threadsuspend)
   {
    synchronized(this)
    {
     wait();
    }
   }
   second++;
    Thread.sleep(1000);
    jTextField1.setText(second+"");
    }
    catch(InterruptedException ee)
    {}
     if(second >59)
     {second=0;
     minute++;
      jTextField2.setText(minute+"");
        }
 if(minute >59)
     {minute=0;
     hour++;
      jTextField3.setText(hour+"");
        }


  }

  }

  public stopwatch() {
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  public static void main(String[] args) {
    stopwatch stopwatch1 = new stopwatch();
    stopwatch1.setSize(400,200);
    stopwatch1.setVisible(true);
  }
  private void jbInit() throws Exception {
    titledBorder1 = new TitledBorder("");
    jButton1.setBackground(SystemColor.info);
    jButton1.setBounds(new Rectangle(32, 112, 77, 40));
    jButton1.setFont(new java.awt.Font("Serif", 1, 14));
    jButton1.setForeground(Color.blue);
    jButton1.setBorder(BorderFactory.createRaisedBevelBorder());
    jButton1.setNextFocusableComponent(this);
    jButton1.setText("play");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButton1_actionPerformed(e);
      }
    });
    this.getContentPane().setLayout(null);
    jButton2.setText("stop");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButton2_actionPerformed(e);
      }
    });
    jButton2.setBackground(SystemColor.info);
    jButton2.setBounds(new Rectangle(245, 112, 77, 40));
    jButton2.setFont(new java.awt.Font("Serif", 1, 14));
    jButton2.setForeground(Color.blue);
    jButton2.setBorder(BorderFactory.createRaisedBevelBorder());
    jButton2.setNextFocusableComponent(this);
    jButton3.setText("pause");
    jButton3.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButton3_actionPerformed(e);
      }
    });
    jButton3.setBackground(SystemColor.info);
    jButton3.setBounds(new Rectangle(135, 112, 77, 40));
    jButton3.setFont(new java.awt.Font("Serif", 1, 14));
    jButton3.setForeground(Color.blue);
    jButton3.setBorder(BorderFactory.createRaisedBevelBorder());
    jButton3.setNextFocusableComponent(this);
    jTextField2.setBounds(new Rectangle(155, 33, 47, 33));
    jTextField2.setBackground(SystemColor.activeCaption);
    jTextField2.setFont(new java.awt.Font("Serif", 1, 16));
    jTextField2.setForeground(Color.white);
    jTextField2.setBorder(BorderFactory.createRaisedBevelBorder());
    jTextField2.setCaretColor(Color.red);
    jTextField2.setSelectionColor(UIManager.getColor("EditorPane.caretForeground"));
    jTextField2.setText("0");
    jTextField3.setBounds(new Rectangle(203, 33, 50, 33));
    jTextField3.setBackground(SystemColor.activeCaption);
    jTextField3.setFont(new java.awt.Font("Serif", 1, 16));
    jTextField3.setForeground(Color.white);
    jTextField3.setBorder(BorderFactory.createRaisedBevelBorder());
    jTextField3.setCaretColor(Color.red);
    jTextField3.setSelectionColor(UIManager.getColor("EditorPane.caretForeground"));
    jTextField3.setText("0");
    jTextField1.setBackground(SystemColor.activeCaption);
    jTextField1.setFont(new java.awt.Font("Serif", 1, 16));
    jTextField1.setForeground(Color.white);
    jTextField1.setBorder(BorderFactory.createRaisedBevelBorder());
    jTextField1.setCaretColor(Color.red);
    jTextField1.setFocusAccelerator('1');
    jTextField1.setSelectionColor(UIManager.getColor("EditorPane.caretForeground"));
    jTextField1.setText("0");
    jTextField1.setBounds(new Rectangle(114, 33, 41, 33));
    this.getContentPane().setBackground(new Color(98, 144, 177));
    this.setCursor(null);
    this.setResizable(false);
    this.setTitle("StopWatch");
    this.getContentPane().add(jTextField2, null);
    this.getContentPane().add(jTextField3, null);
    this.getContentPane().add(jTextField1, null);
    this.getContentPane().add(jButton1, null);
    this.getContentPane().add(jButton2, null);
    this.getContentPane().add(jButton3, null);
  }

synchronized void jButton1_actionPerformed(ActionEvent e) {
jTextField3.setText("0");
jTextField2.setText("0");
jTextField1.setText("0");
second=0;
minute=0;
hour=0;
Threadsuspend=false;
t.start();
notify();
  }

 synchronized void jButton3_actionPerformed(ActionEvent e) {
 Threadsuspend=!Threadsuspend;
if(!Threadsuspend)
{
notify();
}
  }

synchronized  void jButton2_actionPerformed(ActionEvent e) {
notify();
t.stop();
t=new Thread(this);
notify();
  }
}
#3

مع الاسف الكود لم يعمل

#5

رفعت رسنا يا واد يا حسام

عمك من زهرة المدائن

#6

الله يكرمك يا عم حسن

عقبال ما نجمالك كدة وانت بتكتب فى c# قريب:P:cool::cool::eek::eek::(:o

#7

الى كل الاخوة الذين لم يعمل معهم الكود

المفروض انك قبل ما تنسخ المشروع تعمل مشروع جديد على محرر الجافا عندك سواء jbuilder or jcreator وتسمى المشروع باسم stopwatch

#8

-

#9

الله اكبر ولله الحمد(f)

هذا الموضوع مغلق.

مواضيع مشابهة