Wednesday, May 27, 2009

Membuat Piramida Bilangan dengan Java

public class PiramidaBilangan
{
/**Main method*/
public static void main(String[] args)
{
int jumBaris;
String data="";

System.out.println("\nPROGRAM MENCETAK PIRAMIDA BILANGAN");
System.out.println("----------------------------------\n");

// Menginstruksikan user untuk memasukkan jumlah baris
System.out.print("Hasil : \n");
data = javax.swing.JOptionPane.showInputDialog(null,"Masukan Jumlah baris:","5");
jumBaris = Integer.parseInt(data);

for (int baris = 1; baris < (jumBaris + 1); baris++) { // Mencetak spasi di urutan depan hingga posisi tengah // untuk memanipulasi tampilan for (int kolom = 1; kolom < (jumBaris + 1) - baris; kolom++) System.out.print(" "); // Mencetak bilangan di urutan depan hingga posisi tengah for (int bilangan = baris; bilangan >= 1; bilangan--)
System.out.print(bilangan);

// Mencetak bilangan dari posisi tengah hingga belakang
for (int bilangan = 2; bilangan <= baris; bilangan++) System.out.print(bilangan); // Memulai baris baru System.out.println(); } } } ////**********************************untuk piramida terbalik*************************** public class PiramidaBilangan { /**Main method*/ public static void main(String[] args) { int jumBaris; String data=""; System.out.println("\nPROGRAM MENCETAK PIRAMIDA BILANGAN"); System.out.println("----------------------------------\n"); // Menginstruksikan user untuk memasukkan jumlah baris System.out.print("Hasil : \n"); data = javax.swing.JOptionPane.showInputDialog(null,"Masukan Jumlah baris:","5"); jumBaris = Integer.parseInt(data); for (int baris = 1; baris < (jumBaris + 1); baris++) { // Mencetak spasi di urutan depan hingga posisi tengah // untuk memanipulasi tampilan for (int kolom = 1; kolom < bilangan =" (jumBaris">= 1; bilangan--)
System.out.print(bilangan);

// Mencetak bilangan dari posisi tengah hingga belakang
for (int bilangan = 2; bilangan <= (jumBaris + 1)-baris; bilangan++) System.out.print(bilangan); // Memulai baris baru System.out.println(); } } } source code download disini

hasil:

Membuat pesan pilhan dengan JOptionPane (ya dan tidak)

/*
* Program ini dibuat oleh Rachmad Hadi Wijoyo
* anda boleh mengunakan dan mendistribusikan dengan bebas
* asalkan tidak mengubah license ini.
* copyright by Rachmad Hadi Wijoyo
*/

package cobacoba;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.TrayIcon.MessageType;
import javax.swing.Icon;
import javax.swing.JOptionPane;

/**
*
* @author rahw
*/
public class OptionDialog {
public OptionDialog(){


String pil[] = {"Ya","Tidak"};

if(JOptionPane.showOptionDialog(null, "Anda yakin da pengen keluar? ", "Coba ShowOptionDialog",JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, pil, this)==JOptionPane.YES_OPTION){
System.exit(0);
}
}
public static void main(String args[]){
new OptionDialog();
}
}


Nengkap event Tombol yang ditekan



package cobacoba;

/*
* bacaTombol
*/

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.*;
import javax.swing.*;

public class bacaTombol extends JFrame
implements KeyListener,
ActionListener
{
JTextArea displayArea;
JTextField typingArea;
static final String newline = System.getProperty("line.separator");

public static void main(String[] args) {
/* Use an appropriate Look and Feel */
try {
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
} catch (UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
} catch (IllegalAccessException ex) {
ex.printStackTrace();
} catch (InstantiationException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
/* Turn off metal's use of bold fonts */
UIManager.put("swing.boldMetal", Boolean.FALSE);

//Schedule a job for event dispatch thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}

/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
bacaTombol frame = new bacaTombol("bacaTombol");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set up the content pane.
frame.addComponentsToPane();


//Display the window.
frame.pack();
frame.setVisible(true);
}

private void addComponentsToPane() {

JButton button = new JButton("Clear");
button.addActionListener(this);

typingArea = new JTextField(20);
typingArea.addKeyListener(this);

//Uncomment this if you wish to turn off focus
//traversal. The focus subsystem consumes
//focus traversal keys, such as Tab and Shift Tab.
//If you uncomment the following line of code, this
//disables focus traversal and the Tab events will
//become available to the key event listener.
//typingArea.setFocusTraversalKeysEnabled(false);

displayArea = new JTextArea();
displayArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(displayArea);
scrollPane.setPreferredSize(new Dimension(375, 125));

getContentPane().add(typingArea, BorderLayout.PAGE_START);
getContentPane().add(scrollPane, BorderLayout.CENTER);
getContentPane().add(button, BorderLayout.PAGE_END);
}

public bacaTombol(String name) {
super(name);
}


/** Handle the key typed event from the text field. */
public void keyTyped(KeyEvent e) {
displayInfo(e, "KEY TYPED: ");
}

/** Handle the key pressed event from the text field. */
public void keyPressed(KeyEvent e) {
displayInfo(e, "KEY PRESSED: ");
}

/** Handle the key released event from the text field. */
public void keyReleased(KeyEvent e) {
displayInfo(e, "KEY RELEASED: ");
}

/** Handle the button click. */
public void actionPerformed(ActionEvent e) {
//Clear the text components.
displayArea.setText("");
typingArea.setText("");

//Return the focus to the typing area.
typingArea.requestFocusInWindow();
}

/*
* We have to jump through some hoops to avoid
* trying to print non-printing characters
* such as Shift. (Not only do they not print,
* but if you put them in a String, the characters
* afterward won't show up in the text area.)
*/
private void displayInfo(KeyEvent e, String keyStatus){

//You should only rely on the key char if the event
//is a key typed event.
int id = e.getID();
String keyString;
if (id == KeyEvent.KEY_TYPED) {
char c = e.getKeyChar();
keyString = "key character = '" + c + "'";
} else {
int keyCode = e.getKeyCode();
keyString = "key code = " + keyCode
+ " ("
+ KeyEvent.getKeyText(keyCode)
+ ")";
}

int modifiersEx = e.getModifiersEx();
String modString = "extended modifiers = " + modifiersEx;
String tmpString = KeyEvent.getModifiersExText(modifiersEx);
if (tmpString.length() > 0) {
modString += " (" + tmpString + ")";
} else {
modString += " (no extended modifiers)";
}

String actionString = "action key? ";
if (e.isActionKey()) {
actionString += "YES";
} else {
actionString += "NO";
}

String locationString = "key location: ";
int location = e.getKeyLocation();
if (location == KeyEvent.KEY_LOCATION_STANDARD) {
locationString += "standard";
} else if (location == KeyEvent.KEY_LOCATION_LEFT) {
locationString += "left";
} else if (location == KeyEvent.KEY_LOCATION_RIGHT) {
locationString += "right";
} else if (location == KeyEvent.KEY_LOCATION_NUMPAD) {
locationString += "numpad";
} else { // (location == KeyEvent.KEY_LOCATION_UNKNOWN)
locationString += "unknown";
}

displayArea.append(keyStatus + newline
+ " " + keyString + newline
+ " " + modString + newline
+ " " + actionString + newline
+ " " + locationString + newline);
displayArea.setCaretPosition(displayArea.getDocument().getLength());
}
}

Membuat Aplikasi SystemTray dengan java


untuk membuat SystemTray seperti gambar diatas ternyata tidak sesulit yang saya kira.
berikut source code beserta penjelasanya.

Dowload project

/*
* Program ini dibuat oleh Rachmad Hadi Wijoyo
* anda boleh mengunakan dan mendistribusikan dengan bebas
* asalkan tidak mengubah license ini.
* copyright by Rachmad Hadi Wijoyo
*/

package cobacoba;

/**
*
* @author rahw
*/
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import javax.swing.*;

public class RTray {
public static void main(String[] args) {
/* Set Look and Feel yang kita guanakan*/
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
//UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
} catch (UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
} catch (IllegalAccessException ex) {
ex.printStackTrace();
} catch (InstantiationException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
/* mematikan evek metal look and feel */
UIManager.put("swing.boldMetal", Boolean.FALSE);

//Menjadwal event-dispatching thread:
//Memasang TrayIcon.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
new tesSystemTray().setVisible(true);
}
});
}

private static void createAndShowGUI() {
//Untuk memeriksa apakah sistem mendukung SystemTray
if (!SystemTray.isSupported()) {
System.out.println("Tidak mendukung SystemTray ");
return;
}
final PopupMenu popup = new PopupMenu();
final TrayIcon trayIcon =
new TrayIcon(createImage("/cobacoba/administrator_128.png", "tray icon"));
final SystemTray tray = SystemTray.getSystemTray();

// membuat popup menu components
MenuItem aboutItem = new MenuItem("Tentang");
CheckboxMenuItem cb2 = new CheckboxMenuItem("Set tooltip");


MenuItem exitItem = new MenuItem("Exit");

//Add components to popup menu
popup.add(aboutItem);
popup.addSeparator();
popup.add(cb2);
popup.addSeparator();

popup.add(exitItem);

trayIcon.setPopupMenu(popup);

try {
tray.add(trayIcon);
trayIcon.setImageAutoSize(true);
} catch (AWTException e) {
System.out.println("TrayIcon tidak dapat dipasang.");
return;
}

trayIcon.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new tesSystemTray().setVisible(true);
}
});

aboutItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null,
"Pesan ini dijalankan dari System Tray\n"+
"Program ini dibuat oleh Rachmad Hadi Wijoyo\n"+
"anda boleh mengunakan dan mendistribusikan dengan bebas\n"+
"asalkan tidak mengubah license ini.\n"+
"copyright by Rachmad Hadi Wijoyo \n"
);
}
});


cb2.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
int cb2Id = e.getStateChange();
if (cb2Id == ItemEvent.SELECTED){
trayIcon.setToolTip("Sun TrayIcon");
} else {
trayIcon.setToolTip(null);
}
}
});


exitItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tray.remove(trayIcon);
System.exit(0);
}
});
}

//Obtain the image URL
protected static Image createImage(String path, String description) {
URL imageURL = RTray.class.getResource(path);

if (imageURL == null) {
System.err.println("Gambar tidak ditemukan di: " + path);
return null;
} else {
return (new ImageIcon(imageURL, description)).getImage();
}
}
}


___________

/*
* Program ini dibuat oleh Rachmad Hadi Wijoyo
* anda boleh mengunakan dan mendistribusikan dengan bebas
* asalkan tidak mengubah license ini.
* copyright by Rachmad Hadi Wijoyo
* anda boleh mengunakan dan mendistribusikan dengan bebas
*/

/*
* tesSystemTray.java
*
* Created on May 19, 2009, 11:05:11 AM
*/

package cobacoba;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.Timer;
/**
*
* @author rahw
*/
public class tesSystemTray extends javax.swing.JFrame {

/** Creates new form tesSystemTray */
public tesSystemTray() {
initComponents();
timerx.start();
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// //GEN-BEGIN:initComponents
private void initComponents() {

jPanel1 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jPanel1.setBackground(new java.awt.Color(153, 153, 255));

jButton1.setText("Sembunyi");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jButton2.setText("Keluar");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cobacoba/administrator_128.png"))); // NOI18N
jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseEntered(java.awt.event.MouseEvent evt) {
jLabel1MouseEntered(evt);
}
public void mouseExited(java.awt.event.MouseEvent evt) {
jLabel1MouseExited(evt);
}
});

jLabel2.setText("copyright by Rachmad Hadi Wijoyo ");

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(117, 117, 117)
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(134, 134, 134)
.addComponent(jLabel1))
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel2)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGap(27, 27, 27)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 86, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton2)
.addComponent(jButton1))
.addGap(18, 18, 18)
.addComponent(jLabel2)
.addGap(4, 4, 4))
);

getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-408)/2, (screenSize.height-327)/2, 408, 327);
}//
//GEN-END:initComponents

private void jLabel1MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel1MouseEntered
// TODO add your handling code here:
jLabel1.setSize(jLabel1.getSize().width+20, jLabel1.getSize().height+20);
}//GEN-LAST:event_jLabel1MouseEntered

private void jLabel1MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel1MouseExited
// TODO add your handling code here:
jLabel1.setSize(jLabel1.getSize().width-20, jLabel1.getSize().height-20);
}//GEN-LAST:event_jLabel1MouseExited

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
dispose();
}//GEN-LAST:event_jButton1ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
System.exit(0);
}//GEN-LAST:event_jButton2ActionPerformed

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new tesSystemTray().setVisible(true);

}
});
}
Timer timerx = new Timer(100, new ActionListener() {
public void actionPerformed(ActionEvent E) {
if (jLabel2.getLocation().x <= (-jPanel1.getWidth()-50)){ jLabel2.setLocation(jPanel1.getWidth(),jLabel2.getLocation().y ); jLabel2.setLocation(jLabel2.getLocation().x-10, jLabel2.getLocation().y); }else{ jLabel2.setLocation(jLabel2.getLocation().x-10, jLabel2.getLocation().y); } } }); // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JPanel jPanel1; // End of variables declaration//GEN-END:variables } Download Project

Menjalankan Aplikasi Lain dan Perintah-perintah DOS(command prompt) menggunakan JAVA




Untuk Menjalankan aplikasi melalui java cukup dengan menggunakan class Runtime.
class tsb Bisa juga untuk menjalankan perintah-perintah Dos seperti:
  • cd C:\data\
  • attrib -s -h C:\data\* /s /d

untuk download project disini

Nah berikut Source codenya:

/*
* Program ini dibuat oleh Rachmad Hadi Wijoyo
* anda boleh mengunakan dan mendistribusikan dengan bebas
* asalkan tidak mengubah license ini.
* copyright by Rachmad Hadi Wijoyo
*/

/*
* Pangil.java
*
* Created on May 24, 2009, 12:05:49 AM
*/

package panggilaplikasi;

import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;

/**
*
* @author rahw
*/
public class Pangil extends javax.swing.JFrame {

/** Creates new form Pangil */
public Pangil() {
initComponents();
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// //GEN-BEGIN:initComponents
private void initComponents() {

jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jButton3 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
setUndecorated(true);

jPanel1.setBackground(new java.awt.Color(153, 204, 255));
jPanel1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 255), 5, true));

jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/panggilaplikasi/administrator_128.png"))); // NOI18N

jButton1.setMnemonic('j');
jButton1.setText("Jalankan");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jButton2.setMnemonic('k');
jButton2.setText("Keluar");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jLabel2.setText("Menjalankan Aplikasi ");

jLabel3.setText("Cari Aplikasi");

jButton3.setText("jButton3");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(12, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel2)
.addGap(31, 31, 31)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 156, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2)))
.addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 268, Short.MAX_VALUE))
.addContainerGap())
);

getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-405)/2, (screenSize.height-300)/2, 405, 300);
}//
//GEN-END:initComponents

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:
JFileChooser fc = new JFileChooser();
fc.setDialogTitle("Pilih Aplikasi");
fc.setFileFilter(new FileFilter() {

@Override
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
}
String fileName = f.getName();
int i = fileName.lastIndexOf('.');
if ((i > 0) && (i < (fileName.length() - 1))) { String fileExt = fileName.substring(i + 1); if ("exe".equalsIgnoreCase(fileExt)) { return true; } } return false; } @Override public String getDescription() { return "exe aja"; } }); fc.showOpenDialog(jTextField1); jTextField1.setText(fc.getCurrentDirectory().getPath()+"\\"+fc.getSelectedFile().getName()); }//GEN-LAST:event_jButton3ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // TODO add your handling code here: System.exit(0); }//GEN-LAST:event_jButton2ActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed try { if(!(jTextField1.getText().isEmpty())) jalankan(jTextField1.getText()); } catch (IOException ex) { Logger.getLogger(Pangil.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_jButton1ActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Pangil().setVisible(true); } }); } public void jalankan(String pathApp) throws IOException{ String cmd = "cmd.exe /k start "; Runtime.getRuntime().exec(cmd + pathApp); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JPanel jPanel1; private javax.swing.JTextField jTextField1; // End of variables declaration//GEN-END:variables }

Welcome

Selamat datang di blog Boso JAVA