Bagi yang pengen membuat calculator dengan menggunakan bahasa java silahkan download sorce code nya disini:
http://www.ziddu.com/download/8242962/calculator.rar.html
Aplikasi ini dibuat dengan menggunakan NetBeans.
Selamat Berkreasi
Calculator dengan Java - NetBeans
by Son Rokhaniawan Perdata, S.T | 2:15 PM in Java, Netbeans, Project | comments (0)
Java and MySQL Store Prosedure Programming I
by Son Rokhaniawan Perdata, S.T | 10:25 AM in Java, Netbeans | comments (0)
Pada DBMS MySQL ada sebuah service dimana kita dapat membuat sebuah prosedur tersimpan di MySQL sendiri serta menjalankan prosedure tersebut kapan sesuai keinginan kita.
Ketika mata kuliah PBO. Aku sering mengamati dosen-dosen mengajarkan tentang koneksi Java ke MySQL. Dan pertanyaanku, mengapa sintaq SQL selalu diketik di list program java? mengapa tidak di tulis di MySQL sendiri?
Jadi kita bisa memisahkan pemrograman Java dan pemrograman MySQL sendiri-sendiri.
di atas adalah uraian singkat dari store prosedure.
*>>Ok. kita masuk ke MySQL. Bagaimana cara membuat sebuah store prosedure dengan parameter inputan.
Buatlah sebuah Form seperti pada gambar di bawah.
*>>pertama kita import libary jdbc MySQL.
masuk ke halaman source
setelah itu ketik pada awal program.
import java.sql.*;
import javax.swing.JOptionPane;
*>>lanjut......pada "Public F_input" silakan di ketik code di bawah.(F_Input adalah nama class yang kalian buat)
public F_input() {
initComponents();
try
{
//meload driver
Class.forName("com.mysql.jdbc.Driver");
//membuat koneksi
conn=DriverManager.getConnection("jdbc:mysql://locahost/db","root","");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e);
}
}
*>>Mari kita buat sebuah method dengan nama "masukan_data" seperti code di bawah.
void masukan_data(){
try{
CallableStatement sp_inputbarang =
conn.prepareCall("{call SP_InputBarang(?,?,?,?,?,?,?)}");
sp_inputbarang.setString(1, txtkodebarang.getText());
sp_inputbarang.setString(2, txtnama.getText());
sp_inputbarang.setDouble(3, Double.parseDouble(txthargabeli.getText()));
sp_inputbarang.setDouble(4, Double.parseDouble(txtdiskon.getText()));
sp_inputbarang.setDouble(5, Double.parseDouble(txthargaprivate.getText()));
sp_inputbarang.setDouble(6, Double.parseDouble(txthargajual.getText()));
sp_inputbarang.setInt(7, Integer.parseInt(txtstock.getText()));
sp_inputbarang.execute();
JOptionPane.showMessageDialog(null, "Simpan data berhasil");
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
*>> Buat Method Kosong untuk mengosongkan textField.
void kosong()
{
txtkodebarang.setText("");
txtnama.setText("");
txthargabeli.setText("");
txtdiskon.setText("");
txthargaprivate.setText("");
txthargajual.setText("");
txtstock.setText("");
}
*>> Klik Kanan pada textField Diskon-->Events-->Focus-->FocusLost. Dan Ketikkan code di bawah.
private void txtdiskonFocusLost(java.awt.event.FocusEvent evt) {
double hargabeli = Double.parseDouble(txthargabeli.getText());
double diskon = Double.parseDouble(txtdiskon.getText());
double hargaprivate = (hargabeli - (hargabeli * (diskon/100)));
txthargaprivate.setText(""+hargaprivate);
}
*>> Klik Kanan pada button Save-->Action-->ActionPerformed. Dan Ketik code di bawah.
private void btsaveActionPerformed(java.awt.event.ActionEvent evt) {
masukan_data();
kosong();
}
*>> Begitu juga pada button Cancel.
private void btcancelActionPerformed(java.awt.event.ActionEvent evt) {
kosong();
}
*>>Dan pada button Close.
private void btcloseActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
}
untuk lebih jelasnya bisa download source code di sini.
cara penggunaan :
- file mysql.sql di import dari SQLYog. (SQLYog bisa didownload di sini)
- folder test_StoreProsedure open lewat Netbeans.
!!!---SELAMAT BEREKSPERIMEN---!!!
SumberMaking Http Simple Server With Java
by Son Rokhaniawan Perdata, S.T | 12:16 AM in Java, Tutorial | comments (2)
Praktikum's task Network and Apparatus Mathematics moves secondly be make one http simple server at localhost. With utilize SocketServer's function, therefore gets to be made one server which will wait “panggilan†on port 80 (HTTP). And will send html's code while called.
SocketServer works in one looping that perpetual to wait marks sense connection to go to port 80 on localhost. There is 4 constructor on SocketServer for example:
- public ServerSocket(int port) throws BindException, IOException
- public ServerSocket(int port, int queueLength) throws BindException, IOException
- public ServerSocket(int port, int queueLength, InetAddress bindAddress) throws IOException
- public ServerSocket( ) throws IOException // Java 1.4
n Java, to make one server gets to be done by trick as follows:
- One serverSocket a new one is made deep one given port (in this case port 80) utilizing constructor of one SocketServer.
- Then serverSocket waits until mark sense coming connection through port has already is determined previous utilize accept's function().
- Then depends from server type, well utilize getInputStream's function(), getOutputStream's function(), or both of ala function goes together to get input and output stream in order to gets communication with client.
- Server and client gets communication / get interaction until its time hang up connection.
- Server, Client or both hangs up connection
- Server returns to to step 2 and waiting until marks sense succeeding connections.
And attachment source's following code that I takes from praktikum's module meagrely modifies to be able to qualify as one http server.
Tips Java : Getting Address's IP and Host Name
by Son Rokhaniawan Perdata, S.T | 11:35 PM in Java, Tutorial | comments (0)
Java provides InetAddress's function to get host's internet protocol address and also name a computer. host's internet protocol address and also name that is gotten don't cling to host's internet protocol address and name local computer only, but can also be utilized for mengecek host's internet protocol address and name at Internet, obviously by condition of computer we most link with Internet. This logistic purpose also relates hand in glove with setting DNS on computer that we utilizes.
Following is sample program that points out fungsionalitas that:- Make one project is Netbeans new
- Add one JFrame Form
- Provede with 2 tags, 2 numbers TextField (txtIPAddress dan txtNamaHost) and 3 Button (btnCheckIPAddress, btnCheckHostName dan btnCheckLokal). See example on pictured following:
- Following code cannikin type on btnCheckHostName, event actionPerformed
- private void btnCheckHostNameActionPerformed(java.awt.event.ActionEvent evt) {
- try {
- String strHostName = InetAddress.getByName(txtIPAddress.getText()).getHostName();
- JOptionPane.showMessageDialog(null, "Host name dari IP Address '" + txtIPAddress.getText() +"' =
"+ strHostName); - } catch (UnknownHostException ex) {
- JOptionPane.showMessageDialog(null, ex);
- Logger.getLogger(frmIpAddress.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- Do import library that needful (import java.net.InetAddress; import javax.swing.JOptionPane;)
- Following code cannikin type on btnCheckIPAddress, event actionPerformed
- private void btnCheckIPAddressActionPerformed(java.awt.event.ActionEvent evt) {
- try {
- String strIPAddress = InetAddress.getByName(txtHostName.getText()).getHostAddress() ;
- JOptionPane.showMessageDialog(null, "Alamat IP dari '"+txtHostName.getText() +"' ="+ strIPAddress);
- } catch (UnknownHostException ex) {
- JOptionPane.showMessageDialog(null, ex);
- Logger.getLogger(frmIpAddress.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- Following code cannikin type on btnCheckLokal event actionPerformed
- private void btnCheckLocalActionPerformed(java.awt.event.ActionEvent evt) {
- try {
- InetAddress AlamatInternet = InetAddress.getLocalHost();
- JOptionPane.showMessageDialog(null, "Host name lokal : " +AlamatInternet.getHostName());
- JOptionPane.showMessageDialog(null, "IP Address lokal : " +AlamatInternet.getHostAddress() );
- } catch (UnknownHostException ex) {
- JOptionPane.showMessageDialog(null, ex);
- Logger.getLogger(frmIpAddress.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- Save and runs application (SHIFT + F6). Insert IP Address and click on “Check Host Name” or insert host name and click “Check IP Address”. Check IP and Host Local don't need entry. Following is umpteen screenshot message one that performs:
This program not smart's ala detect entry what that internet protocol address or host name. To easy, I utilize 2 numbers TextField for example. On terapan's application, input IP Address or Host Name can thru get variable.
1. What is NetBeans?
NetBeans is an open-source Integrated Development Environment (IDE) you can download and use for free. NetBeans is also an extensible platform which you can use to build OS-independent applications. Finally, NetBeans is a thriving open-source community with hundreds of thousands of experienced developers located all around the world. More information.
2. How Do I Get Started?
Download the NetBeans IDE. It has everything you need develop world-class applications. NetBeans software is a 100% Java-based IDE and platform, so it works on every OS where the JDK is available. NetBeans supports a wide range of Java technologies, but is not limited to Java - other languages are supported as well. The NetBeans tools have so much functionality, you can choose which download is best for you. Learn more about supported technologies and features on the features page. You can add more functionality with plug-in modules (in the IDE, choose Tools > Plugins).
3. Where Can I Get Involved?
There is a thriving worldwide community of NetBeans users out there, ranging from new users to gurus. Join them to discuss tips and tricks, NetBeans features, problem solving and much more. Sign up now!
4. How Do I Learn More?
There is a wealth of knowledge here on netbeans.org to get your teeth into, with new content being posted weekly. Tutorials, articles, guides, demos and screencasts.
Welcome! We hope your visit is pleasant.
Java technology is both a programming language and a platform.
The Java Programming Language
The Java programming language is a high-level language that can be characterized by all of the following buzzwords:
- Simple
- Architecture neutral
- Object oriented
- Portable
- Distributed
- High performance
- Multithreaded
- Robust
- Dynamic
- Secure
In the Java programming language, all source code is first written in plain text files ending with the .java extension. Those source files are then compiled into .class files by the javac compiler. A .class file does not contain code that is native to your processor; it instead contains bytecodes — the machine language of the Java Virtual Machine1 (Java VM). The java launcher tool then runs your application with an instance of the Java Virtual Machine.
Figure showing MyProgram.java, compiler, MyProgram.class, Java VM, and My Program running on a computer.
An overview of the software development process.
Because the Java VM is available on many different operating systems, the same .class files are capable of running on Microsoft Windows, the Solaris TM Operating System (Solaris OS), Linux, or Mac OS. Some virtual machines, such as the Java HotSpot virtual machine, perform additional steps at runtime to give your application a performance boost. This include various tasks such as finding performance bottlenecks and recompiling (to native code) frequently used sections of code.
Figure showing source code, compiler, and Java VM's for Win32, Solaris OS/Linux, and Mac OS
Through the Java VM, the same application is capable of running on multiple platforms.
The Java Platform
A platform is the hardware or software environment in which a program runs. We've already mentioned some of the most popular platforms like Microsoft Windows, Linux, Solaris OS, and Mac OS. Most platforms can be described as a combination of the operating system and underlying hardware. The Java platform differs from most other platforms in that it's a software-only platform that runs on top of other hardware-based platforms.
The Java platform has two components:
- The Java Virtual Machine
- The Java Application Programming Interface (API)
The API is a large collection of ready-made software components that provide many useful capabilities. It is grouped into libraries of related classes and interfaces; these libraries are known as packages. The next section, What Can Java Technology Do? highlights some of the functionality provided by the API.
Figure showing MyProgram.java, API, Java Virtual Machine, and Hardware-Based Platform
The API and Java Virtual Machine insulate the program from the underlying hardware.
As a platform-independent environment, the Java platform can be a bit slower than native code. However, advances in compiler and virtual machine technologies are bringing performance close to that of native code without threatening portability.
The terms"Java Virtual Machine" and "JVM" mean a Virtual Machine for the Java platform.
