کرونومتر جاوا ⏱️
برنامه کرونومتر جاوا #جاوا #کرنومتر #برنامه // ******************************************** *** کلاس عمومی اصلی { public static void main(string[] args) { Stopwatch Stopwatch = new Stopwatch(); } } // ******************************************** *** واردات java.awt.*; واردات java.awt.event.*; واردات javax.swing.*; کرونومتر کلاس عمومی ActionListener را پیاده سازی می کند{ فریم JFrame = new JFrame(); JButton startButton = new JButton("START"); JButton resetButton = new JButton("RESET"); JLabel timeLabel = new JLabel(); int elapsedTime = 0; int ثانیه =0; int دقیقه =0; بین ساعت = 0; بولی شروع = نادرست; String seconds_string = String.format("%02d", seconds); String minutes_string = String.format("%02d", minutes); String hours_string = String.format("%02d", hours); تایمر = تایمر جدید (1000، جدید ActionListener() { public void actionPerformed(ActionEvent e) { elapsedTime=elapsedTime+1000; ساعت = (گذر زمان/3600000)؛ دقیقه = (گذر زمان/60000) % 60; ثانیه = (گذر زمان/1000) % 60; seconds_string = String.format("%02d"، seconds); minutes_string = String.format("%02d"، دقیقه); hours_string = String.format("%02d", hours); timeLabel.setText(hours_string+":"+minutes_string+":"+seconds_string); } })؛ کرونومتر(){ timeLabel.setText(hours_string+":"+minutes_string+":"+seconds_string); timeLabel.setBounds(100,100,200,100); timeLabel.setFont(new Font("Verdana",Font.PLAIN,35)); timeLabel.setBorder(BorderFactory.createBevelBorder(1)); timeLabel.setOpaque(true); timeLabel.setHorizontalAlignment(JTextField.CENTER); startButton.setBounds(100,200,100,50); startButton.setFont(new Font("Ink Free", Font.PLAIN,20)); startButton.setFocusable(false); startButton.addActionListener(this); resetButton.setBounds(200,200,100,50); resetButton.setFont(new Font("Ink Free", Font.PLAIN,20)); resetButton.setFocusable(false); resetButton.addActionListener(this); frame.add(startButton); frame.add(resetButton); frame.add(timeLabel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(420,420); frame.setLayout(null); frame.setVisible(true); } @Override public void actionPerformed(ActionEvent e) { if(e.getSource()==startButton) { if(شروع==نادرست) { شروع = درست startButton.setText("STOP"); start(); } دیگری { شروع = نادرست; startButton.setText("START"); متوقف کردن()؛ } } if(e.getSource()==resetButton) { شروع = نادرست; startButton.setText("START"); reset(); } } void start() { timer.start(); } void stop() { timer.stop(); } void reset() { timer.stop(); elapsedTime=0; ثانیه =0; دقیقه=0; ساعت=0; seconds_string = String.format("%02d"، seconds); minutes_string = String.format("%02d"، دقیقه); hours_string = String.format("%02d", hours); timeLabel.setText(hours_string+":"+minutes_string+":"+seconds_string); } }