package blog.emrahkahraman.com.tr;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class ResimGoster extends JFrame implements ActionListener {

private JTextField txtLink;
private JLabel lblResim;
private JLabel lblLink;
private JButton btnGoster;

public ResimGoster()
{
txtLink=new JTextField();
lblResim=new JLabel();
lblLink=new JLabel("Link");
btnGoster=new JButton("Göster");
setSize(400,500);
setLayout(null);
pencereGoster();
}

private void pencereGoster() {
Container con=this.getContentPane();
txtLink.setBounds(100,20,220,25);
btnGoster.setBounds(130,60,80,25);
lblResim.setBounds(30,100,400,400);
lblLink.setBounds(50,20,100,25);
con.add(txtLink);
con.add(lblResim);
con.add(lblLink);
con.add(btnGoster);
btnGoster.addActionListener(this);

}

public static void main(String[] args) {

ResimGoster rg=new ResimGoster();
rg.setVisible(true);

}

@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==btnGoster)
{
URL url;
try {
url = new URL(txtLink.getText());
BufferedImage image = ImageIO.read(url);
lblResim.setIcon(new ImageIcon(image));
}
catch (MalformedURLException e1) {
e1.printStackTrace();
}
catch (IOException ex) {
ex.printStackTrace();
}

System.out.println();
}
}
}

Yazar : Emrah Kahraman

Bilgisayar Mühendisi

Java Web Adresi Girilen Resmin JLabel’da Gösterilmesi Yazısı için Yorum Yapabilirsiniz

Sponsor
Alexa
Hakkımda
Bağlantılar