Image processing with java

// berikut ini adalah program untuk menampilkan gambar atau sering disebut image processing
// menggunakan java. dengan menggunakan GUI unuk mempercantik panampilan.
// by rawza… for yutta…
//
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class grafikImage extends JComponent implements ActionListener
{
private String nmFile;
private JButton b_open;
private JFileChooser openFile_dialog;
private JLabel label;
public grafikImage()
{
nmFile=””;
openFile_dialog = new JFileChooser();
setLayout(new FlowLayout(FlowLayout.LEFT));
b_open = new JButton(“Buka”);
label = new JLabel(“”,JLabel.CENTER);
add(b_open);
add(label);
b_open.addActionListener(this);
}
public void paintComponent(Graphics g)
{
Image gambar = Toolkit.getDefaultToolkit().getImage(nmFile);
g.drawImage(gambar,5,35,this);
}
public void actionPerformed(ActionEvent aksi)
{
if(aksi.getSource()==b_open)
{
int hasil = openFile_dialog.showOpenDialog(this);
if(hasil==JFileChooser.APPROVE_OPTION)
{
nmFile=openFile_dialog.getSelectedFile().toString();
label.setText(nmFile);
repaint();
}
}
}
public static void main (String[] args)
{
JFrame form = new JFrame(“COntoh ambil gambar”);
//form.setLayout(null);
form.setDefaultLookAndFeelDecorated(true);
form.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
form.getContentPane().add(new grafikImage());
form.setBounds(0,0,600,600);
form.setLocationRelativeTo(null);
form.setVisible(true);
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: