Program Stopwatch ini adalah program tugas kuliah saya..langsung aja ini tampilannya??????
Program stopwatch ini Bisa Di Download Di SINI
coding nya sebagai berikut:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ta;
/**
*
* @author Richer
*/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class stopwatch
extends JFrame implements ActionListener {
Timer time;
int milidetik, detik, menit, jam;
String nol_jam = "";
String nol_men = "";
String nol_det = "";
String nol_mili = "";
int no = 0;
JTextField tampilan = new JTextField("Tekan Mulai");
JTextField tampilan2 = new JTextField("");
JTextField tampilan3 = new JTextField("");
JTextField tampilan4 = new JTextField("");
JTextField tampilan5 = new JTextField("");
List Split = new List();
Button mulai = new Button("Start");
Button reset = new Button("Reset");
Button stop = new Button("Stop");
Button split = new Button("Split");
public stopwatch() {
setResizable(false);
getContentPane().setLayout(null);
tampilan.setFont(new java.awt.Font("Times New Roman", Font.BOLD, 20));
tampilan.setEditable(false);
tampilan.setForeground(Color.black);
tampilan.setBackground(Color.white);
tampilan.setHorizontalAlignment(JTextField.CENTER);
tampilan.setBounds(new Rectangle(75, 16, 146, 35));
Split.setBounds(new Rectangle(11, 110, 271, 148));
Split.setForeground(Color.black);
mulai.setBounds(new Rectangle(12, 68, 40, 30));
mulai.setSize(60, 30);
mulai.setForeground(Color.black);
mulai.setBackground(Color.green);
split.setBounds(new Rectangle(82, 68, 40, 30));
split.setSize(60, 30);
split.setForeground(Color.black);
split.setBackground(Color.green);
split.setEnabled(false);
reset.setEnabled(false);
reset.setBounds(new Rectangle(152, 68, 40, 30));
reset.setSize(60, 30);
reset.setForeground(Color.black);
reset.setBackground(Color.green);
stop.setEnabled(false);
stop.setBounds(new Rectangle(222, 68, 40, 30));
stop.setSize(60, 30);
stop.setForeground(Color.black);
stop.setBackground(Color.green);
tampilan2.setFont(new java.awt.Font("Times New Roman", Font.PLAIN, 12));
tampilan2.setEditable(false);
tampilan2.setForeground(Color.white);
tampilan2.setBackground(Color.black);
tampilan2.setHorizontalAlignment(JTextField.CENTER);
tampilan2.setBounds(new Rectangle(21, 280, 146, 35));
tampilan2.setSize(250, 20);
tampilan2.setText(" Stopwatch. Created By Richser / 672007283");
tampilan3.setEditable(false);
tampilan3.setBackground(Color.green);
tampilan3.setHorizontalAlignment(JTextField.CENTER);
tampilan3.setBounds(new Rectangle(16, 275, 146, 35));
tampilan3.setSize(260, 30);
tampilan4.setEditable(false);
tampilan4.setBackground(Color.green);
tampilan4.setHorizontalAlignment(JTextField.CENTER);
tampilan4.setBounds(new Rectangle(70, 11, 146, 35));
tampilan4.setSize(156, 45);
tampilan5.setEditable(false);
tampilan5.setBackground(new java.awt.Color(150,102,110));
tampilan5.setHorizontalAlignment(JTextField.CENTER);
tampilan5.setBounds(new Rectangle(1, 1));
tampilan5.setSize(300, 340);
mulai.addActionListener(this);
stop.addActionListener(this);
reset.addActionListener(this);
split.addActionListener(this);
this.getContentPane().add(tampilan);
this.getContentPane().add(mulai);
this.getContentPane().add(reset);
this.getContentPane().add(stop);
this.getContentPane().add(split);
this.getContentPane().add(tampilan2);
this.getContentPane().add(Split);
this.getContentPane().add(tampilan3);
this.getContentPane().add(tampilan4);
this.getContentPane().add(tampilan5);
}
public void aktifkan() {
ActionListener tr = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
milidetik++;
if(milidetik==100)
{
milidetik = 0;
detik++;
if(detik==60)
{
detik = 0;
menit++;
if(menit==60)
{
menit=0;
jam++;
if (jam==24);
{
jam=0;
}}}}
if (jam <= 9) {
nol_jam = "0";
}else nol_jam="";
if (menit <= 9) {
nol_men = "0";
}else nol_men="";
if (detik <= 9) {
nol_det = "0";
}else nol_det="";
if (milidetik <= 9) {
nol_mili = "0";
}else nol_mili="";
tampilan.setText(nol_jam + Integer.toString(jam)+ " : " + nol_men + Integer.toString(menit)+ " : " +
nol_det +Integer.toString(detik)+ " : " + nol_mili + Integer.toString(milidetik));
}
};
time=new Timer(10,tr);
time.start();
}
public void actionPerformed(ActionEvent e) {
Object tombol = e.getSource();
if (tombol== mulai) {
mulai.setEnabled(false);
reset.setEnabled(false);
stop.setEnabled(true);
split.setEnabled(true);
aktifkan();
}
if (tombol == split) {
no += 1;
Split.add(no + ". " + tampilan.getText());
}
if (tombol == stop) {
mulai.setEnabled(true);
reset.setEnabled(true);
stop.setEnabled(false);
split.setEnabled(false);
time.stop();
}
if (tombol == reset) {
no=0;menit=0;detik=0;milidetik=0;jam=0;nol_mili="0";nol_men="0";nol_det="0";nol_jam="0";
tampilan.setText(nol_jam + Integer.toString(jam)+ " : " + nol_men + Integer.toString(menit)+ " : " +
nol_det +Integer.toString(detik)+ " : " + nol_mili + Integer.toString(milidetik));
Split.clear();
}
}
}
-----------------------
class Mainnya
package ta;
import javax.swing.JFrame;
/**
*
* @author Richer
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic
stopwatch sw = new stopwatch();
sw.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
sw.setTitle(" Stopwatch");
sw.setSize(300, 340);
sw.show();
}
}
Selamat Mencoba Semoga Sukses
3 comments
trima kasih mas, konten di blognya oke2 punya..
ReplySalam merindu ya mas :D
sama2 mba jelekkkkkkkkk?????
Replylinknya udah gak bisa dibuka ya
ReplyPost a Comment