Assalamu'alaikum warohmatulloh wabarokaatuh Sobat Setia Catatan Sederahana kali ini saya akan Membagikan sebuah Catatan Code Java Ketika saya Sedang belajar java Untuk membuat Alarm Java ternyata,,saya belum Ada Waktu Untuk MemPraktekan nya ..Nah kalau sobat mau
Dibawah ini Code nya
package AlarmJava;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Calendar;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
import javax.swing.JCheckBox;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.Font;
import javax.swing.ImageIcon;
import java.awt.Color;
import javax.swing.SwingConstants;
@SuppressWarnings({ "serial", "restriction" })
public class FrmAlarmJava extends JFrame {
private JPanel contentPane;
private JLabel lblWaktu;
private JLabel lblSetWaktu;
private JTextField txtWaktu;
private JButton btnAlarmSound;
private JLabel lblPath;
private JCheckBox cbAktif;
private JLabel lblKeterangan;
String aktifitas;
private JLabel lblSetAlarmDan;
private JLabel lblPathSound;
private JLabel lblWall;
private JLabel lblNewLabel;
private JLabel lblNewLabel_1;
/**
* Create the frame.
*/
public FrmAlarmJava() {
setTitle("Alarm Java");
addWindowListener(new WindowAdapter() {
@Override
public void windowOpened(WindowEvent e) {
Waktu();
}
});
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 623, 312);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
cbAktif = new JCheckBox("Aktif");
cbAktif.setForeground(new Color(255, 255, 255));
cbAktif.setFont(new Font("Droid Sans", Font.BOLD, 13));
cbAktif.setOpaque(false);
cbAktif.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
aktifitas = JOptionPane
.showInputDialog("Masukkan nama aktifitas : ");
}
});
cbAktif.setBounds(475, 174, 81, 39);
contentPane.add(cbAktif);
lblKeterangan = new JLabel("");
lblKeterangan.setHorizontalAlignment(SwingConstants.CENTER);
lblKeterangan.setFont(new Font("Droid Sans", Font.BOLD, 13));
lblKeterangan.setBounds(159, 135, 225, 29);
contentPane.add(lblKeterangan);
lblWaktu = new JLabel("");
lblWaktu.setFont(new Font("Daniel Black", Font.BOLD, 14));
lblWaktu.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if (cbAktif.isSelected() == true) {
lblKeterangan.setEnabled(false);
if (txtWaktu.getText().equals(lblWaktu.getText())) {
player();
JOptionPane.showMessageDialog(null, aktifitas);
} else {
}
} else {
lblKeterangan.setEnabled(true);
}
}
});
lblWaktu.setBounds(12, 248, 107, 29);
contentPane.add(lblWaktu);
lblSetWaktu = new JLabel("Set waktu : ");
lblSetWaktu.setFont(new Font("Droid Sans", Font.BOLD, 13));
lblSetWaktu.setBounds(160, 28, 90, 15);
contentPane.add(lblSetWaktu);
txtWaktu = new JTextField();
txtWaktu.setFont(new Font("Droid Sans", Font.BOLD, 13));
txtWaktu.setText("00:00:00");
txtWaktu.setBounds(159, 46, 210, 29);
contentPane.add(txtWaktu);
txtWaktu.setColumns(10);
btnAlarmSound = new JButton("Alarm Sound");
btnAlarmSound.setBackground(new Color(51, 153, 204));
btnAlarmSound.setFont(new Font("Droid Sans", Font.BOLD, 13));
btnAlarmSound.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog(null);
File f = chooser.getSelectedFile();
String filename = f.getAbsolutePath();
lblPath.setText(filename);
}
});
btnAlarmSound.setBounds(159, 87, 135, 25);
contentPane.add(btnAlarmSound);
lblPath = new JLabel("");
lblPath.setBounds(159, 141, 218, 23);
contentPane.add(lblPath);
lblSetAlarmDan = new JLabel("Set Alarm dan Pesan : ");
lblSetAlarmDan.setForeground(new Color(255, 255, 255));
lblSetAlarmDan.setFont(new Font("Droid Sans", Font.BOLD, 13));
lblSetAlarmDan.setBounds(444, 135, 142, 35);
contentPane.add(lblSetAlarmDan);
lblPathSound = new JLabel("Path Sound : ");
lblPathSound.setForeground(new Color(255, 255, 255));
lblPathSound.setFont(new Font("Droid Sans", Font.BOLD, 13));
lblPathSound.setBounds(57, 135, 90, 29);
contentPane.add(lblPathSound);
lblNewLabel = new JLabel("");
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel.setIcon(new ImageIcon(FrmAlarmJava.class
.getResource("/AlarmJava/time-admin_1.png")));
lblNewLabel.setBounds(363, 12, 142, 123);
contentPane.add(lblNewLabel);
lblNewLabel_1 = new JLabel("");
lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_1.setIcon(new ImageIcon(FrmAlarmJava.class.getResource("/AlarmJava/icon.png")));
lblNewLabel_1.setBounds(517, 0, 93, 87);
contentPane.add(lblNewLabel_1);
lblWall = new JLabel("");
lblWall.setIcon(new ImageIcon(FrmAlarmJava.class
.getResource("/AlarmJava/wall_1.jpg")));
lblWall.setBounds(0, 0, 621, 289);
contentPane.add(lblWall);
setLocationRelativeTo(null);
}
private void Waktu() {
ActionListener taskPerformer = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
String nol_jam = "";
String nol_menit = "";
String nol_detik = "";
Calendar dt = Calendar.getInstance();
int nilai_jam = dt.get(Calendar.HOUR_OF_DAY);
int nilai_menit = dt.get(Calendar.MINUTE);
int nilai_detik = dt.get(Calendar.SECOND);
if (nilai_jam <= 9) {
nol_jam = "0";
}
if (nilai_menit <= 9) {
nol_menit = "0";
}
if (nilai_detik <= 9) {
nol_detik = "0";
}
String jam = nol_jam + Integer.toString(nilai_jam);
String menit = nol_menit + Integer.toString(nilai_menit);
String detik = nol_detik + Integer.toString(nilai_detik);
lblWaktu.setText(jam + ":" + menit + ":" + detik);
}
};
new javax.swing.Timer(1000, taskPerformer).start();
}
void player() {
InputStream in;
try {
in = new FileInputStream(new File(lblPath.getText()));
AudioStream audios = new AudioStream(in);
AudioPlayer.player.start(audios);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
FrmAlarmJava frame = new FrmAlarmJava();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
Sobat tidak Usah Copy saya siapkan File Rar yang berisi code tersebut berserta image Jam Dibawah ini Link Donlod nya
DOWNLOAD
Alhamdulillah Catatan sederhana Code Alarm Java Telah Seesai Mohon Maaf Jika Ada Kesalahan Wasalamu'alaikum warohmatulloh wabarokaatuh
Artikel Yang Lainnya
File Java
mantap nih, di tunggu follow back nya gan
ReplyDeleteOk Gan MAKASIH atas Kunjungan nya Di Gubuk saya
ReplyDelete